- A module main source: r.g.
nan-objectwrap.ccNan::ObjectWrap: define for Holding C++ object(e.g. pointers) in each JS Objectinfo.IsConstructCall(): true when called withnew- it is important check because
ObjectWrap::Wrapcrush vm when in non-IsConstructCallcase
- it is important check because
info.Callee(): returnsLocal<Function>object of theNAN_METHODNan::NewInstance(function, argc, argv): same asnew Function(arg...)in JSNan::ObjectWrap#Wrap(object): bind C++ ObjectWrap object to the JS object instance(usuallyinfo.This())Nan::ObjectWrap::Unwrap<T>(object): access ObjectWrap object bound the JS object(usuallyinfo.Holder()asthisin JS)NAN_GETTERandNAN_SETTER: Native function for property accessorinfo: parameters of accessor functionproperty: property name asString(getter and setter)value: setting value in setter
v8::FunctionTemplate: as a constructor function, it bundled sub templates to set additional members asconstructor.prototypeInstanceTemplate(): use for adding instance member functionsPrototypeTemplate(): use for adding static/class member functions
v8::InstanceTemplate#SetInternalFieldCount(n): set a count of custom members slot in C++ layer in v8- for
ObjectWrapof node.js, it should set 1
- for
Nan::SetPrototypeMethod(functpl, name, cppfunc): set cppfunc as instance methodNan::SetAccessor(objtpl, name, getter, setter=nullptr): define Getter and Setter to the object(instance or prototpe) templateNan::GetFunction(v8::FunctionTemplate): get constructor function object from the template bundleNan::Set(v8::Object target, v8::Value key, v8::Value value): set property to JS object
Simple Example for a native module with exporting functions
APIs:
- nan: https://github.com/nodejs/nan
- v8: http://v8.paulfryzel.com/docs/master/
- http://v8.paulfryzel.com/docs/master/classv8_1_1_function_callback_info.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_function_template.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_object_template.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_function.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_object.html