diff options
author | Phillip Kovalev <twilightfeel@gmail.com> | 2016-01-20 00:52:16 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-02-02 09:41:50 -0800 |
commit | 71470a8e45af4ee65292327e5648fcf566324b0f (patch) | |
tree | 395606b15efe1aaba8c6c0eb5e0352017af2589f /src | |
parent | 61fe86b560a403d47e5a5a7fcd3be1f757878b37 (diff) | |
download | node-new-71470a8e45af4ee65292327e5648fcf566324b0f.tar.gz |
module: pass v8::Object to linked module initialization function
Fixes: https://github.com/nodejs/node/issues/4756
PR-URL: https://github.com/nodejs/node/pull/4771
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Rod Vagg <r@va.gg>
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/node.cc b/src/node.cc index 29127fbfc6..63cde12683 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2407,27 +2407,30 @@ static void Binding(const FunctionCallbackInfo<Value>& args) { static void LinkedBinding(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); - Local<String> module = args[0]->ToString(env->isolate()); + Local<String> module_name = args[0]->ToString(env->isolate()); Local<Object> cache = env->binding_cache_object(); - Local<Value> exports_v = cache->Get(module); + Local<Value> exports_v = cache->Get(module_name); if (exports_v->IsObject()) return args.GetReturnValue().Set(exports_v.As<Object>()); - node::Utf8Value module_v(env->isolate(), module); - node_module* mod = get_linked_module(*module_v); + node::Utf8Value module_name_v(env->isolate(), module_name); + node_module* mod = get_linked_module(*module_name_v); if (mod == nullptr) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "No such module was linked: %s", - *module_v); + *module_name_v); return env->ThrowError(errmsg); } + Local<Object> module = Object::New(env->isolate()); Local<Object> exports = Object::New(env->isolate()); + Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports"); + module->Set(exports_prop, exports); if (mod->nm_context_register_func != nullptr) { mod->nm_context_register_func(exports, @@ -2440,7 +2443,7 @@ static void LinkedBinding(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("Linked module has no declared entry point."); } - cache->Set(module, exports); + cache->Set(module_name, module->Get(exports_prop)); args.GetReturnValue().Set(exports); } |