Skip to content

Commit

Permalink
Add NAN_MODULE_WORKER_ENABLED macro as a replacement for NAN_MODULE t…
Browse files Browse the repository at this point in the history
…hat supports multiple workers (#792)

* Add NAN_MODULE_WORKER_ENABLED macro as a replacement for NAN_MODULE that supports multiple workers

Uses the named symbol node_register_module_v## variant of registration that works on node 10.5 with --experimental-workers. May need updating in the future if node requires native modules to explicitly opt in to multiple isolate support.
  • Loading branch information
rpetrich authored and kkoopa committed Jul 2, 2018
1 parent 139920e commit b058fb0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@

namespace Nan {

#define NAN_CONCAT(a, b) NAN_CONCAT_HELPER(a, b)
#define NAN_CONCAT_HELPER(a, b) a##b

#define NAN_INLINE inline // TODO(bnoordhuis) Remove in v3.0.0.

#if defined(__GNUC__) && \
Expand Down Expand Up @@ -148,6 +151,21 @@ namespace Nan {
#define NAN_MODULE_INIT(name) \
void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)

#if NODE_MAJOR_VERSION >= 10 || \
NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3
#define NAN_MODULE_WORKER_ENABLED(module_name, registration) \
extern "C" NODE_MODULE_EXPORT void \
NAN_CONCAT(node_register_module_v, NODE_MODULE_VERSION)( \
v8::Local<v8::Object> exports, v8::Local<v8::Value> module, \
v8::Local<v8::Context> context) \
{ \
registration(exports); \
}
#else
#define NAN_MODULE_WORKER_ENABLED(module_name, registration) \
NODE_MODULE(module_name, registration)
#endif

//=== CallbackInfo =============================================================

#include "nan_callbacks.h" // NOLINT(build/include)
Expand Down

0 comments on commit b058fb0

Please sign in to comment.