src,lib: make DOMException available in all Contexts · nodejs/node@1e669b2 (original) (raw)
`@@ -177,19 +177,30 @@ uint32_t Message::AddWASMModule(WasmCompiledModule::TransferrableModule&& mod) {
`
177
177
``
178
178
`namespace {
`
179
179
``
180
``
`-
void ThrowDataCloneException(Environment* env, Local message) {
`
``
180
`+
void ThrowDataCloneException(Local context, Local message) {
`
``
181
`+
Isolate* isolate = context->GetIsolate();
`
181
182
` Local argv[] = {
`
182
183
` message,
`
183
``
`-
FIXED_ONE_BYTE_STRING(env->isolate(), "DataCloneError")
`
``
184
`+
FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")
`
184
185
` };
`
185
186
` Local exception;
`
186
``
`-
Local domexception_ctor = env->domexception_function();
`
187
``
`-
CHECK(!domexception_ctor.IsEmpty());
`
188
``
`-
if (!domexception_ctor->NewInstance(env->context(), arraysize(argv), argv)
`
``
187
+
``
188
`+
Local per_context_bindings;
`
``
189
`+
Local domexception_ctor_val;
`
``
190
`+
if (!GetPerContextExports(context).ToLocal(&per_context_bindings) ||
`
``
191
`+
!per_context_bindings->Get(context,
`
``
192
`+
FIXED_ONE_BYTE_STRING(isolate, "DOMException"))
`
``
193
`+
.ToLocal(&domexception_ctor_val)) {
`
``
194
`+
return;
`
``
195
`+
}
`
``
196
+
``
197
`+
CHECK(domexception_ctor_val->IsFunction());
`
``
198
`+
Local domexception_ctor = domexception_ctor_val.As();
`
``
199
`+
if (!domexception_ctor->NewInstance(context, arraysize(argv), argv)
`
189
200
` .ToLocal(&exception)) {
`
190
201
`return;
`
191
202
` }
`
192
``
`-
env->isolate()->ThrowException(exception);
`
``
203
`+
isolate->ThrowException(exception);
`
193
204
`}
`
194
205
``
195
206
`// This tells V8 how to serialize objects that it does not understand
`
`@@ -201,7 +212,7 @@ class SerializerDelegate : public ValueSerializer::Delegate {
`
201
212
` : env_(env), context_(context), msg_(m) {}
`
202
213
``
203
214
`void ThrowDataCloneError(Local message) override {
`
204
``
`-
ThrowDataCloneException(env_, message);
`
``
215
`+
ThrowDataCloneException(context_, message);
`
205
216
` }
`
206
217
``
207
218
` Maybe WriteHostObject(Isolate* isolate, Local object) override {
`
`@@ -309,7 +320,7 @@ Maybe Message::Serialize(Environment* env,
`
309
320
`if (std::find(array_buffers.begin(), array_buffers.end(), ab) !=
`
310
321
` array_buffers.end()) {
`
311
322
`ThrowDataCloneException(
`
312
``
`-
env,
`
``
323
`+
context,
`
313
324
`FIXED_ONE_BYTE_STRING(
`
314
325
` env->isolate(),
`
315
326
`"Transfer list contains duplicate ArrayBuffer"));
`
`@@ -326,15 +337,15 @@ Maybe Message::Serialize(Environment* env,
`
326
337
`// Check if the source MessagePort is being transferred.
`
327
338
`if (!source_port.IsEmpty() && entry == source_port) {
`
328
339
`ThrowDataCloneException(
`
329
``
`-
env,
`
``
340
`+
context,
`
330
341
`FIXED_ONE_BYTE_STRING(env->isolate(),
`
331
342
`"Transfer list contains source port"));
`
332
343
`return Nothing();
`
333
344
` }
`
334
345
` MessagePort* port = Unwrap(entry.As());
`
335
346
`if (port == nullptr || port->IsDetached()) {
`
336
347
`ThrowDataCloneException(
`
337
``
`-
env,
`
``
348
`+
context,
`
338
349
`FIXED_ONE_BYTE_STRING(
`
339
350
` env->isolate(),
`
340
351
`"MessagePort in transfer list is already detached"));
`
`@@ -343,7 +354,7 @@ Maybe Message::Serialize(Environment* env,
`
343
354
`if (std::find(delegate.ports_.begin(), delegate.ports_.end(), port) !=
`
344
355
` delegate.ports_.end()) {
`
345
356
`ThrowDataCloneException(
`
346
``
`-
env,
`
``
357
`+
context,
`
347
358
`FIXED_ONE_BYTE_STRING(
`
348
359
` env->isolate(),
`
349
360
`"Transfer list contains duplicate MessagePort"));
`
`@@ -811,13 +822,6 @@ static void MessageChannel(const FunctionCallbackInfo& args) {
`
811
822
` .FromJust();
`
812
823
`}
`
813
824
``
814
``
`-
static void RegisterDOMException(const FunctionCallbackInfo& args) {
`
815
``
`-
Environment* env = Environment::GetCurrent(args);
`
816
``
`-
CHECK_EQ(args.Length(), 1);
`
817
``
`-
CHECK(args[0]->IsFunction());
`
818
``
`-
env->set_domexception_function(args[0].As());
`
819
``
`-
}
`
820
``
-
821
825
`static void InitMessaging(Local target,
`
822
826
` Local unused,
`
823
827
` Local context,
`
`@@ -839,8 +843,6 @@ static void InitMessaging(Local target,
`
839
843
`GetMessagePortConstructor(env, context).ToLocalChecked())
`
840
844
` .FromJust();
`
841
845
``
842
``
`-
env->SetMethod(target, "registerDOMException", RegisterDOMException);
`
843
``
-
844
846
`// These are not methods on the MessagePort prototype, because
`
845
847
`// the browser equivalents do not provide them.
`
846
848
` env->SetMethod(target, "stopMessagePort", MessagePort::Stop);
`