diff --git a/src/async_wrap.cc b/src/async_wrap.cc index aac2f3c911b044..ad150ff7b0ca13 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -44,6 +44,7 @@ using v8::MaybeLocal; using v8::Nothing; using v8::Number; using v8::Object; +using v8::ObjectTemplate; using v8::PropertyAttribute; using v8::ReadOnly; using v8::String; @@ -351,24 +352,31 @@ Local AsyncWrap::GetConstructorTemplate( return tmpl; } -void AsyncWrap::Initialize(Local target, - Local unused, - Local context, - void* priv) { +void AsyncWrap::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + + SetMethod(isolate, target, "setupHooks", SetupHooks); + SetMethod(isolate, target, "setCallbackTrampoline", SetCallbackTrampoline); + SetMethod(isolate, target, "pushAsyncContext", PushAsyncContext); + SetMethod(isolate, target, "popAsyncContext", PopAsyncContext); + SetMethod(isolate, target, "executionAsyncResource", ExecutionAsyncResource); + SetMethod(isolate, target, "clearAsyncIdStack", ClearAsyncIdStack); + SetMethod(isolate, target, "queueDestroyAsyncId", QueueDestroyAsyncId); + SetMethod(isolate, target, "setPromiseHooks", SetPromiseHooks); + SetMethod(isolate, target, "registerDestroyHook", RegisterDestroyHook); + AsyncWrap::GetConstructorTemplate(isolate_data); +} + +void AsyncWrap::CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); HandleScope scope(isolate); - SetMethod(context, target, "setupHooks", SetupHooks); - SetMethod(context, target, "setCallbackTrampoline", SetCallbackTrampoline); - SetMethod(context, target, "pushAsyncContext", PushAsyncContext); - SetMethod(context, target, "popAsyncContext", PopAsyncContext); - SetMethod(context, target, "executionAsyncResource", ExecutionAsyncResource); - SetMethod(context, target, "clearAsyncIdStack", ClearAsyncIdStack); - SetMethod(context, target, "queueDestroyAsyncId", QueueDestroyAsyncId); - SetMethod(context, target, "setPromiseHooks", SetPromiseHooks); - SetMethod(context, target, "registerDestroyHook", RegisterDestroyHook); - PropertyAttribute ReadOnlyDontDelete = static_cast(ReadOnly | DontDelete); @@ -625,7 +633,6 @@ void AsyncWrap::AsyncReset(Local resource, double execution_async_id, async_id_, trigger_async_id_); } - void AsyncWrap::EmitAsyncInit(Environment* env, Local object, Local type, @@ -710,6 +717,9 @@ Local AsyncWrap::GetOwner(Environment* env, Local obj) { } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(async_wrap, node::AsyncWrap::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL(async_wrap, + node::AsyncWrap::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT(async_wrap, + node::AsyncWrap::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE(async_wrap, node::AsyncWrap::RegisterExternalReferences) diff --git a/src/async_wrap.h b/src/async_wrap.h index b52b4d7ee7d69a..1c6e62846d915c 100644 --- a/src/async_wrap.h +++ b/src/async_wrap.h @@ -147,10 +147,12 @@ class AsyncWrap : public BaseObject { Environment* env); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); - static void Initialize(v8::Local target, - v8::Local unused, - v8::Local context, - void* priv); + static void CreatePerContextProperties(v8::Local target, + v8::Local unused, + v8::Local context, + void* priv); + static void CreatePerIsolateProperties( + IsolateData* isolate_data, v8::Local target); static void GetAsyncId(const v8::FunctionCallbackInfo& args); static void PushAsyncContext(const v8::FunctionCallbackInfo& args); diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index d665b38cfc5f1a..38cb63d8a75643 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -16,10 +16,12 @@ using v8::ArrayBuffer; using v8::BackingStore; using v8::Context; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; using v8::Isolate; using v8::Local; using v8::MaybeLocal; using v8::Object; +using v8::ObjectTemplate; using v8::String; using v8::Uint8Array; using v8::Value; @@ -216,20 +218,23 @@ void BindingData::ToUnicode(const v8::FunctionCallbackInfo& args) { String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked()); } -void BindingData::Initialize(Local target, - Local unused, - Local context, - void* priv) { +void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + SetMethod(isolate, target, "encodeInto", EncodeInto); + SetMethodNoSideEffect(isolate, target, "encodeUtf8String", EncodeUtf8String); + SetMethodNoSideEffect(isolate, target, "decodeUTF8", DecodeUTF8); + SetMethodNoSideEffect(isolate, target, "toASCII", ToASCII); + SetMethodNoSideEffect(isolate, target, "toUnicode", ToUnicode); +} + +void BindingData::CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { Realm* realm = Realm::GetCurrent(context); - BindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; - - SetMethod(context, target, "encodeInto", EncodeInto); - SetMethodNoSideEffect(context, target, "encodeUtf8String", EncodeUtf8String); - SetMethodNoSideEffect(context, target, "decodeUTF8", DecodeUTF8); - SetMethodNoSideEffect(context, target, "toASCII", ToASCII); - SetMethodNoSideEffect(context, target, "toUnicode", ToUnicode); + realm->AddBindingData(context, target); } void BindingData::RegisterTimerExternalReferences( @@ -245,7 +250,11 @@ void BindingData::RegisterTimerExternalReferences( } // namespace node NODE_BINDING_CONTEXT_AWARE_INTERNAL( - encoding_binding, node::encoding_binding::BindingData::Initialize) + encoding_binding, + node::encoding_binding::BindingData::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT( + encoding_binding, + node::encoding_binding::BindingData::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE( encoding_binding, node::encoding_binding::BindingData::RegisterTimerExternalReferences) diff --git a/src/encoding_binding.h b/src/encoding_binding.h index 8a009dfce27731..437aa9c5587918 100644 --- a/src/encoding_binding.h +++ b/src/encoding_binding.h @@ -35,10 +35,12 @@ class BindingData : public SnapshotableObject { static void ToASCII(const v8::FunctionCallbackInfo& args); static void ToUnicode(const v8::FunctionCallbackInfo& args); - static void Initialize(v8::Local target, - v8::Local unused, - v8::Local context, - void* priv); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local ctor); + static void CreatePerContextProperties(v8::Local target, + v8::Local unused, + v8::Local context, + void* priv); static void RegisterTimerExternalReferences( ExternalReferenceRegistry* registry); diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 0a1b0677975122..69e2a389f9e148 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -154,19 +154,24 @@ void HandleWrap::OnClose(uv_handle_t* handle) { wrap->MakeCallback(env->handle_onclose_symbol(), 0, nullptr); } } - Local HandleWrap::GetConstructorTemplate(Environment* env) { - Local tmpl = env->handle_wrap_ctor_template(); + return GetConstructorTemplate(env->isolate_data()); +} + +Local HandleWrap::GetConstructorTemplate( + IsolateData* isolate_data) { + Local tmpl = isolate_data->handle_wrap_ctor_template(); if (tmpl.IsEmpty()) { - Isolate* isolate = env->isolate(); + Isolate* isolate = isolate_data->isolate(); tmpl = NewFunctionTemplate(isolate, nullptr); - tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "HandleWrap")); - tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env)); + tmpl->SetClassName( + FIXED_ONE_BYTE_STRING(isolate_data->isolate(), "HandleWrap")); + tmpl->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); SetProtoMethod(isolate, tmpl, "close", HandleWrap::Close); SetProtoMethodNoSideEffect(isolate, tmpl, "hasRef", HandleWrap::HasRef); SetProtoMethod(isolate, tmpl, "ref", HandleWrap::Ref); SetProtoMethod(isolate, tmpl, "unref", HandleWrap::Unref); - env->set_handle_wrap_ctor_template(tmpl); + isolate_data->set_handle_wrap_ctor_template(tmpl); } return tmpl; } diff --git a/src/handle_wrap.h b/src/handle_wrap.h index a86f8b41c44a72..cc3273432804bf 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -76,6 +76,8 @@ class HandleWrap : public AsyncWrap { virtual void Close( v8::Local close_callback = v8::Local()); + static v8::Local GetConstructorTemplate( + IsolateData* isolate_data); static v8::Local GetConstructorTemplate( Environment* env); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); diff --git a/src/node_binding.h b/src/node_binding.h index 1b024774e120a9..d6e59d19ea4652 100644 --- a/src/node_binding.h +++ b/src/node_binding.h @@ -31,8 +31,16 @@ static_assert(static_cast(NM_F_LINKED) == #endif #define NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) \ + V(async_wrap) \ + V(blob) \ V(builtins) \ + V(contextify) \ + V(encoding_binding) \ + V(fs) \ + V(timers) \ + V(process_methods) \ V(performance) \ + V(url) \ V(worker) \ NODE_BUILTIN_ICU_BINDINGS(V) diff --git a/src/node_blob.cc b/src/node_blob.cc index 4d249a9cbda01c..a7b83f088f0777 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -29,6 +29,7 @@ using v8::Int32; using v8::Isolate; using v8::Local; using v8::Object; +using v8::ObjectTemplate; using v8::String; using v8::Uint32; using v8::Undefined; @@ -107,23 +108,25 @@ void BlobFromFilePath(const FunctionCallbackInfo& args) { } } // namespace -void Blob::Initialize( - Local target, - Local unused, - Local context, - void* priv) { - Realm* realm = Realm::GetCurrent(context); +void Blob::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); - BlobBindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; + SetMethod(isolate, target, "createBlob", New); + SetMethod(isolate, target, "storeDataObject", StoreDataObject); + SetMethod(isolate, target, "getDataObject", GetDataObject); + SetMethod(isolate, target, "revokeObjectURL", RevokeObjectURL); + SetMethod(isolate, target, "concat", Concat); + SetMethod(isolate, target, "createBlobFromFilePath", BlobFromFilePath); +} - SetMethod(context, target, "createBlob", New); - SetMethod(context, target, "storeDataObject", StoreDataObject); - SetMethod(context, target, "getDataObject", GetDataObject); - SetMethod(context, target, "revokeObjectURL", RevokeObjectURL); - SetMethod(context, target, "concat", Concat); - SetMethod(context, target, "createBlobFromFilePath", BlobFromFilePath); +void Blob::CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Realm* realm = Realm::GetCurrent(context); + realm->AddBindingData(context, target); } Local Blob::GetConstructorTemplate(Environment* env) { @@ -562,5 +565,7 @@ void Blob::RegisterExternalReferences(ExternalReferenceRegistry* registry) { } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(blob, node::Blob::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL(blob, + node::Blob::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT(blob, node::Blob::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE(blob, node::Blob::RegisterExternalReferences) diff --git a/src/node_blob.h b/src/node_blob.h index 5007f788482d2a..96468534916e22 100644 --- a/src/node_blob.h +++ b/src/node_blob.h @@ -26,11 +26,12 @@ class Blob : public BaseObject { static void RegisterExternalReferences( ExternalReferenceRegistry* registry); - static void Initialize( - v8::Local target, - v8::Local unused, - v8::Local context, - void* priv); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local ctor); + static void CreatePerContextProperties(v8::Local target, + v8::Local unused, + v8::Local context, + void* priv); static void New(const v8::FunctionCallbackInfo& args); static void GetReader(const v8::FunctionCallbackInfo& args); diff --git a/src/node_contextify.cc b/src/node_contextify.cc index a21acf06a32781..7f9f71ba74223a 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -114,7 +114,6 @@ BaseObjectPtr ContextifyContext::New( Local sandbox_obj, const ContextOptions& options) { HandleScope scope(env->isolate()); - InitializeGlobalTemplates(env->isolate_data()); Local object_template = env->contextify_global_template(); DCHECK(!object_template.IsEmpty()); const SnapshotData* snapshot_data = env->isolate_data()->snapshot_data(); @@ -169,9 +168,6 @@ ContextifyContext::~ContextifyContext() { } void ContextifyContext::InitializeGlobalTemplates(IsolateData* isolate_data) { - if (!isolate_data->contextify_global_template().IsEmpty()) { - return; - } DCHECK(isolate_data->contextify_wrapper_template().IsEmpty()); Local global_func_template = FunctionTemplate::New(isolate_data->isolate()); @@ -322,11 +318,12 @@ BaseObjectPtr ContextifyContext::New( return result; } -void ContextifyContext::Init(Environment* env, Local target) { - Local context = env->context(); - SetMethod(context, target, "makeContext", MakeContext); - SetMethod(context, target, "isContext", IsContext); - SetMethod(context, target, "compileFunction", CompileFunction); +void ContextifyContext::CreatePerIsolateProperties( + IsolateData* isolate_data, Local target) { + Isolate* isolate = isolate_data->isolate(); + SetMethod(isolate, target, "makeContext", MakeContext); + SetMethod(isolate, target, "isContext", IsContext); + SetMethod(isolate, target, "compileFunction", CompileFunction); } void ContextifyContext::RegisterExternalReferences( @@ -735,11 +732,10 @@ void ContextifyContext::IndexedPropertyDeleterCallback( args.GetReturnValue().Set(false); } -void ContextifyScript::Init(Environment* env, Local target) { - Isolate* isolate = env->isolate(); - HandleScope scope(env->isolate()); - Local class_name = - FIXED_ONE_BYTE_STRING(env->isolate(), "ContextifyScript"); +void ContextifyScript::CreatePerIsolateProperties( + IsolateData* isolate_data, Local target) { + Isolate* isolate = isolate_data->isolate(); + Local class_name = FIXED_ONE_BYTE_STRING(isolate, "ContextifyScript"); Local script_tmpl = NewFunctionTemplate(isolate, New); script_tmpl->InstanceTemplate()->SetInternalFieldCount( @@ -748,11 +744,8 @@ void ContextifyScript::Init(Environment* env, Local target) { SetProtoMethod(isolate, script_tmpl, "createCachedData", CreateCachedData); SetProtoMethod(isolate, script_tmpl, "runInContext", RunInContext); - Local context = env->context(); - - target->Set(context, class_name, - script_tmpl->GetFunction(context).ToLocalChecked()).Check(); - env->set_script_context_constructor_template(script_tmpl); + target->Set(isolate, "ContextifyScript", script_tmpl); + isolate_data->set_script_context_constructor_template(script_tmpl); } void ContextifyScript::RegisterExternalReferences( @@ -1382,15 +1375,15 @@ void MicrotaskQueueWrap::New(const FunctionCallbackInfo& args) { new MicrotaskQueueWrap(Environment::GetCurrent(args), args.This()); } -void MicrotaskQueueWrap::Init(Environment* env, Local target) { - Isolate* isolate = env->isolate(); +void MicrotaskQueueWrap::CreatePerIsolateProperties( + IsolateData* isolate_data, Local target) { + Isolate* isolate = isolate_data->isolate(); HandleScope scope(isolate); - Local context = env->context(); Local tmpl = NewFunctionTemplate(isolate, New); tmpl->InstanceTemplate()->SetInternalFieldCount( ContextifyScript::kInternalFieldCount); - env->set_microtask_queue_ctor_template(tmpl); - SetConstructorFunction(context, target, "MicrotaskQueue", tmpl); + isolate_data->set_microtask_queue_ctor_template(tmpl); + SetConstructorFunction(isolate, target, "MicrotaskQueue", tmpl); } void MicrotaskQueueWrap::RegisterExternalReferences( @@ -1398,30 +1391,37 @@ void MicrotaskQueueWrap::RegisterExternalReferences( registry->Register(New); } -void Initialize(Local target, - Local unused, - Local context, - void* priv) { - Environment* env = Environment::GetCurrent(context); - Isolate* isolate = env->isolate(); - ContextifyContext::Init(env, target); - ContextifyScript::Init(env, target); - MicrotaskQueueWrap::Init(env, target); +void CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + ContextifyContext::CreatePerIsolateProperties(isolate_data, target); + ContextifyScript::CreatePerIsolateProperties(isolate_data, target); + MicrotaskQueueWrap::CreatePerIsolateProperties(isolate_data, target); - SetMethod(context, target, "startSigintWatchdog", StartSigintWatchdog); - SetMethod(context, target, "stopSigintWatchdog", StopSigintWatchdog); + SetMethod(isolate, target, "startSigintWatchdog", StartSigintWatchdog); + SetMethod(isolate, target, "stopSigintWatchdog", StopSigintWatchdog); // Used in tests. SetMethodNoSideEffect( - context, target, "watchdogHasPendingSigint", WatchdogHasPendingSigint); + isolate, target, "watchdogHasPendingSigint", WatchdogHasPendingSigint); { - Local tpl = FunctionTemplate::New(env->isolate()); - tpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "CompiledFnEntry")); + Local tpl = FunctionTemplate::New(isolate); + tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "CompiledFnEntry")); tpl->InstanceTemplate()->SetInternalFieldCount( CompiledFnEntry::kInternalFieldCount); - env->set_compiled_fn_entry_template(tpl->InstanceTemplate()); + isolate_data->set_compiled_fn_entry_template(tpl->InstanceTemplate()); } + SetMethod(isolate, target, "measureMemory", MeasureMemory); +} + +static void CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Environment* env = Environment::GetCurrent(context); + Isolate* isolate = env->isolate(); Local constants = Object::New(env->isolate()); Local measure_memory = Object::New(env->isolate()); @@ -1447,8 +1447,6 @@ void Initialize(Local target, READONLY_PROPERTY(constants, "measureMemory", measure_memory); target->Set(context, env->constants_string(), constants).Check(); - - SetMethod(context, target, "measureMemory", MeasureMemory); } void RegisterExternalReferences(ExternalReferenceRegistry* registry) { @@ -1464,6 +1462,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { } // namespace contextify } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(contextify, node::contextify::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL( + contextify, node::contextify::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT(contextify, + node::contextify::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE(contextify, node::contextify::RegisterExternalReferences) diff --git a/src/node_contextify.h b/src/node_contextify.h index 76c89318bb6cbf..3160160521e0fe 100644 --- a/src/node_contextify.h +++ b/src/node_contextify.h @@ -18,7 +18,8 @@ class MicrotaskQueueWrap : public BaseObject { const std::shared_ptr& microtask_queue() const; - static void Init(Environment* env, v8::Local target); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static void New(const v8::FunctionCallbackInfo& args); @@ -58,7 +59,8 @@ class ContextifyContext : public BaseObject { v8::Local object_template, const SnapshotData* snapshot_data, v8::MicrotaskQueue* queue); - static void Init(Environment* env, v8::Local target); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static ContextifyContext* ContextFromContextifiedSandbox( @@ -156,7 +158,8 @@ class ContextifyScript : public BaseObject { ContextifyScript(Environment* env, v8::Local object); ~ContextifyScript() override; - static void Init(Environment* env, v8::Local target); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static void New(const v8::FunctionCallbackInfo& args); static bool InstanceOf(Environment* env, const v8::Local& args); diff --git a/src/node_file.cc b/src/node_file.cc index dc9e1a1606a78a..ed7ec2902f69fa 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -74,7 +74,6 @@ using v8::Object; using v8::ObjectTemplate; using v8::Promise; using v8::String; -using v8::Symbol; using v8::Undefined; using v8::Value; @@ -2827,121 +2826,117 @@ InternalFieldInfoBase* BindingData::Serialize(int index) { return info; } -void Initialize(Local target, - Local unused, - Local context, - void* priv) { - Realm* realm = Realm::GetCurrent(context); - Environment* env = realm->env(); - Isolate* isolate = env->isolate(); - BindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; - - SetMethod(context, target, "access", Access); - SetMethod(context, target, "close", Close); - SetMethod(context, target, "open", Open); - SetMethod(context, target, "openFileHandle", OpenFileHandle); - SetMethod(context, target, "read", Read); - SetMethod(context, target, "readBuffers", ReadBuffers); - SetMethod(context, target, "fdatasync", Fdatasync); - SetMethod(context, target, "fsync", Fsync); - SetMethod(context, target, "rename", Rename); - SetMethod(context, target, "ftruncate", FTruncate); - SetMethod(context, target, "rmdir", RMDir); - SetMethod(context, target, "mkdir", MKDir); - SetMethod(context, target, "readdir", ReadDir); - SetMethod(context, target, "internalModuleReadJSON", InternalModuleReadJSON); - SetMethod(context, target, "internalModuleStat", InternalModuleStat); - SetMethod(context, target, "stat", Stat); - SetMethod(context, target, "lstat", LStat); - SetMethod(context, target, "fstat", FStat); - SetMethod(context, target, "statfs", StatFs); - SetMethod(context, target, "link", Link); - SetMethod(context, target, "symlink", Symlink); - SetMethod(context, target, "readlink", ReadLink); - SetMethod(context, target, "unlink", Unlink); - SetMethod(context, target, "writeBuffer", WriteBuffer); - SetMethod(context, target, "writeBuffers", WriteBuffers); - SetMethod(context, target, "writeString", WriteString); - SetMethod(context, target, "realpath", RealPath); - SetMethod(context, target, "copyFile", CopyFile); - - SetMethod(context, target, "chmod", Chmod); - SetMethod(context, target, "fchmod", FChmod); - - SetMethod(context, target, "chown", Chown); - SetMethod(context, target, "fchown", FChown); - SetMethod(context, target, "lchown", LChown); - - SetMethod(context, target, "utimes", UTimes); - SetMethod(context, target, "futimes", FUTimes); - SetMethod(context, target, "lutimes", LUTimes); - - SetMethod(context, target, "mkdtemp", Mkdtemp); - - target - ->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "kFsStatsFieldsNumber"), - Integer::New( - isolate, - static_cast(FsStatsOffset::kFsStatsFieldsNumber))) - .Check(); - - StatWatcher::Initialize(env, target); +static void CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + + SetMethod(isolate, target, "access", Access); + SetMethod(isolate, target, "close", Close); + SetMethod(isolate, target, "open", Open); + SetMethod(isolate, target, "openFileHandle", OpenFileHandle); + SetMethod(isolate, target, "read", Read); + SetMethod(isolate, target, "readBuffers", ReadBuffers); + SetMethod(isolate, target, "fdatasync", Fdatasync); + SetMethod(isolate, target, "fsync", Fsync); + SetMethod(isolate, target, "rename", Rename); + SetMethod(isolate, target, "ftruncate", FTruncate); + SetMethod(isolate, target, "rmdir", RMDir); + SetMethod(isolate, target, "mkdir", MKDir); + SetMethod(isolate, target, "readdir", ReadDir); + SetMethod(isolate, target, "internalModuleReadJSON", InternalModuleReadJSON); + SetMethod(isolate, target, "internalModuleStat", InternalModuleStat); + SetMethod(isolate, target, "stat", Stat); + SetMethod(isolate, target, "lstat", LStat); + SetMethod(isolate, target, "fstat", FStat); + SetMethod(isolate, target, "statfs", StatFs); + SetMethod(isolate, target, "link", Link); + SetMethod(isolate, target, "symlink", Symlink); + SetMethod(isolate, target, "readlink", ReadLink); + SetMethod(isolate, target, "unlink", Unlink); + SetMethod(isolate, target, "writeBuffer", WriteBuffer); + SetMethod(isolate, target, "writeBuffers", WriteBuffers); + SetMethod(isolate, target, "writeString", WriteString); + SetMethod(isolate, target, "realpath", RealPath); + SetMethod(isolate, target, "copyFile", CopyFile); + + SetMethod(isolate, target, "chmod", Chmod); + SetMethod(isolate, target, "fchmod", FChmod); + + SetMethod(isolate, target, "chown", Chown); + SetMethod(isolate, target, "fchown", FChown); + SetMethod(isolate, target, "lchown", LChown); + + SetMethod(isolate, target, "utimes", UTimes); + SetMethod(isolate, target, "futimes", FUTimes); + SetMethod(isolate, target, "lutimes", LUTimes); + + SetMethod(isolate, target, "mkdtemp", Mkdtemp); + + StatWatcher::CreatePerIsolateProperties(isolate_data, ctor); + + target->Set( + FIXED_ONE_BYTE_STRING(isolate, "kFsStatsFieldsNumber"), + Integer::New(isolate, + static_cast(FsStatsOffset::kFsStatsFieldsNumber))); // Create FunctionTemplate for FSReqCallback Local fst = NewFunctionTemplate(isolate, NewFSReqCallback); fst->InstanceTemplate()->SetInternalFieldCount( FSReqBase::kInternalFieldCount); - fst->Inherit(AsyncWrap::GetConstructorTemplate(env)); - SetConstructorFunction(context, target, "FSReqCallback", fst); + fst->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); + SetConstructorFunction(isolate, target, "FSReqCallback", fst); // Create FunctionTemplate for FileHandleReadWrap. There’s no need // to do anything in the constructor, so we only store the instance template. Local fh_rw = FunctionTemplate::New(isolate); fh_rw->InstanceTemplate()->SetInternalFieldCount( FSReqBase::kInternalFieldCount); - fh_rw->Inherit(AsyncWrap::GetConstructorTemplate(env)); + fh_rw->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); Local fhWrapString = FIXED_ONE_BYTE_STRING(isolate, "FileHandleReqWrap"); fh_rw->SetClassName(fhWrapString); - env->set_filehandlereadwrap_template( - fst->InstanceTemplate()); + isolate_data->set_filehandlereadwrap_template(fst->InstanceTemplate()); // Create Function Template for FSReqPromise Local fpt = FunctionTemplate::New(isolate); - fpt->Inherit(AsyncWrap::GetConstructorTemplate(env)); + fpt->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); Local promiseString = FIXED_ONE_BYTE_STRING(isolate, "FSReqPromise"); fpt->SetClassName(promiseString); Local fpo = fpt->InstanceTemplate(); fpo->SetInternalFieldCount(FSReqBase::kInternalFieldCount); - env->set_fsreqpromise_constructor_template(fpo); + isolate_data->set_fsreqpromise_constructor_template(fpo); // Create FunctionTemplate for FileHandle Local fd = NewFunctionTemplate(isolate, FileHandle::New); - fd->Inherit(AsyncWrap::GetConstructorTemplate(env)); + fd->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); SetProtoMethod(isolate, fd, "close", FileHandle::Close); SetProtoMethod(isolate, fd, "releaseFD", FileHandle::ReleaseFD); Local fdt = fd->InstanceTemplate(); fdt->SetInternalFieldCount(FileHandle::kInternalFieldCount); - StreamBase::AddMethods(env, fd); - SetConstructorFunction(context, target, "FileHandle", fd); - env->set_fd_constructor_template(fdt); + StreamBase::AddMethods(isolate_data, fd); + SetConstructorFunction(isolate, target, "FileHandle", fd); + isolate_data->set_fd_constructor_template(fdt); // Create FunctionTemplate for FileHandle::CloseReq Local fdclose = FunctionTemplate::New(isolate); fdclose->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "FileHandleCloseReq")); - fdclose->Inherit(AsyncWrap::GetConstructorTemplate(env)); + fdclose->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data)); Local fdcloset = fdclose->InstanceTemplate(); fdcloset->SetInternalFieldCount(FSReqBase::kInternalFieldCount); - env->set_fdclose_constructor_template(fdcloset); + isolate_data->set_fdclose_constructor_template(fdcloset); - target->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "kUsePromises"), - env->fs_use_promises_symbol()).Check(); + target->Set(isolate, "kUsePromises", isolate_data->fs_use_promises_symbol()); +} + +static void CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Realm* realm = Realm::GetCurrent(context); + realm->AddBindingData(context, target); } BindingData* FSReqBase::binding_data() { @@ -3004,5 +2999,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { } // end namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs, node::fs::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs, node::fs::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT(fs, node::fs::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE(fs, node::fs::RegisterExternalReferences) diff --git a/src/node_process.h b/src/node_process.h index 5af062e63ea49b..cb8c7962825f46 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -48,7 +48,8 @@ void PatchProcessObject(const v8::FunctionCallbackInfo& args); namespace process { class BindingData : public SnapshotableObject { public: - void AddMethods(); + static void AddMethods(v8::Isolate* isolate, + v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); using InternalFieldInfo = InternalFieldInfoBase; diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 93657860379fdf..bd0ba33d7d8dd9 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -41,6 +41,7 @@ using v8::CFunction; using v8::Context; using v8::Float64Array; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; using v8::HeapStatistics; using v8::Integer; using v8::Isolate; @@ -49,6 +50,7 @@ using v8::Maybe; using v8::NewStringType; using v8::Number; using v8::Object; +using v8::ObjectTemplate; using v8::String; using v8::Uint32; using v8::Value; @@ -478,11 +480,11 @@ BindingData::BindingData(Realm* realm, v8::Local object) v8::CFunction BindingData::fast_number_(v8::CFunction::Make(FastNumber)); v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt)); -void BindingData::AddMethods() { - Local ctx = env()->context(); - SetFastMethodNoSideEffect(ctx, object(), "hrtime", SlowNumber, &fast_number_); +void BindingData::AddMethods(Isolate* isolate, Local target) { SetFastMethodNoSideEffect( - ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_); + isolate, target, "hrtime", SlowNumber, &fast_number_); + SetFastMethodNoSideEffect( + isolate, target, "hrtimeBigInt", SlowBigInt, &fast_bigint_); } void BindingData::RegisterExternalReferences( @@ -569,44 +571,45 @@ void BindingData::Deserialize(Local context, CHECK_NOT_NULL(binding); } -static void Initialize(Local target, - Local unused, - Local context, - void* priv) { - Realm* realm = Realm::GetCurrent(context); - Environment* env = realm->env(); - BindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; - binding_data->AddMethods(); +static void CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + BindingData::AddMethods(isolate, target); // define various internal methods - if (env->owns_process_state()) { - SetMethod(context, target, "_debugProcess", DebugProcess); - SetMethod(context, target, "abort", Abort); - SetMethod(context, target, "causeSegfault", CauseSegfault); - SetMethod(context, target, "chdir", Chdir); - } - - SetMethod(context, target, "umask", Umask); - SetMethod(context, target, "memoryUsage", MemoryUsage); - SetMethod(context, target, "constrainedMemory", GetConstrainedMemory); - SetMethod(context, target, "rss", Rss); - SetMethod(context, target, "cpuUsage", CPUUsage); - SetMethod(context, target, "resourceUsage", ResourceUsage); - - SetMethod(context, target, "_debugEnd", DebugEnd); - SetMethod(context, target, "_getActiveRequests", GetActiveRequests); - SetMethod(context, target, "_getActiveHandles", GetActiveHandles); - SetMethod(context, target, "getActiveResourcesInfo", GetActiveResourcesInfo); - SetMethod(context, target, "_kill", Kill); - SetMethod(context, target, "_rawDebug", RawDebug); - - SetMethodNoSideEffect(context, target, "cwd", Cwd); - SetMethod(context, target, "dlopen", binding::DLOpen); - SetMethod(context, target, "reallyExit", ReallyExit); - SetMethodNoSideEffect(context, target, "uptime", Uptime); - SetMethod(context, target, "patchProcessObject", PatchProcessObject); + SetMethod(isolate, target, "_debugProcess", DebugProcess); + SetMethod(isolate, target, "abort", Abort); + SetMethod(isolate, target, "causeSegfault", CauseSegfault); + SetMethod(isolate, target, "chdir", Chdir); + + SetMethod(isolate, target, "umask", Umask); + SetMethod(isolate, target, "memoryUsage", MemoryUsage); + SetMethod(isolate, target, "constrainedMemory", GetConstrainedMemory); + SetMethod(isolate, target, "rss", Rss); + SetMethod(isolate, target, "cpuUsage", CPUUsage); + SetMethod(isolate, target, "resourceUsage", ResourceUsage); + + SetMethod(isolate, target, "_debugEnd", DebugEnd); + SetMethod(isolate, target, "_getActiveRequests", GetActiveRequests); + SetMethod(isolate, target, "_getActiveHandles", GetActiveHandles); + SetMethod(isolate, target, "getActiveResourcesInfo", GetActiveResourcesInfo); + SetMethod(isolate, target, "_kill", Kill); + SetMethod(isolate, target, "_rawDebug", RawDebug); + + SetMethodNoSideEffect(isolate, target, "cwd", Cwd); + SetMethod(isolate, target, "dlopen", binding::DLOpen); + SetMethod(isolate, target, "reallyExit", ReallyExit); + SetMethodNoSideEffect(isolate, target, "uptime", Uptime); + SetMethod(isolate, target, "patchProcessObject", PatchProcessObject); +} + +static void CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Realm* realm = Realm::GetCurrent(context); + realm->AddBindingData(context, target); } void RegisterExternalReferences(ExternalReferenceRegistry* registry) { @@ -641,6 +644,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { } // namespace process } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(process_methods, node::process::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL(process_methods, + node::process::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT(process_methods, + node::process::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE(process_methods, node::process::RegisterExternalReferences) diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 83b96e9dd2030e..39a22eb2e1fca5 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -40,21 +40,22 @@ using v8::Integer; using v8::Isolate; using v8::Local; using v8::Object; +using v8::ObjectTemplate; using v8::Uint32; using v8::Value; -void StatWatcher::Initialize(Environment* env, Local target) { - Isolate* isolate = env->isolate(); - HandleScope scope(env->isolate()); +void StatWatcher::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); Local t = NewFunctionTemplate(isolate, StatWatcher::New); t->InstanceTemplate()->SetInternalFieldCount( StatWatcher::kInternalFieldCount); - t->Inherit(HandleWrap::GetConstructorTemplate(env)); - + t->Inherit(HandleWrap::GetConstructorTemplate(isolate_data)); SetProtoMethod(isolate, t, "start", StatWatcher::Start); - SetConstructorFunction(env->context(), target, "StatWatcher", t); + SetConstructorFunction(isolate, target, "StatWatcher", t); } void StatWatcher::RegisterExternalReferences( diff --git a/src/node_stat_watcher.h b/src/node_stat_watcher.h index 7efd22fdfdb841..cc76975ddb5653 100644 --- a/src/node_stat_watcher.h +++ b/src/node_stat_watcher.h @@ -39,7 +39,8 @@ class ExternalReferenceRegistry; class StatWatcher : public HandleWrap { public: - static void Initialize(Environment* env, v8::Local target); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local ctor); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); protected: diff --git a/src/node_url.cc b/src/node_url.cc index 02f9e580971796..078e155fc49374 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -19,11 +19,13 @@ using v8::CFunction; using v8::Context; using v8::FastOneByteString; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; using v8::HandleScope; using v8::Isolate; using v8::Local; using v8::NewStringType; using v8::Object; +using v8::ObjectTemplate; using v8::String; using v8::Value; @@ -322,22 +324,25 @@ void BindingData::UpdateComponents(const ada::url_components& components, "kURLComponentsLength should be up-to-date"); } -void BindingData::Initialize(Local target, - Local unused, - Local context, - void* priv) { - Realm* realm = Realm::GetCurrent(context); - BindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; - - SetMethodNoSideEffect(context, target, "domainToASCII", DomainToASCII); - SetMethodNoSideEffect(context, target, "domainToUnicode", DomainToUnicode); - SetMethodNoSideEffect(context, target, "format", Format); - SetMethod(context, target, "parse", Parse); - SetMethod(context, target, "update", Update); +void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); + SetMethodNoSideEffect(isolate, target, "domainToASCII", DomainToASCII); + SetMethodNoSideEffect(isolate, target, "domainToUnicode", DomainToUnicode); + SetMethodNoSideEffect(isolate, target, "format", Format); + SetMethod(isolate, target, "parse", Parse); + SetMethod(isolate, target, "update", Update); SetFastMethodNoSideEffect( - context, target, "canParse", CanParse, &fast_can_parse_); + isolate, target, "canParse", CanParse, &fast_can_parse_); +} + +void BindingData::CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Realm* realm = Realm::GetCurrent(context); + realm->AddBindingData(context, target); } void BindingData::RegisterExternalReferences( @@ -365,6 +370,9 @@ std::string FromFilePath(const std::string_view file_path) { } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(url, node::url::BindingData::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL( + url, node::url::BindingData::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT( + url, node::url::BindingData::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE( url, node::url::BindingData::RegisterExternalReferences) diff --git a/src/node_url.h b/src/node_url.h index 735a191e5eac16..04a57a9e2c413a 100644 --- a/src/node_url.h +++ b/src/node_url.h @@ -56,10 +56,12 @@ class BindingData : public SnapshotableObject { static void Parse(const v8::FunctionCallbackInfo& args); static void Update(const v8::FunctionCallbackInfo& args); - static void Initialize(v8::Local target, - v8::Local unused, - v8::Local context, - void* priv); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local ctor); + static void CreatePerContextProperties(v8::Local target, + v8::Local unused, + v8::Local context, + void* priv); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); private: diff --git a/src/stream_base.cc b/src/stream_base.cc index f1769ca52970fe..65dab1ccac7cde 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -491,13 +491,12 @@ Local StreamBase::GetObject() { return GetAsyncWrap()->object(); } -void StreamBase::AddMethod(Environment* env, +void StreamBase::AddMethod(Isolate* isolate, Local signature, enum PropertyAttribute attributes, Local t, JSMethodFunction* stream_method, Local string) { - Isolate* isolate = env->isolate(); Local templ = NewFunctionTemplate(isolate, stream_method, @@ -509,19 +508,37 @@ void StreamBase::AddMethod(Environment* env, } void StreamBase::AddMethods(Environment* env, Local t) { - Isolate* isolate = env->isolate(); + AddMethods(env->isolate_data(), t); +} + +void StreamBase::AddMethods(IsolateData* isolate_data, + Local t) { + Isolate* isolate = isolate_data->isolate(); HandleScope scope(isolate); enum PropertyAttribute attributes = static_cast(ReadOnly | DontDelete | DontEnum); Local sig = Signature::New(isolate, t); - AddMethod(env, sig, attributes, t, GetFD, env->fd_string()); - AddMethod( - env, sig, attributes, t, GetExternal, env->external_stream_string()); - AddMethod(env, sig, attributes, t, GetBytesRead, env->bytes_read_string()); - AddMethod( - env, sig, attributes, t, GetBytesWritten, env->bytes_written_string()); + AddMethod(isolate, sig, attributes, t, GetFD, isolate_data->fd_string()); + AddMethod(isolate, + sig, + attributes, + t, + GetExternal, + isolate_data->external_stream_string()); + AddMethod(isolate, + sig, + attributes, + t, + GetBytesRead, + isolate_data->bytes_read_string()); + AddMethod(isolate, + sig, + attributes, + t, + GetBytesWritten, + isolate_data->bytes_written_string()); SetProtoMethod(isolate, t, "readStart", JSMethod<&StreamBase::ReadStartJS>); SetProtoMethod(isolate, t, "readStop", JSMethod<&StreamBase::ReadStopJS>); SetProtoMethod(isolate, t, "shutdown", JSMethod<&StreamBase::Shutdown>); diff --git a/src/stream_base.h b/src/stream_base.h index 3035ae89715518..e96ff036157ab9 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -313,6 +313,8 @@ class StreamBase : public StreamResource { kInternalFieldCount }; + static void AddMethods(IsolateData* isolate_data, + v8::Local target); static void AddMethods(Environment* env, v8::Local target); static void RegisterExternalReferences(ExternalReferenceRegistry* registry); @@ -409,7 +411,7 @@ class StreamBase : public StreamResource { EmitToJSStreamListener default_listener_; void SetWriteResult(const StreamWriteResult& res); - static void AddMethod(Environment* env, + static void AddMethod(v8::Isolate* isolate, v8::Local sig, enum v8::PropertyAttribute attributes, v8::Local t, diff --git a/src/timers.cc b/src/timers.cc index 2f10daba12ef3a..8318894e33cb54 100644 --- a/src/timers.cc +++ b/src/timers.cc @@ -12,9 +12,12 @@ namespace timers { using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; +using v8::Isolate; using v8::Local; using v8::Number; using v8::Object; +using v8::ObjectTemplate; using v8::Value; void BindingData::SetupTimers(const FunctionCallbackInfo& args) { @@ -119,34 +122,40 @@ v8::CFunction BindingData::fast_toggle_timer_ref_( v8::CFunction BindingData::fast_toggle_immediate_ref_( v8::CFunction::Make(FastToggleImmediateRef)); -void BindingData::Initialize(Local target, - Local unused, - Local context, - void* priv) { - Realm* realm = Realm::GetCurrent(context); - Environment* env = realm->env(); - BindingData* const binding_data = - realm->AddBindingData(context, target); - if (binding_data == nullptr) return; +void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, + Local ctor) { + Isolate* isolate = isolate_data->isolate(); + Local target = ctor->InstanceTemplate(); - SetMethod(context, target, "setupTimers", SetupTimers); + SetMethod(isolate, target, "setupTimers", SetupTimers); SetFastMethod( - context, target, "getLibuvNow", SlowGetLibuvNow, &fast_get_libuv_now_); - SetFastMethod(context, + isolate, target, "getLibuvNow", SlowGetLibuvNow, &fast_get_libuv_now_); + SetFastMethod(isolate, target, "scheduleTimer", SlowScheduleTimer, &fast_schedule_timers_); - SetFastMethod(context, + SetFastMethod(isolate, target, "toggleTimerRef", SlowToggleTimerRef, &fast_toggle_timer_ref_); - SetFastMethod(context, + SetFastMethod(isolate, target, "toggleImmediateRef", SlowToggleImmediateRef, &fast_toggle_immediate_ref_); +} + +void BindingData::CreatePerContextProperties(Local target, + Local unused, + Local context, + void* priv) { + Realm* realm = Realm::GetCurrent(context); + Environment* env = realm->env(); + BindingData* const binding_data = + realm->AddBindingData(context, target); + if (binding_data == nullptr) return; // TODO(joyeecheung): move these into BindingData. target @@ -187,7 +196,9 @@ void BindingData::RegisterTimerExternalReferences( } // namespace node -NODE_BINDING_CONTEXT_AWARE_INTERNAL(timers, - node::timers::BindingData::Initialize) +NODE_BINDING_CONTEXT_AWARE_INTERNAL( + timers, node::timers::BindingData::CreatePerContextProperties) +NODE_BINDING_PER_ISOLATE_INIT( + timers, node::timers::BindingData::CreatePerIsolateProperties) NODE_BINDING_EXTERNAL_REFERENCE( timers, node::timers::BindingData::RegisterTimerExternalReferences) diff --git a/src/timers.h b/src/timers.h index 7f2ac45e71af6d..61cc5d6bf8ed43 100644 --- a/src/timers.h +++ b/src/timers.h @@ -45,10 +45,12 @@ class BindingData : public SnapshotableObject { static void FastToggleImmediateRef(v8::Local receiver, bool ref); static void ToggleImmediateRefImpl(BindingData* data, bool ref); - static void Initialize(v8::Local target, - v8::Local unused, - v8::Local context, - void* priv); + static void CreatePerIsolateProperties(IsolateData* isolate_data, + v8::Local ctor); + static void CreatePerContextProperties(v8::Local target, + v8::Local unused, + v8::Local context, + void* priv); static void RegisterTimerExternalReferences( ExternalReferenceRegistry* registry);