@@ -34,6 +34,7 @@ using v8::MaybeLocal;
3434using v8::Null;
3535using v8::Number;
3636using v8::Object;
37+ using v8::ObjectTemplate;
3738using v8::ResourceConstraints;
3839using v8::SealHandleScope;
3940using v8::String;
@@ -882,19 +883,16 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
882883 }
883884}
884885
885- void InitWorker (Local<Object> target,
886- Local<Value> unused,
887- Local<Context> context,
888- void * priv) {
889- Environment* env = Environment::GetCurrent (context);
890- Isolate* isolate = env->isolate ();
886+ void InitWorker (IsolateData* isolate_data, Local<FunctionTemplate> target) {
887+ Isolate* isolate = isolate_data->isolate ();
888+ Local<ObjectTemplate> proto = target->PrototypeTemplate ();
891889
892890 {
893891 Local<FunctionTemplate> w = NewFunctionTemplate (isolate, Worker::New);
894892
895893 w->InstanceTemplate ()->SetInternalFieldCount (
896894 Worker::kInternalFieldCount );
897- w->Inherit (AsyncWrap::GetConstructorTemplate (env ));
895+ w->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
898896
899897 SetProtoMethod (isolate, w, " startThread" , Worker::StartThread);
900898 SetProtoMethod (isolate, w, " stopThread" , Worker::StopThread);
@@ -906,23 +904,32 @@ void InitWorker(Local<Object> target,
906904 SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
907905 SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
908906
909- SetConstructorFunction (context, target , " Worker" , w);
907+ SetConstructorFunction (isolate, proto , " Worker" , w);
910908 }
911909
912910 {
913911 Local<FunctionTemplate> wst = NewFunctionTemplate (isolate, nullptr );
914912
915913 wst->InstanceTemplate ()->SetInternalFieldCount (
916914 WorkerHeapSnapshotTaker::kInternalFieldCount );
917- wst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
915+ wst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
918916
919917 Local<String> wst_string =
920918 FIXED_ONE_BYTE_STRING (isolate, " WorkerHeapSnapshotTaker" );
921919 wst->SetClassName (wst_string);
922- env->set_worker_heap_snapshot_taker_template (wst->InstanceTemplate ());
920+ isolate_data->set_worker_heap_snapshot_taker_template (
921+ wst->InstanceTemplate ());
923922 }
924923
925- SetMethod (context, target, " getEnvMessagePort" , GetEnvMessagePort);
924+ SetMethod (isolate, proto, " getEnvMessagePort" , GetEnvMessagePort);
925+ }
926+
927+ void InitWorker (Local<Object> target,
928+ Local<Value> unused,
929+ Local<Context> context,
930+ void * priv) {
931+ Environment* env = Environment::GetCurrent (context);
932+ Isolate* isolate = env->isolate ();
926933
927934 target
928935 ->Set (env->context (),
@@ -976,5 +983,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
976983} // namespace node
977984
978985NODE_BINDING_CONTEXT_AWARE_INTERNAL (worker, node::worker::InitWorker)
986+ NODE_BINDING_PER_ISOLATE_INIT(worker, node::worker::InitWorker)
979987NODE_BINDING_EXTERNAL_REFERENCE(worker,
980988 node::worker::RegisterExternalReferences)
0 commit comments