Skip to content

Commit 9b1f28f

Browse files
committed
fix(ext/web): make DOMException properly serializable
1 parent c31e307 commit 9b1f28f

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

Cargo.lock

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repository = "https://github.com/denoland/deno"
6363

6464
[workspace.dependencies]
6565
deno_ast = { version = "=0.50.3", features = ["transpiling"] }
66-
deno_core = { version = "0.363.0" }
66+
deno_core = { path = "../deno_core/core" } # version = "0.363.0" }
6767

6868
deno_cache_dir = "=0.25.0"
6969
deno_doc = "=0.186.0"

ext/web/01_dom_exception.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// <reference path="../web/internal.d.ts" />
88
/// <reference path="../../cli/tsc/dts/lib.deno_web.d.ts" />
99

10-
import { primordials } from "ext:core/mod.js";
10+
import { core, primordials } from "ext:core/mod.js";
1111
const {
1212
Error,
1313
ErrorPrototype,
@@ -94,6 +94,10 @@ class DOMException {
9494
[_name];
9595
[_code];
9696

97+
[core.hostObjectBrand]() {
98+
return { type: "DOMException", message: this.message, name: this.name };
99+
}
100+
97101
// https://webidl.spec.whatwg.org/#dom-domexception-domexception
98102
constructor(message = "", name = "Error") {
99103
message = webidl.converters.DOMString(

ext/web/13_message_port.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ function opCreateEntangledMessagePort() {
350350
return op_message_port_create_entangled();
351351
}
352352

353+
const CURSED_DESERIALIZERS = {
354+
DOMException: (obj) => new DOMException(obj.message, obj.name),
355+
};
356+
353357
/**
354358
* @param {messagePort.MessageData} messageData
355359
* @returns {[any, object[]]}
@@ -386,6 +390,7 @@ function deserializeJsMessageData(messageData) {
386390
options = {
387391
hostObjects,
388392
transferredArrayBuffers,
393+
deserializers: CURSED_DESERIALIZERS,
389394
};
390395
}
391396

@@ -501,7 +506,7 @@ function structuredClone(value, options) {
501506
// Fast-path, avoiding round-trip serialization and deserialization
502507
if (options.transfer.length === 0) {
503508
try {
504-
return core.structuredClone(value);
509+
return core.structuredClone(value, CURSED_DESERIALIZERS);
505510
} catch (e) {
506511
if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {
507512
throw new DOMException(e.message, "DataCloneError");

tests/unit/structured_clone_test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ Deno.test("correct DataCloneError message", () => {
5858

5959
// ab2 should not be detached after above failure
6060
structuredClone(ab2, { transfer: [ab2] });
61+
62+
const de = structuredClone(new DOMException("message", "SomeError"));
63+
assert(de instanceof DOMException);
64+
assertEquals(de.message, "message");
65+
assertEquals(de.name, "SomeError");
6166
});

0 commit comments

Comments
 (0)