diff --git a/src/async-wrap.cc b/src/async-wrap.cc index de1007e73d1d..313998713d15 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -72,9 +72,7 @@ static void SetupHooks(const FunctionCallbackInfo& args) { } -static void Initialize(Handle target, - Handle unused, - Handle context) { +static void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); HandleScope scope(isolate); @@ -185,4 +183,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 39c880015636..b9fe508a175c 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1242,9 +1242,7 @@ static void CaresTimerClose(Environment* env, } -static void Initialize(Handle target, - Handle unused, - Handle context) { +static void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); int r = ares_library_init(ARES_LIB_INIT_ALL); @@ -1320,4 +1318,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 04f3b997fd8e..92d5a40b3f87 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -45,9 +45,7 @@ using v8::Value; class FSEventWrap: public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context); + static void Initialize(Handle target, Handle context); static void New(const FunctionCallbackInfo& args); static void Start(const FunctionCallbackInfo& args); static void Close(const FunctionCallbackInfo& args); @@ -78,9 +76,7 @@ FSEventWrap::~FSEventWrap() { } -void FSEventWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void FSEventWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), New); @@ -200,4 +196,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/node.cc b/src/node.cc index d15b47577f4a..730fd0090a2c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2043,10 +2043,12 @@ void DLOpen(const FunctionCallbackInfo& args) { mp->nm_link = modlist_addon; modlist_addon = mp; - if (mp->nm_context_register_func != NULL) { - mp->nm_context_register_func(exports, module, env->context(), mp->nm_priv); - } else if (mp->nm_register_func != NULL) { - mp->nm_register_func(exports, module, mp->nm_priv); + if (mp->nm_register_func != NULL) { + mp->nm_register_func(mp->nm_init, + exports, + module, + env->context(), + mp->nm_priv); } else { env->ThrowError("Module has no declared entry point."); return; @@ -2157,12 +2159,14 @@ static void Binding(const FunctionCallbackInfo& args) { node_module* mod = get_builtin_module(*module_v); if (mod != NULL) { exports = Object::New(env->isolate()); + assert(mod->nm_register_func != NULL); // Internal bindings don't have a "module" object, only exports. - assert(mod->nm_register_func == NULL); - assert(mod->nm_context_register_func != NULL); - Local unused = Undefined(env->isolate()); - mod->nm_context_register_func(exports, unused, - env->context(), mod->nm_priv); + Local noModule = Undefined(env->isolate()).As(); + mod->nm_register_func(mod->nm_init, + exports, + noModule, + env->context(), + mod->nm_priv); cache->Set(module, exports); } else if (!strcmp(*module_v, "constants")) { exports = Object::New(env->isolate()); @@ -2209,13 +2213,12 @@ static void LinkedBinding(const FunctionCallbackInfo& args) { Local exports = Object::New(env->isolate()); - if (mod->nm_context_register_func != NULL) { - mod->nm_context_register_func(exports, - module, - env->context(), - mod->nm_priv); - } else if (mod->nm_register_func != NULL) { - mod->nm_register_func(exports, module, mod->nm_priv); + if (mod->nm_register_func != NULL) { + 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 bb8a3de0e43b..7e0a3ab7f638 100644 --- a/src/node.h +++ b/src/node.h @@ -334,17 +334,138 @@ NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)", const char *signo_string(int errorno); - +// NOTE(agnat): This is the updated version of the addon register function. We +// no longer distinguish between context aware and unaware modules. It's all +// the same... typedef void (*addon_register_func)( + void * init, v8::Handle exports, - v8::Handle module, - void* priv); - -typedef void (*addon_context_register_func)( - v8::Handle exports, - v8::Handle module, + v8::Handle module, v8::Handle context, - void* priv); + void * priv); + +namespace detail { + +// used to select the optional arguments of the init function. +// don't like it to much, but it'll do... +template struct OptionalInitArg; + +template <> +struct OptionalInitArg > { + static inline + v8::Handle + pick(v8::Handle module, + v8::Handle context, + void * priv) { + return module; + } +}; + +template <> +struct OptionalInitArg > { + static inline + v8::Handle + pick(v8::Handle module, + v8::Handle context, + void * priv) { + return context; + } +}; + +template <> +struct OptionalInitArg { + static inline + void* + pick(v8::Handle module, + v8::Handle context, + void * priv) { + return priv; + } +}; + +// AddonInitAdapter takes the type of the init function as an argument. +// The implementation of registerAddon is selected based on the functions +// signature. +template struct AddonInitAdapter; + +template <> +struct AddonInitAdapter)> { + typedef void (*init_func)(v8::Handle); + + static + void + registerAddon(void * f, + v8::Handle exports, + v8::Handle module, + v8::Handle context, + void * priv) { + init_func init(reinterpret_cast(f)); + init(exports); + } +}; + +template +struct AddonInitAdapter, A1)> { + typedef void (*init_func)(v8::Handle, A1); + + static + void + registerAddon(void * f, + v8::Handle exports, + v8::Handle module, + v8::Handle context, + void * priv) { + init_func init(reinterpret_cast(f)); + init(exports, + OptionalInitArg::pick(module, context, priv)); + } +}; + +template +struct AddonInitAdapter, A1, A2)> { + typedef void (*init_func)(v8::Handle, A1, A2); + + static + void + registerAddon(void * f, + v8::Handle exports, + v8::Handle module, + v8::Handle context, + void * priv) { + init_func init(reinterpret_cast(f)); + init(exports, + OptionalInitArg::pick(module, context, priv), + OptionalInitArg::pick(module, context, priv)); + } +}; + +template +struct AddonInitAdapter, A1, A2, A3)> { + typedef void (*init_func)(v8::Handle, A1, A2, A3); + + static + void + registerAddon(void * f, + v8::Handle exports, + v8::Handle module, + v8::Handle context, + void * priv) { + init_func init(reinterpret_cast(f)); + init(exports, + OptionalInitArg::pick(module, context, priv), + OptionalInitArg::pick(module, context, priv), + OptionalInitArg::pick(module, context, priv)); + } +}; + +// utility function to capture the type F +template +addon_register_func +selectAddonRegisterFunction(F f) { + return AddonInitAdapter::registerAddon; +} + +} // end of namespace detail #define NM_F_BUILTIN 0x01 #define NM_F_LINKED 0x02 @@ -355,7 +476,7 @@ struct node_module { void* nm_dso_handle; const char* nm_filename; node::addon_register_func nm_register_func; - node::addon_context_register_func nm_context_register_func; + void* nm_init; const char* nm_modname; void* nm_priv; struct node_module* nm_link; @@ -385,26 +506,7 @@ 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 = \ { \ @@ -412,8 +514,8 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); flags, \ NULL, \ __FILE__, \ - NULL, \ - (node::addon_context_register_func) (regfunc), \ + node::detail::selectAddonRegisterFunction(initfunc), \ + reinterpret_cast(initfunc), \ NODE_STRINGIFY(modname), \ priv, \ NULL \ @@ -423,14 +525,15 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); } \ } -#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) +// TODO(agnat): deprecate +#define NODE_MODULE_CONTEXT_AWARE(modname, initfunc) \ + NODE_MODULE_X(modname, initfunc, NULL, 0) -#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, NM_F_BUILTIN) /* * For backward compatibility in add-on modules. diff --git a/src/node_buffer.cc b/src/node_buffer.cc index cd66a8ac7408..b838d2f26759 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -649,9 +649,7 @@ void SetupBufferJS(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "setupBufferJS"), FunctionTemplate::New(env->isolate(), SetupBufferJS) @@ -662,4 +660,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 2e8fd2cade62..aa1453724670 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -715,9 +715,7 @@ class ContextifyScript : public BaseObject { }; -void InitContextify(Handle target, - Handle unused, - Handle context) { +void InitContextify(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); ContextifyContext::Init(env, target); ContextifyScript::Init(env, target); @@ -725,4 +723,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 36836c1a7906..bda53fc7d97c 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5113,10 +5113,7 @@ void SetEngine(const FunctionCallbackInfo& args) { // FIXME(bnoordhuis) Handle global init correctly. -void InitCrypto(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitCrypto(Handle target, Handle context) { static uv_once_t init_once = UV_ONCE_INIT; uv_once(&init_once, InitCryptoOnce); @@ -5156,4 +5153,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 1a719b9058a7..1c24e66f158a 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -703,7 +703,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::Handle target, v8::Handle context); } // namespace crypto } // namespace node diff --git a/src/node_file.cc b/src/node_file.cc index 6736864bc57c..3a135a290808 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1130,10 +1130,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(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); // Function which creates a new Stats object. @@ -1185,4 +1182,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 dc5deedb0a1c..0e8212ffb981 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -27,8 +27,7 @@ namespace node { -void InitFs(v8::Handle target); - +void InitFs(v8::Handle target, v8::Handle context); } // namespace node #endif // SRC_NODE_FILE_H_ diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 8d9b66ed06b8..2e75cd929fc3 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -570,10 +570,7 @@ const struct http_parser_settings Parser::settings = { }; -void InitHttpParser(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitHttpParser(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), Parser::New); @@ -613,4 +610,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 e376f52145d5..bffa044c73eb 100644 --- a/src/node_http_parser.h +++ b/src/node_http_parser.h @@ -28,7 +28,8 @@ namespace node { -void InitHttpParser(v8::Handle target); +void InitHttpParser(v8::Handle target, + v8::Handle context); } // namespace node diff --git a/src/node_os.cc b/src/node_os.cc index a7041aed7a01..18449cebe116 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -300,9 +300,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Handle target) { NODE_SET_METHOD(target, "getEndianness", GetEndianness); NODE_SET_METHOD(target, "getHostname", GetHostname); NODE_SET_METHOD(target, "getLoadAvg", GetLoadAvg); @@ -318,4 +316,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 b71b2a384db0..480c63212c70 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -207,9 +207,7 @@ void StopGarbageCollectionTracking(const FunctionCallbackInfo& args) { } -void InitializeV8Bindings(Handle target, - Handle unused, - Handle context) { +void InitializeV8Bindings(Handle target, Handle context) { NODE_SET_METHOD(target, "startGarbageCollectionTracking", StartGarbageCollectionTracking); @@ -221,4 +219,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 4f0c938998af..11aa34766c05 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -64,8 +64,7 @@ enum node_zlib_mode { }; -void InitZlib(v8::Handle target); - +void InitZlib(Handle target, Handle context); /** * Deflate/Inflate @@ -608,10 +607,7 @@ class ZCtx : public AsyncWrap { }; -void InitZlib(Handle target, - Handle unused, - Handle context, - void* priv) { +void InitZlib(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local z = FunctionTemplate::New(env->isolate(), ZCtx::New); @@ -671,4 +667,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 69cdfcdff3cf..247b67048c0c 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -88,9 +88,7 @@ Local PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) { } -void PipeWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void PipeWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), New); @@ -334,4 +332,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 959f28f4dca9..386306ae67e4 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -34,7 +34,6 @@ class PipeWrap : public StreamWrap { static v8::Local Instantiate(Environment* env, AsyncWrap* parent); static void Initialize(v8::Handle target, - v8::Handle unused, v8::Handle context); private: diff --git a/src/process_wrap.cc b/src/process_wrap.cc index a270c3884360..9a5692c94a51 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -47,9 +47,7 @@ using v8::Value; class ProcessWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local constructor = FunctionTemplate::New(env->isolate(), New); @@ -288,4 +286,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 a50340d511a7..3edbf24d9402 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -43,9 +43,7 @@ using v8::Value; class SignalWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local constructor = FunctionTemplate::New(env->isolate(), New); @@ -121,4 +119,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/smalloc.cc b/src/smalloc.cc index 7dc3510a0bf5..2501d6ee1551 100644 --- a/src/smalloc.cc +++ b/src/smalloc.cc @@ -537,9 +537,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Handle wrapper) { } -void Initialize(Handle exports, - Handle unused, - Handle context) { +void Initialize(Handle exports, Handle context) { Environment* env = Environment::GetCurrent(context); NODE_SET_METHOD(exports, "copyOnto", CopyOnto); @@ -563,4 +561,4 @@ void Initialize(Handle exports, } // namespace smalloc } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(smalloc, node::smalloc::Initialize) +NODE_MODULE_BUILTIN(smalloc, node::smalloc::Initialize) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 59de8d463041..b826af2442f0 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -353,9 +353,7 @@ void SyncProcessStdioPipe::CloseCallback(uv_handle_t* handle) { } -void SyncProcessRunner::Initialize(Handle target, - Handle unused, - Handle context) { +void SyncProcessRunner::Initialize(Handle target) { NODE_SET_METHOD(target, "spawn", Spawn); } @@ -1053,5 +1051,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 615e1b9b888d..7bed406d790a 100644 --- a/src/spawn_sync.h +++ b/src/spawn_sync.h @@ -150,9 +150,7 @@ class SyncProcessRunner { }; public: - static void Initialize(Handle target, - Handle unused, - Handle context); + static void Initialize(Handle target); static void Spawn(const FunctionCallbackInfo& args); private: diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 840b16614a13..84dc8bc5adc4 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -57,9 +57,7 @@ using v8::Undefined; using v8::Value; -void StreamWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void StreamWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local sw = @@ -773,4 +771,4 @@ int StreamWrapCallbacks::DoShutdown(ShutdownWrap* req_wrap, uv_shutdown_cb cb) { } // 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 38e5d4842257..e80dca2469e4 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -121,7 +121,6 @@ class StreamWrapCallbacks { class StreamWrap : public HandleWrap { public: static void Initialize(v8::Handle target, - v8::Handle unused, v8::Handle context); void OverrideCallbacks(StreamWrapCallbacks* callbacks, bool gc) { diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index a5b20a6ac5a6..3d1bfab19ad4 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -83,9 +83,7 @@ Local TCPWrap::Instantiate(Environment* env, AsyncWrap* parent) { } -void TCPWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void TCPWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), New); @@ -526,4 +524,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 c923b387f0e7..8e1c235f4be2 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -32,7 +32,6 @@ 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); uv_tcp_t* UVHandle(); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 71e6a613431a..c985e0647914 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -46,9 +46,7 @@ const uint32_t kOnTimeout = 0; class TimerWrap : public HandleWrap { public: - static void Initialize(Handle target, - Handle unused, - Handle context) { + static void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local constructor = FunctionTemplate::New(env->isolate(), New); @@ -161,4 +159,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 607f786501e3..2b648cf78fc8 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -821,9 +821,7 @@ int TLSCallbacks::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB -void TLSCallbacks::Initialize(Handle target, - Handle unused, - Handle context) { +void TLSCallbacks::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); NODE_SET_METHOD(target, "wrap", TLSCallbacks::Wrap); @@ -854,4 +852,4 @@ void TLSCallbacks::Initialize(Handle target, } // namespace node -NODE_MODULE_CONTEXT_AWARE_BUILTIN(tls_wrap, node::TLSCallbacks::Initialize) +NODE_MODULE_BUILTIN(tls_wrap, node::TLSCallbacks::Initialize) diff --git a/src/tls_wrap.h b/src/tls_wrap.h index b12a6b661229..d3d8f6aa31a4 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -49,7 +49,6 @@ class TLSCallbacks : public crypto::SSLWrap, ~TLSCallbacks(); static void Initialize(v8::Handle target, - v8::Handle unused, v8::Handle context); const char* Error(); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 34ee14dec70e..4c9cbf16bf87 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -48,9 +48,7 @@ using v8::String; using v8::Value; -void TTYWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void TTYWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), New); @@ -190,4 +188,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 91abfeb41450..ab7fe5dd671d 100644 --- a/src/tty_wrap.h +++ b/src/tty_wrap.h @@ -31,7 +31,6 @@ namespace node { class TTYWrap : public StreamWrap { public: static void Initialize(v8::Handle target, - v8::Handle unused, v8::Handle context); uv_tty_t* UVHandle(); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 614326fa1fb9..60d737e9c61c 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -94,9 +94,7 @@ UDPWrap::~UDPWrap() { } -void UDPWrap::Initialize(Handle target, - Handle unused, - Handle context) { +void UDPWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); Local t = FunctionTemplate::New(env->isolate(), New); @@ -468,4 +466,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 693fa51b7180..9caf80f91092 100644 --- a/src/udp_wrap.h +++ b/src/udp_wrap.h @@ -34,7 +34,6 @@ namespace node { class UDPWrap: public HandleWrap { public: static void Initialize(v8::Handle target, - v8::Handle unused, v8::Handle context); static void GetFD(v8::Local, const v8::PropertyCallbackInfo&); diff --git a/src/uv.cc b/src/uv.cc index 54bbf92f12c4..34558d079679 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -49,9 +49,7 @@ void ErrName(const FunctionCallbackInfo& args) { } -void Initialize(Handle target, - Handle unused, - Handle context) { +void Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"), FunctionTemplate::New(env->isolate(), ErrName)->GetFunction()); @@ -66,4 +64,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/at-exit/binding.cc b/test/addons/at-exit/binding.cc index 156dbe4ff54b..1459d20c5c23 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(Handle exports) { AtExit(at_exit_cb1); AtExit(at_exit_cb2, cookie); AtExit(at_exit_cb2, cookie); diff --git a/test/addons/c++11-addon/binding.cc b/test/addons/c++11-addon/binding.cc new file mode 100644 index 000000000000..fb9cd77da6c2 --- /dev/null +++ b/test/addons/c++11-addon/binding.cc @@ -0,0 +1,8 @@ +#include + +#if __cplusplus <= 199711L // not C++11 +# warning C++11 is not available. +#endif + +void init(v8::Handle exports) {} +NODE_MODULE(binding, init); diff --git a/test/addons/c++11-addon/binding.gyp b/test/addons/c++11-addon/binding.gyp new file mode 100644 index 000000000000..9e47694bc75a --- /dev/null +++ b/test/addons/c++11-addon/binding.gyp @@ -0,0 +1,16 @@ +{ 'targets': + [ { 'target_name': 'binding' + , 'sources': ['binding.cc'] + , 'cflags': ['-std=c++11'] + , 'conditions': + [ [ 'OS=="mac"', + { 'xcode_settings': + { 'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11', '-stdlib=libc++'] + , 'MACOSX_DEPLOYMENT_TARGET': '10.7' + } + } + ] + ] + } + ] +} diff --git a/test/addons/c++11-addon/test.js b/test/addons/c++11-addon/test.js new file mode 100644 index 000000000000..4466b898afe5 --- /dev/null +++ b/test/addons/c++11-addon/test.js @@ -0,0 +1 @@ +var binding = require('./build/Release/binding'); diff --git a/test/addons/hello-world/binding.cc b/test/addons/hello-world/binding.cc index 1a6d179abe26..c3eb57d4ec10 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(Handle 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 000000000000..ec9d2855c4e9 --- /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 000000000000..86052668d4ba --- /dev/null +++ b/test/addons/init_signatures/init_exports.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Handle 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 000000000000..718fc23ac3cc --- /dev/null +++ b/test/addons/init_signatures/init_exports_context.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Handle exports, v8::Handle 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 000000000000..4800345b2ba3 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Handle exports, v8::Handle 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 000000000000..b981973f7326 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_context.cc @@ -0,0 +1,7 @@ +#include "init_test.h" +void init(v8::Handle exports, + v8::Handle module, + v8::Handle 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 000000000000..4474f94fe090 --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_context_private.cc @@ -0,0 +1,8 @@ +#include "init_test.h" +void init(v8::Handle exports, + v8::Handle module, + v8::Handle 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 000000000000..b28f8b22e8bc --- /dev/null +++ b/test/addons/init_signatures/init_exports_module_private.cc @@ -0,0 +1,7 @@ +#include "init_test.h" +void init(v8::Handle exports, + v8::Handle 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 000000000000..e09836eb5f6b --- /dev/null +++ b/test/addons/init_signatures/init_exports_private.cc @@ -0,0 +1,5 @@ +#include "init_test.h" +void init(v8::Handle 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 000000000000..077fcfb911b5 --- /dev/null +++ b/test/addons/init_signatures/init_test.h @@ -0,0 +1,24 @@ +#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, char const* 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 node::test +#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 000000000000..d4d4fc86e9a1 --- /dev/null +++ b/test/addons/init_signatures/test.js @@ -0,0 +1,16 @@ +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 1337395c1b92..dd76ee8a258e 100644 --- a/test/addons/repl-domain-abort/binding.cc +++ b/test/addons/repl-domain-abort/binding.cc @@ -40,8 +40,8 @@ void Method(const FunctionCallbackInfo& args) { NULL); } -void init(Handle target) { - NODE_SET_METHOD(target, "method", Method); +void init(Handle exports) { + NODE_SET_METHOD(exports, "method", Method); } NODE_MODULE(binding, init);