@@ -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;
@@ -882,19 +883,17 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
882
883
}
883
884
}
884
885
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 ();
891
890
892
891
{
893
892
Local<FunctionTemplate> w = NewFunctionTemplate (isolate, Worker::New);
894
893
895
894
w->InstanceTemplate ()->SetInternalFieldCount (
896
895
Worker::kInternalFieldCount );
897
- w->Inherit (AsyncWrap::GetConstructorTemplate (env ));
896
+ w->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
898
897
899
898
SetProtoMethod (isolate, w, " startThread" , Worker::StartThread);
900
899
SetProtoMethod (isolate, w, " stopThread" , Worker::StopThread);
@@ -906,23 +905,32 @@ void InitWorker(Local<Object> target,
906
905
SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
907
906
SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
908
907
909
- SetConstructorFunction (context, target , " Worker" , w);
908
+ SetConstructorFunction (isolate, proto , " Worker" , w);
910
909
}
911
910
912
911
{
913
912
Local<FunctionTemplate> wst = NewFunctionTemplate (isolate, nullptr );
914
913
915
914
wst->InstanceTemplate ()->SetInternalFieldCount (
916
915
WorkerHeapSnapshotTaker::kInternalFieldCount );
917
- wst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
916
+ wst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
918
917
919
918
Local<String> wst_string =
920
919
FIXED_ONE_BYTE_STRING (isolate, " WorkerHeapSnapshotTaker" );
921
920
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 ());
923
923
}
924
924
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 ();
926
934
927
935
target
928
936
->Set (env->context (),
@@ -975,6 +983,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
975
983
} // namespace worker
976
984
} // namespace node
977
985
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)
979
990
NODE_BINDING_EXTERNAL_REFERENCE(worker,
980
991
node::worker::RegisterExternalReferences)
0 commit comments