@@ -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; |
@@ -707,7 +708,8 @@ MessagePort* MessagePort::New( |
707 | 708 | std::unique_ptr<MessagePortData> data, |
708 | 709 | std::shared_ptr<SiblingGroup> sibling_group) { |
709 | 710 | Context::Scope context_scope(context); |
710 | | - Local<FunctionTemplate> ctor_templ = GetMessagePortConstructorTemplate(env); |
| 711 | + Local<FunctionTemplate> ctor_templ = |
| 712 | + GetMessagePortConstructorTemplate(env->isolate_data()); |
711 | 713 |
|
712 | 714 | // Construct a new instance, then assign the listener instance and possibly |
713 | 715 | // the MessagePortData to it. |
@@ -1107,7 +1109,8 @@ void MessagePort::Stop(const FunctionCallbackInfo<Value>& args) { |
1107 | 1109 | void MessagePort::CheckType(const FunctionCallbackInfo<Value>& args) { |
1108 | 1110 | Environment* env = Environment::GetCurrent(args); |
1109 | 1111 | args.GetReturnValue().Set( |
1110 | | - GetMessagePortConstructorTemplate(env)->HasInstance(args[0])); |
| 1112 | + GetMessagePortConstructorTemplate(env->isolate_data()) |
| 1113 | + ->HasInstance(args[0])); |
1111 | 1114 | } |
1112 | 1115 |
|
1113 | 1116 | void MessagePort::Drain(const FunctionCallbackInfo<Value>& args) { |
@@ -1184,28 +1187,30 @@ void MessagePort::MemoryInfo(MemoryTracker* tracker) const { |
1184 | 1187 | tracker->TrackField("emit_message_fn", emit_message_fn_); |
1185 | 1188 | } |
1186 | 1189 |
|
1187 | | -Local<FunctionTemplate> GetMessagePortConstructorTemplate(Environment* env) { |
| 1190 | +Local<FunctionTemplate> GetMessagePortConstructorTemplate( |
| 1191 | + IsolateData* isolate_data) { |
1188 | 1192 | // Factor generating the MessagePort JS constructor into its own piece |
1189 | 1193 | // of code, because it is needed early on in the child environment setup. |
1190 | | - Local<FunctionTemplate> templ = env->message_port_constructor_template(); |
| 1194 | + Local<FunctionTemplate> templ = |
| 1195 | + isolate_data->message_port_constructor_template(); |
1191 | 1196 | if (!templ.IsEmpty()) |
1192 | 1197 | return templ; |
1193 | 1198 |
|
1194 | 1199 | { |
1195 | | - Isolate* isolate = env->isolate(); |
| 1200 | + Isolate* isolate = isolate_data->isolate(); |
1196 | 1201 | Local<FunctionTemplate> m = NewFunctionTemplate(isolate, MessagePort::New); |
1197 | | - m->SetClassName(env->message_port_constructor_string()); |
| 1202 | + m->SetClassName(isolate_data->message_port_constructor_string()); |
1198 | 1203 | m->InstanceTemplate()->SetInternalFieldCount( |
1199 | 1204 | MessagePort::kInternalFieldCount); |
1200 | | - m->Inherit(HandleWrap::GetConstructorTemplate(env)); |
| 1205 | + m->Inherit(HandleWrap::GetConstructorTemplate(isolate_data)); |
1201 | 1206 |
|
1202 | 1207 | SetProtoMethod(isolate, m, "postMessage", MessagePort::PostMessage); |
1203 | 1208 | SetProtoMethod(isolate, m, "start", MessagePort::Start); |
1204 | 1209 |
|
1205 | | - env->set_message_port_constructor_template(m); |
| 1210 | + isolate_data->set_message_port_constructor_template(m); |
1206 | 1211 | } |
1207 | 1212 |
|
1208 | | - return GetMessagePortConstructorTemplate(env); |
| 1213 | + return GetMessagePortConstructorTemplate(isolate_data); |
1209 | 1214 | } |
1210 | 1215 |
|
1211 | 1216 | JSTransferable::JSTransferable(Environment* env, Local<Object> obj) |
@@ -1573,15 +1578,12 @@ static void BroadcastChannel(const FunctionCallbackInfo<Value>& args) { |
1573 | 1578 | } |
1574 | 1579 | } |
1575 | 1580 |
|
1576 | | -static void InitMessaging(Local<Object> target, |
1577 | | - Local<Value> unused, |
1578 | | - Local<Context> context, |
1579 | | - void* priv) { |
1580 | | - Environment* env = Environment::GetCurrent(context); |
1581 | | - Isolate* isolate = env->isolate(); |
| 1581 | +static void CreatePerIsolateProperties(IsolateData* isolate_data, |
| 1582 | + Local<ObjectTemplate> target) { |
| 1583 | + Isolate* isolate = isolate_data->isolate(); |
1582 | 1584 |
|
1583 | 1585 | { |
1584 | | - SetConstructorFunction(context, |
| 1586 | + SetConstructorFunction(isolate, |
1585 | 1587 | target, |
1586 | 1588 | "MessageChannel", |
1587 | 1589 | NewFunctionTemplate(isolate, MessageChannel)); |
@@ -1594,31 +1596,36 @@ static void InitMessaging(Local<Object> target, |
1594 | 1596 | JSTransferable::kInternalFieldCount); |
1595 | 1597 | t->SetClassName(OneByteString(isolate, "JSTransferable")); |
1596 | 1598 | SetConstructorFunction( |
1597 | | - context, target, "JSTransferable", t, SetConstructorFunctionFlag::NONE); |
| 1599 | + isolate, target, "JSTransferable", t, SetConstructorFunctionFlag::NONE); |
1598 | 1600 | } |
1599 | 1601 |
|
1600 | | - SetConstructorFunction(context, |
| 1602 | + SetConstructorFunction(isolate, |
1601 | 1603 | target, |
1602 | | - env->message_port_constructor_string(), |
1603 | | - GetMessagePortConstructorTemplate(env), |
1604 | | - SetConstructorFunctionFlag::NONE); |
| 1604 | + isolate_data->message_port_constructor_string(), |
| 1605 | + GetMessagePortConstructorTemplate(isolate_data)); |
1605 | 1606 |
|
1606 | 1607 | // These are not methods on the MessagePort prototype, because |
1607 | 1608 | // the browser equivalents do not provide them. |
1608 | | - SetMethod(context, target, "stopMessagePort", MessagePort::Stop); |
1609 | | - SetMethod(context, target, "checkMessagePort", MessagePort::CheckType); |
1610 | | - SetMethod(context, target, "drainMessagePort", MessagePort::Drain); |
| 1609 | + SetMethod(isolate, target, "stopMessagePort", MessagePort::Stop); |
| 1610 | + SetMethod(isolate, target, "checkMessagePort", MessagePort::CheckType); |
| 1611 | + SetMethod(isolate, target, "drainMessagePort", MessagePort::Drain); |
1611 | 1612 | SetMethod( |
1612 | | - context, target, "receiveMessageOnPort", MessagePort::ReceiveMessage); |
| 1613 | + isolate, target, "receiveMessageOnPort", MessagePort::ReceiveMessage); |
1613 | 1614 | SetMethod( |
1614 | | - context, target, "moveMessagePortToContext", MessagePort::MoveToContext); |
1615 | | - SetMethod(context, |
| 1615 | + isolate, target, "moveMessagePortToContext", MessagePort::MoveToContext); |
| 1616 | + SetMethod(isolate, |
1616 | 1617 | target, |
1617 | 1618 | "setDeserializerCreateObjectFunction", |
1618 | 1619 | SetDeserializerCreateObjectFunction); |
1619 | | - SetMethod(context, target, "broadcastChannel", BroadcastChannel); |
1620 | | - SetMethod(context, target, "structuredClone", StructuredClone); |
| 1620 | + SetMethod(isolate, target, "broadcastChannel", BroadcastChannel); |
| 1621 | + SetMethod(isolate, target, "structuredClone", StructuredClone); |
| 1622 | +} |
1621 | 1623 |
|
| 1624 | +static void CreatePerContextProperties(Local<Object> target, |
| 1625 | + Local<Value> unused, |
| 1626 | + Local<Context> context, |
| 1627 | + void* priv) { |
| 1628 | + Environment* env = Environment::GetCurrent(context); |
1622 | 1629 | { |
1623 | 1630 | Local<Function> domexception = GetDOMException(context).ToLocalChecked(); |
1624 | 1631 | target |
@@ -1650,6 +1657,9 @@ static void RegisterExternalReferences(ExternalReferenceRegistry* registry) { |
1650 | 1657 | } // namespace worker |
1651 | 1658 | } // namespace node |
1652 | 1659 |
|
1653 | | -NODE_BINDING_CONTEXT_AWARE_INTERNAL(messaging, node::worker::InitMessaging) |
| 1660 | +NODE_BINDING_CONTEXT_AWARE_INTERNAL(messaging, |
| 1661 | + node::worker::CreatePerContextProperties) |
| 1662 | +NODE_BINDING_PER_ISOLATE_INIT(messaging, |
| 1663 | + node::worker::CreatePerIsolateProperties) |
1654 | 1664 | NODE_BINDING_EXTERNAL_REFERENCE(messaging, |
1655 | 1665 | node::worker::RegisterExternalReferences) |