diff options
author | Yihong Wang <yh.wang@ibm.com> | 2017-10-21 23:16:50 -0700 |
---|---|---|
committer | Gibson Fahnestock <gibfahn@gmail.com> | 2017-11-13 23:17:34 +0000 |
commit | 8680bb9f1a0163cfbdc4443c1eb2b56c5e443616 (patch) | |
tree | 16d97c77379adba2d45dc17787f314b9e3cb1b1b /src/node.cc | |
parent | 21a7459d490d832d5d547833d527083e460999e1 (diff) | |
download | android-node-v8-8680bb9f1a0163cfbdc4443c1eb2b56c5e443616.tar.gz android-node-v8-8680bb9f1a0163cfbdc4443c1eb2b56c5e443616.tar.bz2 android-node-v8-8680bb9f1a0163cfbdc4443c1eb2b56c5e443616.zip |
src: explicitly register built-in modules
Previously, built-in modules are registered before main() via
__attribute__((constructor)) mechanism in GCC and similiar
mechanism in MSVC. This causes some issues when node is built as
static library. Calling module registration function for built-in
modules in node::Init() helps to avoid the issues.
Signed-off-by: Yihong Wang <yh.wang@ibm.com>
PR-URL: https://github.com/nodejs/node/pull/16565
Refs: https://github.com/nodejs/node/pull/14986#issuecomment-332758206
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node.cc')
-rw-r--r-- | src/node.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/node.cc b/src/node.cc index 05120fbde1..cced5e7f8f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -124,6 +124,16 @@ typedef int mode_t; extern char **environ; #endif +// This is used to load built-in modules. Instead of using +// __attribute__((constructor)), we call the _register_<modname> +// function for each built-in modules explicitly in +// node::RegisterBuiltinModules(). This is only forward declaration. +// The definitions are in each module's implementation when calling +// the NODE_BUILTIN_MODULE_CONTEXT_AWARE. +#define V(modname) void _register_##modname(); + NODE_BUILTIN_MODULES(V) +#undef V + namespace node { using v8::Array; @@ -4305,6 +4315,9 @@ void Init(int* argc, // Initialize prog_start_time to get relative uptime. prog_start_time = static_cast<double>(uv_now(uv_default_loop())); + // Register built-in modules + node::RegisterBuiltinModules(); + // Make inherited handles noninheritable. uv_disable_stdio_inheritance(); @@ -4694,11 +4707,18 @@ int Start(int argc, char** argv) { return exit_code; } +// Call built-in modules' _register_<module name> function to +// do module registration explicitly. +void RegisterBuiltinModules() { +#define V(modname) _register_##modname(); + NODE_BUILTIN_MODULES(V) +#undef V +} } // namespace node #if !HAVE_INSPECTOR -static void InitEmptyBindings() {} +void InitEmptyBindings() {} -NODE_MODULE_CONTEXT_AWARE_BUILTIN(inspector, InitEmptyBindings) +NODE_BUILTIN_MODULE_CONTEXT_AWARE(inspector, InitEmptyBindings) #endif // !HAVE_INSPECTOR |