Skip to content

Commit bac2fc2

Browse files
bartlomiejuclaude
andcommitted
fix(web): support structuredClone for DOMException
Uses the cloneable resource registry to enable structured cloning of DOMException objects. Serializes message, name, and stack; code is derived from name on deserialization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1ea5ff0 commit bac2fc2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ext/web/01_dom_exception.js

Lines changed: 21 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,
@@ -137,6 +137,12 @@ class DOMException {
137137
error[_name] = name;
138138
error[_code] = code;
139139
error[webidl.brand] = webidl.brand;
140+
error[core.hostObjectBrand] = () => ({
141+
type: "DOMException",
142+
message,
143+
name,
144+
stack: error.stack,
145+
});
140146

141147
return error;
142148
}
@@ -217,4 +223,18 @@ for (let i = 0; i < entries.length; ++i) {
217223
ObjectDefineProperty(DOMException.prototype, key, desc);
218224
}
219225

226+
core.registerCloneableResource("DOMException", (data) => {
227+
const ex = new DOMException(data.message, data.name);
228+
if (data.stack !== undefined) {
229+
ObjectDefineProperty(ex, "stack", {
230+
__proto__: null,
231+
value: data.stack,
232+
configurable: true,
233+
writable: true,
234+
enumerable: false,
235+
});
236+
}
237+
return ex;
238+
});
239+
220240
export { DOMException, DOMExceptionPrototype };

0 commit comments

Comments
 (0)