Skip to content

Commit 71470a8

Browse files
Phillip Kovalevjasnell
Phillip Kovalev
authored andcommitted
module: pass v8::Object to linked module initialization function
Fixes: #4756 PR-URL: #4771 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 61fe86b commit 71470a8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/node.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -2407,27 +2407,30 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
24072407
static void LinkedBinding(const FunctionCallbackInfo<Value>& args) {
24082408
Environment* env = Environment::GetCurrent(args.GetIsolate());
24092409

2410-
Local<String> module = args[0]->ToString(env->isolate());
2410+
Local<String> module_name = args[0]->ToString(env->isolate());
24112411

24122412
Local<Object> cache = env->binding_cache_object();
2413-
Local<Value> exports_v = cache->Get(module);
2413+
Local<Value> exports_v = cache->Get(module_name);
24142414

24152415
if (exports_v->IsObject())
24162416
return args.GetReturnValue().Set(exports_v.As<Object>());
24172417

2418-
node::Utf8Value module_v(env->isolate(), module);
2419-
node_module* mod = get_linked_module(*module_v);
2418+
node::Utf8Value module_name_v(env->isolate(), module_name);
2419+
node_module* mod = get_linked_module(*module_name_v);
24202420

24212421
if (mod == nullptr) {
24222422
char errmsg[1024];
24232423
snprintf(errmsg,
24242424
sizeof(errmsg),
24252425
"No such module was linked: %s",
2426-
*module_v);
2426+
*module_name_v);
24272427
return env->ThrowError(errmsg);
24282428
}
24292429

2430+
Local<Object> module = Object::New(env->isolate());
24302431
Local<Object> exports = Object::New(env->isolate());
2432+
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports");
2433+
module->Set(exports_prop, exports);
24312434

24322435
if (mod->nm_context_register_func != nullptr) {
24332436
mod->nm_context_register_func(exports,
@@ -2440,7 +2443,7 @@ static void LinkedBinding(const FunctionCallbackInfo<Value>& args) {
24402443
return env->ThrowError("Linked module has no declared entry point.");
24412444
}
24422445

2443-
cache->Set(module, exports);
2446+
cache->Set(module_name, module->Get(exports_prop));
24442447

24452448
args.GetReturnValue().Set(exports);
24462449
}

0 commit comments

Comments
 (0)