@@ -30,6 +30,7 @@ using v8::Maybe;
30
30
using v8::MaybeLocal;
31
31
using v8::Nothing;
32
32
using v8::Object;
33
+ using v8::ObjectTemplate;
33
34
using v8::SharedArrayBuffer;
34
35
using v8::SharedValueConveyor;
35
36
using v8::String;
@@ -717,7 +718,8 @@ MessagePort* MessagePort::New(
717
718
std::unique_ptr<MessagePortData> data,
718
719
std::shared_ptr<SiblingGroup> sibling_group) {
719
720
Context::Scope context_scope (context);
720
- Local<FunctionTemplate> ctor_templ = GetMessagePortConstructorTemplate (env);
721
+ Local<FunctionTemplate> ctor_templ =
722
+ GetMessagePortConstructorTemplate (env->isolate_data ());
721
723
722
724
// Construct a new instance, then assign the listener instance and possibly
723
725
// the MessagePortData to it.
@@ -1116,7 +1118,8 @@ void MessagePort::Stop(const FunctionCallbackInfo<Value>& args) {
1116
1118
void MessagePort::CheckType (const FunctionCallbackInfo<Value>& args) {
1117
1119
Environment* env = Environment::GetCurrent (args);
1118
1120
args.GetReturnValue ().Set (
1119
- GetMessagePortConstructorTemplate (env)->HasInstance (args[0 ]));
1121
+ GetMessagePortConstructorTemplate (env->isolate_data ())
1122
+ ->HasInstance (args[0 ]));
1120
1123
}
1121
1124
1122
1125
void MessagePort::Drain (const FunctionCallbackInfo<Value>& args) {
@@ -1193,28 +1196,30 @@ void MessagePort::MemoryInfo(MemoryTracker* tracker) const {
1193
1196
tracker->TrackField (" emit_message_fn" , emit_message_fn_);
1194
1197
}
1195
1198
1196
- Local<FunctionTemplate> GetMessagePortConstructorTemplate (Environment* env) {
1199
+ Local<FunctionTemplate> GetMessagePortConstructorTemplate (
1200
+ IsolateData* isolate_data) {
1197
1201
// Factor generating the MessagePort JS constructor into its own piece
1198
1202
// of code, because it is needed early on in the child environment setup.
1199
- Local<FunctionTemplate> templ = env->message_port_constructor_template ();
1203
+ Local<FunctionTemplate> templ =
1204
+ isolate_data->message_port_constructor_template ();
1200
1205
if (!templ.IsEmpty ())
1201
1206
return templ;
1202
1207
1203
1208
{
1204
- Isolate* isolate = env ->isolate ();
1209
+ Isolate* isolate = isolate_data ->isolate ();
1205
1210
Local<FunctionTemplate> m = NewFunctionTemplate (isolate, MessagePort::New);
1206
- m->SetClassName (env ->message_port_constructor_string ());
1211
+ m->SetClassName (isolate_data ->message_port_constructor_string ());
1207
1212
m->InstanceTemplate ()->SetInternalFieldCount (
1208
1213
MessagePort::kInternalFieldCount );
1209
- m->Inherit (HandleWrap::GetConstructorTemplate (env ));
1214
+ m->Inherit (HandleWrap::GetConstructorTemplate (isolate_data ));
1210
1215
1211
1216
SetProtoMethod (isolate, m, " postMessage" , MessagePort::PostMessage);
1212
1217
SetProtoMethod (isolate, m, " start" , MessagePort::Start);
1213
1218
1214
- env ->set_message_port_constructor_template (m);
1219
+ isolate_data ->set_message_port_constructor_template (m);
1215
1220
}
1216
1221
1217
- return GetMessagePortConstructorTemplate (env );
1222
+ return GetMessagePortConstructorTemplate (isolate_data );
1218
1223
}
1219
1224
1220
1225
// static
@@ -1636,15 +1641,12 @@ static void BroadcastChannel(const FunctionCallbackInfo<Value>& args) {
1636
1641
}
1637
1642
}
1638
1643
1639
- static void InitMessaging (Local<Object> target,
1640
- Local<Value> unused,
1641
- Local<Context> context,
1642
- void * priv) {
1643
- Environment* env = Environment::GetCurrent (context);
1644
- Isolate* isolate = env->isolate ();
1644
+ static void CreatePerIsolateProperties (IsolateData* isolate_data,
1645
+ Local<ObjectTemplate> target) {
1646
+ Isolate* isolate = isolate_data->isolate ();
1645
1647
1646
1648
{
1647
- SetConstructorFunction (context ,
1649
+ SetConstructorFunction (isolate ,
1648
1650
target,
1649
1651
" MessageChannel" ,
1650
1652
NewFunctionTemplate (isolate, MessageChannel));
@@ -1655,31 +1657,36 @@ static void InitMessaging(Local<Object> target,
1655
1657
t->InstanceTemplate ()->SetInternalFieldCount (
1656
1658
JSTransferable::kInternalFieldCount );
1657
1659
t->SetClassName (OneByteString (isolate, " JSTransferable" ));
1658
- env-> isolate_data () ->set_js_transferable_constructor_template (t);
1660
+ isolate_data->set_js_transferable_constructor_template (t);
1659
1661
}
1660
1662
1661
- SetConstructorFunction (context ,
1663
+ SetConstructorFunction (isolate ,
1662
1664
target,
1663
- env->message_port_constructor_string (),
1664
- GetMessagePortConstructorTemplate (env),
1665
- SetConstructorFunctionFlag::NONE);
1665
+ isolate_data->message_port_constructor_string (),
1666
+ GetMessagePortConstructorTemplate (isolate_data));
1666
1667
1667
1668
// These are not methods on the MessagePort prototype, because
1668
1669
// the browser equivalents do not provide them.
1669
- SetMethod (context , target, " stopMessagePort" , MessagePort::Stop);
1670
- SetMethod (context , target, " checkMessagePort" , MessagePort::CheckType);
1671
- SetMethod (context , target, " drainMessagePort" , MessagePort::Drain);
1670
+ SetMethod (isolate , target, " stopMessagePort" , MessagePort::Stop);
1671
+ SetMethod (isolate , target, " checkMessagePort" , MessagePort::CheckType);
1672
+ SetMethod (isolate , target, " drainMessagePort" , MessagePort::Drain);
1672
1673
SetMethod (
1673
- context , target, " receiveMessageOnPort" , MessagePort::ReceiveMessage);
1674
+ isolate , target, " receiveMessageOnPort" , MessagePort::ReceiveMessage);
1674
1675
SetMethod (
1675
- context , target, " moveMessagePortToContext" , MessagePort::MoveToContext);
1676
- SetMethod (context ,
1676
+ isolate , target, " moveMessagePortToContext" , MessagePort::MoveToContext);
1677
+ SetMethod (isolate ,
1677
1678
target,
1678
1679
" setDeserializerCreateObjectFunction" ,
1679
1680
SetDeserializerCreateObjectFunction);
1680
- SetMethod (context, target, " broadcastChannel" , BroadcastChannel);
1681
- SetMethod (context, target, " structuredClone" , StructuredClone);
1681
+ SetMethod (isolate, target, " broadcastChannel" , BroadcastChannel);
1682
+ SetMethod (isolate, target, " structuredClone" , StructuredClone);
1683
+ }
1682
1684
1685
+ static void CreatePerContextProperties (Local<Object> target,
1686
+ Local<Value> unused,
1687
+ Local<Context> context,
1688
+ void * priv) {
1689
+ Environment* env = Environment::GetCurrent (context);
1683
1690
{
1684
1691
Local<Function> domexception = GetDOMException (context).ToLocalChecked ();
1685
1692
target
@@ -1710,6 +1717,9 @@ static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
1710
1717
} // namespace worker
1711
1718
} // namespace node
1712
1719
1713
- NODE_BINDING_CONTEXT_AWARE_INTERNAL (messaging, node::worker::InitMessaging)
1720
+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (messaging,
1721
+ node::worker::CreatePerContextProperties)
1722
+ NODE_BINDING_PER_ISOLATE_INIT (messaging,
1723
+ node::worker::CreatePerIsolateProperties)
1714
1724
NODE_BINDING_EXTERNAL_REFERENCE (messaging,
1715
1725
node::worker::RegisterExternalReferences)
0 commit comments