summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/node_messaging.cc34
-rw-r--r--test/wpt/test-url.js17
2 files changed, 25 insertions, 26 deletions
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index fa583a2570..0e782ef726 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -186,27 +186,30 @@ uint32_t Message::AddWASMModule(WasmModuleObject::TransferrableModule&& mod) {
namespace {
-void ThrowDataCloneException(Local<Context> context, Local<String> message) {
+MaybeLocal<Function> GetDOMException(Local<Context> context) {
Isolate* isolate = context->GetIsolate();
- Local<Value> argv[] = {
- message,
- FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")
- };
- Local<Value> exception;
-
Local<Object> per_context_bindings;
Local<Value> domexception_ctor_val;
if (!GetPerContextExports(context).ToLocal(&per_context_bindings) ||
!per_context_bindings->Get(context,
FIXED_ONE_BYTE_STRING(isolate, "DOMException"))
.ToLocal(&domexception_ctor_val)) {
- return;
+ return MaybeLocal<Function>();
}
-
CHECK(domexception_ctor_val->IsFunction());
Local<Function> domexception_ctor = domexception_ctor_val.As<Function>();
- if (!domexception_ctor->NewInstance(context, arraysize(argv), argv)
- .ToLocal(&exception)) {
+ return domexception_ctor;
+}
+
+void ThrowDataCloneException(Local<Context> context, Local<String> message) {
+ Isolate* isolate = context->GetIsolate();
+ Local<Value> argv[] = {message,
+ FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")};
+ Local<Value> exception;
+ Local<Function> domexception_ctor;
+ if (!GetDOMException(context).ToLocal(&domexception_ctor) ||
+ !domexception_ctor->NewInstance(context, arraysize(argv), argv)
+ .ToLocal(&exception)) {
return;
}
isolate->ThrowException(exception);
@@ -900,6 +903,15 @@ static void InitMessaging(Local<Object> target,
env->SetMethod(target, "receiveMessageOnPort", MessagePort::ReceiveMessage);
env->SetMethod(target, "moveMessagePortToContext",
MessagePort::MoveToContext);
+
+ {
+ Local<Function> domexception = GetDOMException(context).ToLocalChecked();
+ target
+ ->Set(context,
+ FIXED_ONE_BYTE_STRING(env->isolate(), "DOMException"),
+ domexception)
+ .Check();
+ }
}
} // anonymous namespace
diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js
index 4b909988dd..5d5240ce18 100644
--- a/test/wpt/test-url.js
+++ b/test/wpt/test-url.js
@@ -3,29 +3,16 @@
// Flags: --expose-internals
require('../common');
-const assert = require('assert');
const { WPTRunner } = require('../common/wpt');
-
+const { internalBinding } = require('internal/test/binding');
+const { DOMException } = internalBinding('messaging');
const runner = new WPTRunner('url');
// Copy global descriptors from the global object
runner.copyGlobalsFromObject(global, ['URL', 'URLSearchParams']);
// Needed by urlsearchparams-constructor.any.js
-let DOMException;
runner.defineGlobal('DOMException', {
get() {
- // A 'hack' to get the DOMException constructor since we don't have it
- // on the global object.
- if (DOMException === undefined) {
- const port = new (require('worker_threads').MessagePort)();
- const ab = new ArrayBuffer(1);
- try {
- port.postMessage(ab, [ab, ab]);
- } catch (err) {
- DOMException = err.constructor;
- }
- assert.strictEqual(DOMException.name, 'DOMException');
- }
return DOMException;
}
});