@@ -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;
@@ -858,19 +859,17 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
858859 }
859860}
860861
861- void InitWorker (Local<Object> target,
862- Local<Value> unused,
863- Local<Context> context,
864- void * priv) {
865- Environment* env = Environment::GetCurrent (context);
866- Isolate* isolate = env->isolate ();
862+ void CreateWorkerPerIsolateProperties (IsolateData* isolate_data,
863+ Local<FunctionTemplate> target) {
864+ Isolate* isolate = isolate_data->isolate ();
865+ Local<ObjectTemplate> proto = target->PrototypeTemplate ();
867866
868867 {
869868 Local<FunctionTemplate> w = NewFunctionTemplate (isolate, Worker::New);
870869
871870 w->InstanceTemplate ()->SetInternalFieldCount (
872871 Worker::kInternalFieldCount );
873- w->Inherit (AsyncWrap::GetConstructorTemplate (env ));
872+ w->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
874873
875874 SetProtoMethod (isolate, w, " startThread" , Worker::StartThread);
876875 SetProtoMethod (isolate, w, " stopThread" , Worker::StopThread);
@@ -882,23 +881,32 @@ void InitWorker(Local<Object> target,
882881 SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
883882 SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
884883
885- SetConstructorFunction (context, target , " Worker" , w);
884+ SetConstructorFunction (isolate, proto , " Worker" , w);
886885 }
887886
888887 {
889888 Local<FunctionTemplate> wst = NewFunctionTemplate (isolate, nullptr );
890889
891890 wst->InstanceTemplate ()->SetInternalFieldCount (
892891 WorkerHeapSnapshotTaker::kInternalFieldCount );
893- wst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
892+ wst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
894893
895894 Local<String> wst_string =
896895 FIXED_ONE_BYTE_STRING (isolate, " WorkerHeapSnapshotTaker" );
897896 wst->SetClassName (wst_string);
898- env->set_worker_heap_snapshot_taker_template (wst->InstanceTemplate ());
897+ isolate_data->set_worker_heap_snapshot_taker_template (
898+ wst->InstanceTemplate ());
899899 }
900900
901- SetMethod (context, target, " getEnvMessagePort" , GetEnvMessagePort);
901+ SetMethod (isolate, proto, " getEnvMessagePort" , GetEnvMessagePort);
902+ }
903+
904+ void CreateWorkerPerContextProperties (Local<Object> target,
905+ Local<Value> unused,
906+ Local<Context> context,
907+ void * priv) {
908+ Environment* env = Environment::GetCurrent (context);
909+ Isolate* isolate = env->isolate ();
902910
903911 target
904912 ->Set (env->context (),
@@ -951,6 +959,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
951959} // namespace worker
952960} // namespace node
953961
954- NODE_BINDING_CONTEXT_AWARE_INTERNAL (worker, node::worker::InitWorker)
962+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (
963+ worker, node::worker::CreateWorkerPerContextProperties)
964+ NODE_BINDING_PER_ISOLATE_INIT(worker,
965+ node::worker::CreateWorkerPerIsolateProperties)
955966NODE_BINDING_EXTERNAL_REFERENCE(worker,
956967 node::worker::RegisterExternalReferences)
0 commit comments