Closed
Description
Linked and built-in native modules initialization function receive v8::String
as second argument instead of v8::Object
instance of Module
. It makes impossible to export something except precreated exports
object.
Dynamic modules initialization:
https://github.com/nodejs/node/blob/v5.4.1/src/node.cc#L2193-L2268
void DLOpen(const FunctionCallbackInfo<Value>& args) {
// ...
Local<Object> module = args[0]->ToObject(env->isolate()); // Cast
// ...
Local<Object> 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);
}
// ...
}
Linked modules initalization:
https://github.com/nodejs/node/blob/v5.4.1/src/node.cc#L2400-L2428
static void LinkedBinding(const FunctionCallbackInfo<Value>& args) {
// ...
Local<String> module = args[0]->ToString(env->isolate());
// ...
Local<Object> 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);
}
// ...
cache->Set(module, exports);
args.GetReturnValue().Set(exports);
}
\cc @indutny