Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a032fc

Browse filesBrowse files
joyeecheungBridgeAR
authored andcommitted
src: expose DOMException to internalBinding('message') for testing
Instead of using a hack to get it in the test. PR-URL: #28072 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent dfdf742 commit 8a032fc
Copy full SHA for 8a032fc

File tree

Expand file treeCollapse file tree

2 files changed

+25
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-26
lines changed
Open diff view settings
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+23-11Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,30 @@ uint32_t Message::AddWASMModule(WasmModuleObject::TransferrableModule&& mod) {
186186

187187
namespace {
188188

189-
void ThrowDataCloneException(Local<Context> context, Local<String> message) {
189+
MaybeLocal<Function> GetDOMException(Local<Context> context) {
190190
Isolate* isolate = context->GetIsolate();
191-
Local<Value> argv[] = {
192-
message,
193-
FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")
194-
};
195-
Local<Value> exception;
196-
197191
Local<Object> per_context_bindings;
198192
Local<Value> domexception_ctor_val;
199193
if (!GetPerContextExports(context).ToLocal(&per_context_bindings) ||
200194
!per_context_bindings->Get(context,
201195
FIXED_ONE_BYTE_STRING(isolate, "DOMException"))
202196
.ToLocal(&domexception_ctor_val)) {
203-
return;
197+
return MaybeLocal<Function>();
204198
}
205-
206199
CHECK(domexception_ctor_val->IsFunction());
207200
Local<Function> domexception_ctor = domexception_ctor_val.As<Function>();
208-
if (!domexception_ctor->NewInstance(context, arraysize(argv), argv)
209-
.ToLocal(&exception)) {
201+
return domexception_ctor;
202+
}
203+
204+
void ThrowDataCloneException(Local<Context> context, Local<String> message) {
205+
Isolate* isolate = context->GetIsolate();
206+
Local<Value> argv[] = {message,
207+
FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")};
208+
Local<Value> exception;
209+
Local<Function> domexception_ctor;
210+
if (!GetDOMException(context).ToLocal(&domexception_ctor) ||
211+
!domexception_ctor->NewInstance(context, arraysize(argv), argv)
212+
.ToLocal(&exception)) {
210213
return;
211214
}
212215
isolate->ThrowException(exception);
@@ -900,6 +903,15 @@ static void InitMessaging(Local<Object> target,
900903
env->SetMethod(target, "receiveMessageOnPort", MessagePort::ReceiveMessage);
901904
env->SetMethod(target, "moveMessagePortToContext",
902905
MessagePort::MoveToContext);
906+
907+
{
908+
Local<Function> domexception = GetDOMException(context).ToLocalChecked();
909+
target
910+
->Set(context,
911+
FIXED_ONE_BYTE_STRING(env->isolate(), "DOMException"),
912+
domexception)
913+
.Check();
914+
}
903915
}
904916

905917
} // anonymous namespace
Collapse file

‎test/wpt/test-url.js‎

Copy file name to clipboardExpand all lines: test/wpt/test-url.js
+2-15Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,16 @@
33
// Flags: --expose-internals
44

55
require('../common');
6-
const assert = require('assert');
76
const { WPTRunner } = require('../common/wpt');
8-
7+
const { internalBinding } = require('internal/test/binding');
8+
const { DOMException } = internalBinding('messaging');
99
const runner = new WPTRunner('url');
1010

1111
// Copy global descriptors from the global object
1212
runner.copyGlobalsFromObject(global, ['URL', 'URLSearchParams']);
1313
// Needed by urlsearchparams-constructor.any.js
14-
let DOMException;
1514
runner.defineGlobal('DOMException', {
1615
get() {
17-
// A 'hack' to get the DOMException constructor since we don't have it
18-
// on the global object.
19-
if (DOMException === undefined) {
20-
const port = new (require('worker_threads').MessagePort)();
21-
const ab = new ArrayBuffer(1);
22-
try {
23-
port.postMessage(ab, [ab, ab]);
24-
} catch (err) {
25-
DOMException = err.constructor;
26-
}
27-
assert.strictEqual(DOMException.name, 'DOMException');
28-
}
2916
return DOMException;
3017
}
3118
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.