@@ -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,17 @@ 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 CreateWorkerPerIsolateProperties (IsolateData* isolate_data,
887+ Local<FunctionTemplate> target) {
888+ Isolate* isolate = isolate_data->isolate ();
889+ Local<ObjectTemplate> proto = target->PrototypeTemplate ();
891890
892891 {
893892 Local<FunctionTemplate> w = NewFunctionTemplate (isolate, Worker::New);
894893
895894 w->InstanceTemplate ()->SetInternalFieldCount (
896895 Worker::kInternalFieldCount );
897- w->Inherit (AsyncWrap::GetConstructorTemplate (env ));
896+ w->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
898897
899898 SetProtoMethod (isolate, w, " startThread" , Worker::StartThread);
900899 SetProtoMethod (isolate, w, " stopThread" , Worker::StopThread);
@@ -906,23 +905,32 @@ void InitWorker(Local<Object> target,
906905 SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
907906 SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
908907
909- SetConstructorFunction (context, target , " Worker" , w);
908+ SetConstructorFunction (isolate, proto , " Worker" , w);
910909 }
911910
912911 {
913912 Local<FunctionTemplate> wst = NewFunctionTemplate (isolate, nullptr );
914913
915914 wst->InstanceTemplate ()->SetInternalFieldCount (
916915 WorkerHeapSnapshotTaker::kInternalFieldCount );
917- wst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
916+ wst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
918917
919918 Local<String> wst_string =
920919 FIXED_ONE_BYTE_STRING (isolate, " WorkerHeapSnapshotTaker" );
921920 wst->SetClassName (wst_string);
922- env->set_worker_heap_snapshot_taker_template (wst->InstanceTemplate ());
921+ isolate_data->set_worker_heap_snapshot_taker_template (
922+ wst->InstanceTemplate ());
923923 }
924924
925- SetMethod (context, target, " getEnvMessagePort" , GetEnvMessagePort);
925+ SetMethod (isolate, proto, " getEnvMessagePort" , GetEnvMessagePort);
926+ }
927+
928+ void CreateWorkerPerContextProperties (Local<Object> target,
929+ Local<Value> unused,
930+ Local<Context> context,
931+ void * priv) {
932+ Environment* env = Environment::GetCurrent (context);
933+ Isolate* isolate = env->isolate ();
926934
927935 target
928936 ->Set (env->context (),
@@ -975,6 +983,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
975983} // namespace worker
976984} // namespace node
977985
978- NODE_BINDING_CONTEXT_AWARE_INTERNAL (worker, node::worker::InitWorker)
986+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (
987+ worker, node::worker::CreateWorkerPerContextProperties)
988+ NODE_BINDING_PER_ISOLATE_INIT(worker,
989+ node::worker::CreateWorkerPerIsolateProperties)
979990NODE_BINDING_EXTERNAL_REFERENCE(worker,
980991 node::worker::RegisterExternalReferences)
0 commit comments