Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.7 KB

README.md

File metadata and controls

56 lines (41 loc) · 1.7 KB

Node.js Addon Examples

See the Node.js C++ addons page for details of the examples here.

In each directory, run:

$ node-gyp rebuild
$ node ./

See the v0.11 branch for updated examples applicable to Node v0.11 and above.

Compatibility notes

Node v0.11: V8 requires current isolate

The V8 upgrade that occured when v0.11 was released requires that the current isolate be passed to scope creation calls and most New() calls.

Isolate* isolate = Isolate::GetCurrent();
// ...
HandleScope scope(isolate);
// ...
Persistent<Function> constructor = Persistent<Function>::New(isolate, tpl->GetFunction());

Omission of the current isolate will only trigger a compile-time warning at this stage but addon authors wishing to remove those warnings and remain backward-compatible with v0.10 and prior may need to get creative with macros:

// NODE_MODULE_VERSION was incremented for v0.11

#if NODE_MODULE_VERSION > 0x000B
#  define MY_NODE_ISOLATE_DECL Isolate* isolate = Isolate::GetCurrent();
#  define MY_NODE_ISOLATE      isolate
#  define MY_NODE_ISOLATE_PRE  isolate, 
#  define MY_NODE_ISOLATE_POST , isolate 
#  define MY_HANDLESCOPE v8::HandleScope scope(MY_NODE_ISOLATE);
#else
#  define MY_NODE_ISOLATE_DECL
#  define MY_NODE_ISOLATE
#  define MY_NODE_ISOLATE_PRE
#  define MY_NODE_ISOLATE_POST
#  define MY_HANDLESCOPE v8::HandleScope scope;
#endif

MY_NODE_ISOLATE_DECL
MY_HANDLESCOPE

// ...

Persistent<Function> constructor = Persistent<Function>::New(MY_NODE_ISOLATE_PRE tpl->GetFunction());