@@ -34,6 +34,7 @@ using v8::MaybeLocal;
34
34
using v8::Null;
35
35
using v8::Number;
36
36
using v8::Object;
37
+ using v8::ObjectTemplate;
37
38
using v8::ResourceConstraints;
38
39
using v8::SealHandleScope;
39
40
using v8::String;
@@ -876,19 +877,17 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
876
877
}
877
878
}
878
879
879
- void InitWorker (Local<Object> target,
880
- Local<Value> unused,
881
- Local<Context> context,
882
- void * priv) {
883
- Environment* env = Environment::GetCurrent (context);
884
- Isolate* isolate = env->isolate ();
880
+ void CreateWorkerPerIsolateProperties (IsolateData* isolate_data,
881
+ Local<FunctionTemplate> target) {
882
+ Isolate* isolate = isolate_data->isolate ();
883
+ Local<ObjectTemplate> proto = target->PrototypeTemplate ();
885
884
886
885
{
887
886
Local<FunctionTemplate> w = NewFunctionTemplate (isolate, Worker::New);
888
887
889
888
w->InstanceTemplate ()->SetInternalFieldCount (
890
889
Worker::kInternalFieldCount );
891
- w->Inherit (AsyncWrap::GetConstructorTemplate (env ));
890
+ w->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
892
891
893
892
SetProtoMethod (isolate, w, " startThread" , Worker::StartThread);
894
893
SetProtoMethod (isolate, w, " stopThread" , Worker::StopThread);
@@ -900,23 +899,32 @@ void InitWorker(Local<Object> target,
900
899
SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
901
900
SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
902
901
903
- SetConstructorFunction (context, target , " Worker" , w);
902
+ SetConstructorFunction (isolate, proto , " Worker" , w);
904
903
}
905
904
906
905
{
907
906
Local<FunctionTemplate> wst = NewFunctionTemplate (isolate, nullptr );
908
907
909
908
wst->InstanceTemplate ()->SetInternalFieldCount (
910
909
WorkerHeapSnapshotTaker::kInternalFieldCount );
911
- wst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
910
+ wst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
912
911
913
912
Local<String> wst_string =
914
913
FIXED_ONE_BYTE_STRING (isolate, " WorkerHeapSnapshotTaker" );
915
914
wst->SetClassName (wst_string);
916
- env->set_worker_heap_snapshot_taker_template (wst->InstanceTemplate ());
915
+ isolate_data->set_worker_heap_snapshot_taker_template (
916
+ wst->InstanceTemplate ());
917
917
}
918
918
919
- SetMethod (context, target, " getEnvMessagePort" , GetEnvMessagePort);
919
+ SetMethod (isolate, proto, " getEnvMessagePort" , GetEnvMessagePort);
920
+ }
921
+
922
+ void CreateWorkerPerContextProperties (Local<Object> target,
923
+ Local<Value> unused,
924
+ Local<Context> context,
925
+ void * priv) {
926
+ Environment* env = Environment::GetCurrent (context);
927
+ Isolate* isolate = env->isolate ();
920
928
921
929
target
922
930
->Set (env->context (),
@@ -969,6 +977,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
969
977
} // namespace worker
970
978
} // namespace node
971
979
972
- NODE_BINDING_CONTEXT_AWARE_INTERNAL (worker, node::worker::InitWorker)
980
+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (
981
+ worker, node::worker::CreateWorkerPerContextProperties)
982
+ NODE_BINDING_PER_ISOLATE_INIT(worker,
983
+ node::worker::CreateWorkerPerIsolateProperties)
973
984
NODE_BINDING_EXTERNAL_REFERENCE(worker,
974
985
node::worker::RegisterExternalReferences)
0 commit comments