Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2020-04-19 22:51:05 +0300
committerAnna Henningsen <anna@addaleax.net>2020-05-06 07:44:04 +0300
commit86fdaa745572a3bec4370ac7bd05d18e6bf64c01 (patch)
tree45890dbc713ad29edd830fd2aa17f592909ccbb7 /src/node_binding.cc
parentf446b2058dcfaf9d4e2f6bdfe555bc4437f41acf (diff)
src: retrieve binding data from the context
Instead of passing them through the data bound to function templates, store references to them in a list embedded inside the context. This makes the function templates more context-independent, and makes it possible to embed binding data in non-main contexts. Co-authored-by: Anna Henningsen <anna@addaleax.net> PR-URL: https://github.com/nodejs/node/pull/33139 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_binding.cc')
-rw-r--r--src/node_binding.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 592d0ca2a39..fdd84c39a20 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -230,6 +230,7 @@ namespace node {
using v8::Context;
using v8::Exception;
+using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Local;
using v8::NewStringType;
@@ -556,8 +557,11 @@ inline struct node_module* FindModule(struct node_module* list,
static Local<Object> InitModule(Environment* env,
node_module* mod,
Local<String> module) {
- Local<Object> exports = Object::New(env->isolate());
// Internal bindings don't have a "module" object, only exports.
+ Local<Function> ctor = env->binding_data_ctor_template()
+ ->GetFunction(env->context())
+ .ToLocalChecked();
+ Local<Object> exports = ctor->NewInstance(env->context()).ToLocalChecked();
CHECK_NULL(mod->nm_register_func);
CHECK_NOT_NULL(mod->nm_context_register_func);
Local<Value> unused = Undefined(env->isolate());