diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 43a647b6d78758..7ff94da749a10c 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -129,9 +129,7 @@ static void SetupHooks(const FunctionCallbackInfo& args) { } -static void Initialize(Handle target, - Handle unused, - Handle context) { +static void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); HandleScope scope(isolate); @@ -270,4 +268,4 @@ Handle AsyncWrap::MakeCallback(const Handle cb, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(async_wrap, node::Initialize) +NODE_MODULE_BUILTIN(async_wrap, node::Initialize) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index d4be7c9b9bfa9b..bafa290dd4b17a 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1240,9 +1240,7 @@ static void CaresTimerClose(Environment* env, } -static void Initialize(Handle target, - Handle unused, - Handle context) { +static void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); int r = ares_library_init(ARES_LIB_INIT_ALL); @@ -1318,4 +1316,4 @@ static void Initialize(Handle target, } // namespace cares_wrap } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(cares_wrap, node::cares_wrap::Initialize) +NODE_MODULE_BUILTIN(cares_wrap, node::cares_wrap::Initialize) diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index e17f9ce58ef5a3..890c17faaeb5fb 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -24,9 +24,7 @@ using v8::Value; class FSEventWrap: public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context); + static void Initialize(Local target, Local context); static void New(const FunctionCallbackInfo& args); static void Start(const FunctionCallbackInfo& args); static void Close(const FunctionCallbackInfo& args); @@ -59,9 +57,7 @@ FSEventWrap::~FSEventWrap() { } -void FSEventWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void FSEventWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -176,4 +172,4 @@ void FSEventWrap::Close(const FunctionCallbackInfo& args) { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize) +NODE_MODULE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize) diff --git a/src/js_stream.cc b/src/js_stream.cc index aa8de3a9ad9b8f..61f6b649f96a8b 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -201,9 +201,7 @@ void JSStream::EmitEOF(const FunctionCallbackInfo& args) { } -void JSStream::Initialize(Handle target, - Handle unused, - Handle context) { +void JSStream::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -226,4 +224,4 @@ void JSStream::Initialize(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(js_stream, node::JSStream::Initialize) +NODE_MODULE_BUILTIN(js_stream, node::JSStream::Initialize) diff --git a/src/js_stream.h b/src/js_stream.h index 9f7ba7de27153c..ec8c1a0161a8ce 100644 --- a/src/js_stream.h +++ b/src/js_stream.h @@ -10,9 +10,8 @@ namespace node { class JSStream : public StreamBase, public AsyncWrap { public: - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); ~JSStream(); diff --git a/src/node.cc b/src/node.cc index c272139e5518cd..97ac6174ab616f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2149,6 +2149,10 @@ void DLOpen(const FunctionCallbackInfo& args) { env->ThrowError("Built-in module self-registered."); return; } + if (mp->nm_flags & NM_F_NODE_MODULE_CONTEXT_AWARE_IS_DEPRECATED) { + fprintf(stderr, "NODE_MODULE_CONTEXT_AWARE(...) used by module %s is " + "deprecated. Use NODE_MODULE(...) instead\n", mp->nm_modname); + } mp->nm_dso_handle = lib.handle; mp->nm_link = modlist_addon; @@ -2157,10 +2161,12 @@ void DLOpen(const FunctionCallbackInfo& args) { Local exports_string = env->exports_string(); Local exports = module->Get(exports_string)->ToObject(env->isolate()); - if (mp->nm_context_register_func != nullptr) { - mp->nm_context_register_func(exports, module, env->context(), mp->nm_priv); - } else if (mp->nm_register_func != nullptr) { - mp->nm_register_func(exports, module, mp->nm_priv); + if (mp->nm_register_func != nullptr) { + mp->nm_register_func(mp->nm_init, + exports, + module, + env->context(), + mp->nm_priv); } else { env->ThrowError("Module has no declared entry point."); return; @@ -2271,11 +2277,12 @@ static void Binding(const FunctionCallbackInfo& args) { if (mod != nullptr) { exports = Object::New(env->isolate()); // Internal bindings don't have a "module" object, only exports. - CHECK_EQ(mod->nm_register_func, nullptr); - CHECK_NE(mod->nm_context_register_func, nullptr); - Local unused = Undefined(env->isolate()); - mod->nm_context_register_func(exports, unused, - env->context(), mod->nm_priv); + CHECK_NE(mod->nm_register_func, nullptr); + mod->nm_register_func(mod->nm_init, + exports, + Undefined(env->isolate()).As(), + env->context(), + mod->nm_priv); cache->Set(module, exports); } else if (!strcmp(*module_v, "constants")) { exports = Object::New(env->isolate()); @@ -2322,13 +2329,12 @@ static void LinkedBinding(const FunctionCallbackInfo& args) { Local exports = Object::New(env->isolate()); - if (mod->nm_context_register_func != nullptr) { - mod->nm_context_register_func(exports, - module, - env->context(), - mod->nm_priv); - } else if (mod->nm_register_func != nullptr) { - mod->nm_register_func(exports, module, mod->nm_priv); + if (mod->nm_register_func != nullptr) { + mod->nm_register_func(mod->nm_init, + exports, + Undefined(env->isolate()).As(), + env->context(), + mod->nm_priv); } else { return env->ThrowError("Linked module has no declared entry point."); } diff --git a/src/node.h b/src/node.h index acdfe5740740ef..fb5af6545960e1 100644 --- a/src/node.h +++ b/src/node.h @@ -357,28 +357,122 @@ NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)", const char *signo_string(int errorno); +//============================================================================== +// Init Function Argument Discomvobulator +//============================================================================== +namespace detail { typedef void (*addon_register_func)( - v8::Handle exports, - v8::Handle module, + void* init_function, + v8::Local exports, + v8::Local module, + v8::Local context, void* priv); -typedef void (*addon_context_register_func)( - v8::Handle exports, - v8::Handle module, - v8::Handle context, - void* priv); +// This template is used to select the optional arguments of the (addon) init +// function. Each specialization returns the corresponding argument. +template struct OptionalInitArg; + +template <> +struct OptionalInitArg > { + static inline + v8::Local + pick(v8::Local module, v8::Local, void*) { + return module; + } +}; + +template <> +struct OptionalInitArg > { + static inline + v8::Local + pick(v8::Local, v8::Local context, void*) { + return context; + } +}; + +template <> +struct OptionalInitArg { + static inline + void* + pick(v8::Local, v8::Local, void* private_) { + return private_; + } +}; -#define NM_F_BUILTIN 0x01 -#define NM_F_LINKED 0x02 +// Template that takes the type of the init function as an argument. It is used +// to inspect the arguments of the init function at compile time and provide a +// suitable adapter registerAddon(...). This adapter is always of type +// addon_register_func. It calls the actual init function with the "requested" +// arguments. To put it differently, the implementation of registerAddon(...) +// is selected (or generated, if you like) based on the functions signature. +template struct AddonInitAdapter; + +// Partial specialization: Allow only function pointers with the following +// properties: +// - returns void +// - takes a Local as first argument (exports) +// - takes zero or more additional arguments of arbitrary type +// +// To further narrow it down it uses a little bit of SFINAE. It only matches +// if there is a suitable specialization of OptionalInitArg<> for each +// additional argument. See registerAddon(...) below. This limits the argument +// types to: +// - Local (the module) +// - Local (the context, duh) +// - void* (the private pointer) +// +// The interesting thing about this application of SFINAE is that we use it +// to trigger a compile-time error. Since the generic version of +// AddonInitAdapter<> is only declared but never defined, the compiler bails +// after the substitution failure. +template +struct AddonInitAdapter, Args...)> { + typedef void (*init_function)(v8::Local, Args...); + + static + void + registerAddon(void* f, + v8::Local exports, + v8::Local module, + v8::Local context, + void* priv) { + // restore function pointer type + init_function init(reinterpret_cast(f)); + // call it + init(exports, OptionalInitArg::pick(module, context, priv)...); + } +}; + +// Main entry point into the init-fuction-argument-discomvobulator. It is +// called with an init function as argument and returns a suitable +// addon_register_func. Note how a template function is used to capture +// the type F. A user of this function (our NODE_MODULE_X(...) macro, below) +// does not have to provide a type. No function pointer types, not even angular +// brackets at the call site. (Remember this pattern. It's pretty powerful) +template +addon_register_func +selectAddonRegisterFunction(F f) { + return AddonInitAdapter::registerAddon; +} + +} // end of namespace detail + +enum node_module_flags { + NM_F_BUILTIN = (1<<0), + NM_F_LINKED = (1<<1), + // Used to emit a deprecation warning. Remove once + // NODE_MODULE_CONTEXT_AWARE is phased out. + NM_F_NODE_MODULE_CONTEXT_AWARE_IS_DEPRECATED = (1<<31) +}; struct node_module { int nm_version; unsigned int nm_flags; void* nm_dso_handle; const char* nm_filename; - node::addon_register_func nm_register_func; - node::addon_context_register_func nm_context_register_func; + node::detail::addon_register_func nm_register_func; + void* nm_init; const char* nm_modname; void* nm_priv; struct node_module* nm_link; @@ -408,52 +502,35 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); static void fn(void) #endif -#define NODE_MODULE_X(modname, regfunc, priv, flags) \ - extern "C" { \ - static node::node_module _module = \ - { \ - NODE_MODULE_VERSION, \ - flags, \ - NULL, \ - __FILE__, \ - (node::addon_register_func) (regfunc), \ - NULL, \ - NODE_STRINGIFY(modname), \ - priv, \ - NULL \ - }; \ - NODE_C_CTOR(_register_ ## modname) { \ - node_module_register(&_module); \ - } \ - } - -#define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \ +#define NODE_MODULE_X(modname, initfunc, priv, flags) \ extern "C" { \ - static node::node_module _module = \ - { \ - NODE_MODULE_VERSION, \ - flags, \ - NULL, \ - __FILE__, \ - NULL, \ - (node::addon_context_register_func) (regfunc), \ - NODE_STRINGIFY(modname), \ - priv, \ - NULL \ - }; \ NODE_C_CTOR(_register_ ## modname) { \ + static node::node_module _module = \ + { \ + NODE_MODULE_VERSION, \ + flags, \ + NULL, \ + __FILE__, \ + node::detail::selectAddonRegisterFunction(initfunc), \ + reinterpret_cast(initfunc), \ + NODE_STRINGIFY(modname), \ + priv, \ + NULL \ + }; \ node_module_register(&_module); \ } \ } -#define NODE_MODULE(modname, regfunc) \ - NODE_MODULE_X(modname, regfunc, NULL, 0) +#define NODE_MODULE(modname, initfunc) \ + NODE_MODULE_X(modname, initfunc, NULL, 0) -#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \ - NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0) +// NOTE(agnat): Deprecated. Just use NODE_MODULE(...) +#define NODE_MODULE_CONTEXT_AWARE(modname, initfunc) \ + NODE_MODULE_X(modname, initfunc, NULL, \ + NM_F_NODE_MODULE_CONTEXT_AWARE_IS_DEPRECATED) -#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \ - NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \ +#define NODE_MODULE_BUILTIN(modname, initfunc) \ + NODE_MODULE_X(modname, initfunc, NULL, node::NM_F_BUILTIN) /* * For backward compatibility in add-on modules. diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 5ab599ebab93ec..6ad34a7214dec6 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -991,9 +991,7 @@ void SetupBufferJS(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "setupBufferJS", SetupBufferJS); @@ -1028,4 +1026,4 @@ void Initialize(Handle target, } // namespace Buffer } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(buffer, node::Buffer::Initialize) +NODE_MODULE_BUILTIN(buffer, node::Buffer::Initialize) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ae043eb376a115..7f63a46a5448ed 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -704,9 +704,7 @@ class ContextifyScript : public BaseObject { }; -void InitContextify(Handle target, - Handle unused, - Handle context) { +void InitContextify(Local target, Local context) { Environment* env = Environment::GetCurrent(context); ContextifyContext::Init(env, target); ContextifyScript::Init(env, target); @@ -714,4 +712,4 @@ void InitContextify(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(contextify, node::InitContextify); +NODE_MODULE_BUILTIN(contextify, node::InitContextify); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c14f2b600c677e..8f8e95e7b1b127 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5262,10 +5262,7 @@ void SetEngine(const FunctionCallbackInfo& args) { // FIXME(bnoordhuis) Handle global init correctly. -void InitCrypto(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitCrypto(Local target, Local context) { static uv_once_t init_once = UV_ONCE_INIT; uv_once(&init_once, InitCryptoOnce); @@ -5311,4 +5308,4 @@ void InitCrypto(Handle target, } // namespace crypto } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(crypto, node::crypto::InitCrypto) +NODE_MODULE_BUILTIN(crypto, node::crypto::InitCrypto) diff --git a/src/node_crypto.h b/src/node_crypto.h index 3a00b519323d52..aa9951a2a326e7 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -722,7 +722,7 @@ bool EntropySource(unsigned char* buffer, size_t length); #ifndef OPENSSL_NO_ENGINE void SetEngine(const v8::FunctionCallbackInfo& args); #endif // !OPENSSL_NO_ENGINE -void InitCrypto(v8::Handle target); +void InitCrypto(v8::Local target, v8::Local context); } // namespace crypto } // namespace node diff --git a/src/node_file.cc b/src/node_file.cc index 0297b08e68d478..ef2078a1c4208e 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1188,10 +1188,7 @@ void FSInitialize(const FunctionCallbackInfo& args) { env->set_fs_stats_constructor_function(stats_constructor); } -void InitFs(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitFs(Local target, Local context) { Environment* env = Environment::GetCurrent(context); // Function which creates a new Stats object. @@ -1245,4 +1242,4 @@ void InitFs(Handle target, } // end namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs, node::InitFs) +NODE_MODULE_BUILTIN(fs, node::InitFs) diff --git a/src/node_file.h b/src/node_file.h index f242ee4f4f10b7..d33b39a8d5ac4f 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -6,7 +6,7 @@ namespace node { -void InitFs(v8::Handle target); +void InitFs(v8::Local target, v8::Local context); } // namespace node diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 6c5d76ecf6cc95..d0b9bde7bae196 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -560,10 +560,7 @@ const struct http_parser_settings Parser::settings = { }; -void InitHttpParser(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitHttpParser(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(Parser::New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -602,4 +599,4 @@ void InitHttpParser(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(http_parser, node::InitHttpParser) +NODE_MODULE_BUILTIN(http_parser, node::InitHttpParser) diff --git a/src/node_http_parser.h b/src/node_http_parser.h index 6fd8b76c6c3a6d..8d80b7bdeec914 100644 --- a/src/node_http_parser.h +++ b/src/node_http_parser.h @@ -7,7 +7,8 @@ namespace node { -void InitHttpParser(v8::Handle target); +void InitHttpParser(v8::Local target, + v8::Local context); } // namespace node diff --git a/src/node_os.cc b/src/node_os.cc index 3abc7ccec15de7..169a164704689d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -291,9 +291,7 @@ static void GetHomeDirectory(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "getHostname", GetHostname); env->SetMethod(target, "getLoadAvg", GetLoadAvg); @@ -312,4 +310,4 @@ void Initialize(Handle target, } // namespace os } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(os, node::os::Initialize) +NODE_MODULE_BUILTIN(os, node::os::Initialize) diff --git a/src/node_v8.cc b/src/node_v8.cc index 0a3e6e76338752..752d0e3eee3351 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -58,9 +58,7 @@ void SetFlagsFromString(const FunctionCallbackInfo& args) { } -void InitializeV8Bindings(Handle target, - Handle unused, - Handle context) { +void InitializeV8Bindings(Local target, Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "updateHeapStatisticsArrayBuffer", @@ -88,4 +86,4 @@ void InitializeV8Bindings(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(v8, node::InitializeV8Bindings) +NODE_MODULE_BUILTIN(v8, node::InitializeV8Bindings) diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 699d5c453c589c..6d3f3da936c990 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -43,7 +43,7 @@ enum node_zlib_mode { }; -void InitZlib(v8::Handle target); +void InitZlib(Local target, Local context); /** @@ -573,10 +573,7 @@ class ZCtx : public AsyncWrap { }; -void InitZlib(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitZlib(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local z = env->NewFunctionTemplate(ZCtx::New); @@ -636,4 +633,4 @@ void InitZlib(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(zlib, node::InitZlib) +NODE_MODULE_BUILTIN(zlib, node::InitZlib) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 2e1ab5b2621c32..3f46531a823d23 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -70,9 +70,7 @@ Local PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) { } -void PipeWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void PipeWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -278,4 +276,4 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(pipe_wrap, node::PipeWrap::Initialize) +NODE_MODULE_BUILTIN(pipe_wrap, node::PipeWrap::Initialize) diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index 6c74de984b34e6..179b2f4675d55a 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -12,9 +12,8 @@ class PipeWrap : public StreamWrap { uv_pipe_t* UVHandle(); static v8::Local Instantiate(Environment* env, AsyncWrap* parent); - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); size_t self_size() const override { return sizeof(*this); } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 14bbb9c9e9a9eb..2edf2fce84f0ec 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -26,9 +26,7 @@ using v8::Value; class ProcessWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); constructor->InstanceTemplate()->SetInternalFieldCount(1); @@ -262,4 +260,4 @@ class ProcessWrap : public HandleWrap { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(process_wrap, node::ProcessWrap::Initialize) +NODE_MODULE_BUILTIN(process_wrap, node::ProcessWrap::Initialize) diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 4811aca53a6183..92f2438e751b4a 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -22,9 +22,7 @@ using v8::Value; class SignalWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); constructor->InstanceTemplate()->SetInternalFieldCount(1); @@ -91,4 +89,4 @@ class SignalWrap : public HandleWrap { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(signal_wrap, node::SignalWrap::Initialize) +NODE_MODULE_BUILTIN(signal_wrap, node::SignalWrap::Initialize) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 97bccfd4b789a6..236e844cef6ae1 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -340,9 +340,8 @@ void SyncProcessStdioPipe::CloseCallback(uv_handle_t* handle) { } -void SyncProcessRunner::Initialize(Handle target, - Handle unused, - Handle context) { +void SyncProcessRunner::Initialize(Local target, + Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "spawn", Spawn); } @@ -1041,5 +1040,4 @@ void SyncProcessRunner::KillTimerCloseCallback(uv_handle_t* handle) { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(spawn_sync, - node::SyncProcessRunner::Initialize) +NODE_MODULE_BUILTIN(spawn_sync, node::SyncProcessRunner::Initialize) diff --git a/src/spawn_sync.h b/src/spawn_sync.h index 3069df610ffb8a..d212c900cd7fa0 100644 --- a/src/spawn_sync.h +++ b/src/spawn_sync.h @@ -129,9 +129,7 @@ class SyncProcessRunner { }; public: - static void Initialize(Handle target, - Handle unused, - Handle context); + static void Initialize(Local target, Local context); static void Spawn(const FunctionCallbackInfo& args); private: diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index ae941f5edbd90b..2d0dd028a26cb7 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -40,9 +40,7 @@ using v8::Undefined; using v8::Value; -void StreamWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void StreamWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local sw = @@ -379,4 +377,4 @@ void StreamWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(stream_wrap, node::StreamWrap::Initialize) +NODE_MODULE_BUILTIN(stream_wrap, node::StreamWrap::Initialize) diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 8e4cdf20be962e..de6cf4afc8031b 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -15,9 +15,8 @@ class StreamWrap; class StreamWrap : public HandleWrap, public StreamBase { public: - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); int GetFD() override; void* Cast() override; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 6980f8b28ce028..982f4960d4b1d7 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -64,9 +64,7 @@ Local TCPWrap::Instantiate(Environment* env, AsyncWrap* parent) { } -void TCPWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void TCPWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -448,4 +446,4 @@ Local AddressToJS(Environment* env, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(tcp_wrap, node::TCPWrap::Initialize) +NODE_MODULE_BUILTIN(tcp_wrap, node::TCPWrap::Initialize) diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index ee1e9817b231e9..33e99061484fc2 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -10,9 +10,8 @@ namespace node { class TCPWrap : public StreamWrap { public: static v8::Local Instantiate(Environment* env, AsyncWrap* parent); - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); uv_tcp_t* UVHandle(); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index f3d5d1fedbac31..6d6998940be380 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -25,9 +25,7 @@ const uint32_t kOnTimeout = 0; class TimerWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); constructor->InstanceTemplate()->SetInternalFieldCount(1); @@ -115,4 +113,4 @@ class TimerWrap : public HandleWrap { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(timer_wrap, node::TimerWrap::Initialize) +NODE_MODULE_BUILTIN(timer_wrap, node::TimerWrap::Initialize) diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index fc19a5ce0bbe38..9a98c5de8aeb20 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -869,9 +869,7 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB -void TLSWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void TLSWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "wrap", TLSWrap::Wrap); @@ -904,4 +902,4 @@ void TLSWrap::Initialize(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(tls_wrap, node::TLSWrap::Initialize) +NODE_MODULE_BUILTIN(tls_wrap, node::TLSWrap::Initialize) diff --git a/src/tls_wrap.h b/src/tls_wrap.h index b906d78de1ffb0..91b0ebc1d1ad57 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -27,9 +27,8 @@ class TLSWrap : public crypto::SSLWrap, public: ~TLSWrap() override; - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); void* Cast() override; int GetFD() override; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index eaec271937530e..071697ed8dad67 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -27,9 +27,7 @@ using v8::String; using v8::Value; -void TTYWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void TTYWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -140,4 +138,4 @@ TTYWrap::TTYWrap(Environment* env, Handle object, int fd, bool readable) } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(tty_wrap, node::TTYWrap::Initialize) +NODE_MODULE_BUILTIN(tty_wrap, node::TTYWrap::Initialize) diff --git a/src/tty_wrap.h b/src/tty_wrap.h index 6d423e1ae5306b..3777b0f8506e9f 100644 --- a/src/tty_wrap.h +++ b/src/tty_wrap.h @@ -9,9 +9,8 @@ namespace node { class TTYWrap : public StreamWrap { public: - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); uv_tty_t* UVHandle(); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index dd3958ec0e37da..55f4c99d25ceef 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -71,9 +71,7 @@ UDPWrap::UDPWrap(Environment* env, Handle object, AsyncWrap* parent) } -void UDPWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void UDPWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); @@ -430,4 +428,4 @@ uv_udp_t* UDPWrap::UVHandle() { } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(udp_wrap, node::UDPWrap::Initialize) +NODE_MODULE_BUILTIN(udp_wrap, node::UDPWrap::Initialize) diff --git a/src/udp_wrap.h b/src/udp_wrap.h index 3373cb9a2dfddb..8d7e65793e99dc 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -13,9 +13,8 @@ namespace node { class UDPWrap: public HandleWrap { public: - static void Initialize(v8::Handle target, - v8::Handle unused, - v8::Handle context); + static void Initialize(v8::Local target, + v8::Local context); static void GetFD(v8::Local, const v8::PropertyCallbackInfo&); static void New(const v8::FunctionCallbackInfo& args); diff --git a/src/uv.cc b/src/uv.cc index 2208ebde3c4f20..425d90f203d8f1 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -9,7 +9,7 @@ namespace uv { using v8::Context; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::Handle; +using v8::Local; using v8::Integer; using v8::Object; using v8::String; @@ -26,9 +26,7 @@ void ErrName(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"), env->NewFunctionTemplate(ErrName)->GetFunction()); @@ -43,4 +41,4 @@ void Initialize(Handle target, } // namespace uv } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(uv, node::uv::Initialize) +NODE_MODULE_BUILTIN(uv, node::uv::Initialize) diff --git a/test/addons/async-hello-world/binding.cc b/test/addons/async-hello-world/binding.cc index f458dc6a5632fd..787241a487e71a 100644 --- a/test/addons/async-hello-world/binding.cc +++ b/test/addons/async-hello-world/binding.cc @@ -62,7 +62,7 @@ void Method(const FunctionCallbackInfo& args) { (uv_after_work_cb)AfterAsync); } -void init(Handle exports, Handle module) { +void init(Local exports, Local module) { NODE_SET_METHOD(module, "exports", Method); } diff --git a/test/addons/at-exit/binding.cc b/test/addons/at-exit/binding.cc index 156dbe4ff54bb8..19cbb3109876f6 100644 --- a/test/addons/at-exit/binding.cc +++ b/test/addons/at-exit/binding.cc @@ -36,7 +36,7 @@ static void sanity_check(void) { assert(at_exit_cb2_called == 2); } -void init(Handle target) { +void init(Local exports) { AtExit(at_exit_cb1); AtExit(at_exit_cb2, cookie); AtExit(at_exit_cb2, cookie); diff --git a/test/addons/hello-world-function-export/binding.cc b/test/addons/hello-world-function-export/binding.cc index 91fc26cef652fb..5ebaf3cbc88e3c 100644 --- a/test/addons/hello-world-function-export/binding.cc +++ b/test/addons/hello-world-function-export/binding.cc @@ -9,7 +9,7 @@ void Method(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); } -void init(Handle exports, Handle module) { +void init(Local exports, Local module) { NODE_SET_METHOD(module, "exports", Method); } diff --git a/test/addons/hello-world/binding.cc b/test/addons/hello-world/binding.cc index 1a6d179abe264b..4d88ef37363d81 100644 --- a/test/addons/hello-world/binding.cc +++ b/test/addons/hello-world/binding.cc @@ -9,8 +9,8 @@ void Method(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); } -void init(Handle target) { - NODE_SET_METHOD(target, "hello", Method); +void init(Local exports) { + NODE_SET_METHOD(exports, "hello", Method); } NODE_MODULE(binding, init); diff --git a/test/addons/init_signatures/binding.gyp b/test/addons/init_signatures/binding.gyp new file mode 100644 index 00000000000000..ec9d2855c4e922 --- /dev/null +++ b/test/addons/init_signatures/binding.gyp @@ -0,0 +1,25 @@ +{ 'target_defaults': { 'defines': ['NODE_TEST_ADDON_NAME=>(_target_name)']} +, 'targets': + [ { 'target_name': 'init_exports' + , 'sources' : ['init_exports.cc'] + } + , { 'target_name': 'init_exports_module' + , 'sources' : ['init_exports_module.cc'] + } + , { 'target_name': 'init_exports_context' + , 'sources' : ['init_exports_context.cc'] + } + , { 'target_name': 'init_exports_private' + , 'sources' : ['init_exports_private.cc'] + } + , { 'target_name': 'init_exports_module_private' + , 'sources' : ['init_exports_module_private.cc'] + } + , { 'target_name': 'init_exports_module_context' + , 'sources' : ['init_exports_module_context.cc'] + } + , { 'target_name': 'init_exports_module_context_private' + , 'sources' : ['init_exports_module_context_private.cc'] + } + ] +} diff --git a/test/addons/init_signatures/init_exports.cc b/test/addons/init_signatures/init_exports.cc new file mode 100644 index 00000000000000..079fd166eb0abe --- /dev/null +++ b/test/addons/init_signatures/init_exports.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Local exports) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_context.cc b/test/addons/init_signatures/init_exports_context.cc new file mode 100644 index 00000000000000..aaf7582e532cd5 --- /dev/null +++ b/test/addons/init_signatures/init_exports_context.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Local exports, v8::Local context) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_module.cc b/test/addons/init_signatures/init_exports_module.cc new file mode 100644 index 00000000000000..00df8c2d7b37b0 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Local exports, v8::Local module) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_module_context.cc b/test/addons/init_signatures/init_exports_module_context.cc new file mode 100644 index 00000000000000..15b502ac76df05 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_context.cc @@ -0,0 +1,7 @@ +#include "init_test.h" +void init(v8::Local exports, + v8::Local module, + v8::Local context) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_module_context_private.cc b/test/addons/init_signatures/init_exports_module_context_private.cc new file mode 100644 index 00000000000000..ae1d7c3c927663 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_context_private.cc @@ -0,0 +1,8 @@ +#include "init_test.h" +void init(v8::Local exports, + v8::Local module, + v8::Local context, + void* priv) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_module_private.cc b/test/addons/init_signatures/init_exports_module_private.cc new file mode 100644 index 00000000000000..28acf8321369e1 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_private.cc @@ -0,0 +1,7 @@ +#include "init_test.h" +void init(v8::Local exports, + v8::Local module, + void* priv) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_exports_private.cc b/test/addons/init_signatures/init_exports_private.cc new file mode 100644 index 00000000000000..12d30fe381a6da --- /dev/null +++ b/test/addons/init_signatures/init_exports_private.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Local exports, void* priv) { + node::test::setInitTag(exports); +} +NODE_MODULE(NODE_TEST_ADDON_NAME, init) diff --git a/test/addons/init_signatures/init_test.h b/test/addons/init_signatures/init_test.h new file mode 100644 index 00000000000000..31edef38993400 --- /dev/null +++ b/test/addons/init_signatures/init_test.h @@ -0,0 +1,26 @@ +#ifndef NODE_TEST_ADDON_INIT_TEST_H +#define NODE_TEST_ADDON_INIT_TEST_H + +#include + +namespace node { +namespace test { + +inline +void +set(v8::Handle obj, const char* name, bool value) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + obj->Set( + v8::String::NewFromUtf8(isolate, name), + v8::Boolean::New(isolate, value)); +} + +inline +void +setInitTag(v8::Handle obj) { + set(obj, "initialized", true); +} + +} // end of namespace test +} // end of namespace node +#endif // NODE_TEST_ADDON_INIT_TEST_H diff --git a/test/addons/init_signatures/test.js b/test/addons/init_signatures/test.js new file mode 100644 index 00000000000000..b8e9de2b3f761e --- /dev/null +++ b/test/addons/init_signatures/test.js @@ -0,0 +1,17 @@ +'use strict'; +var assert = require('assert') + , path = require('path') + , i, name, addon + , signatures = [ ['exports'] + , ['exports', 'module'] + , ['exports', 'context'] + , ['exports', 'private'] + , ['exports', 'module', 'private'] + , ['exports', 'module', 'context'] + , ['exports', 'module', 'context', 'private'] + ]; +for (i in signatures) { + name = 'init_' + signatures[i].join('_'); + addon = require('./build/Release/' + name); + assert.ok(addon.initialized); +} diff --git a/test/addons/repl-domain-abort/binding.cc b/test/addons/repl-domain-abort/binding.cc index a875eabb71142d..e7415c317fc89f 100644 --- a/test/addons/repl-domain-abort/binding.cc +++ b/test/addons/repl-domain-abort/binding.cc @@ -3,7 +3,7 @@ using v8::Function; using v8::FunctionCallbackInfo; -using v8::Handle; +using v8::Local; using v8::HandleScope; using v8::Isolate; using v8::Object; @@ -19,8 +19,8 @@ void Method(const FunctionCallbackInfo& args) { NULL); } -void init(Handle target) { - NODE_SET_METHOD(target, "method", Method); +void init(Local exports) { + NODE_SET_METHOD(exports, "method", Method); } NODE_MODULE(binding, init);