Currently, custom error objects implemented in JavaScript are not cloneable via postMessage / structuredClone with perfect fidelity.
e.g.
const d = new DOMException('foo', 'AbortErr');
const mc = new MessageChannel();
mc.port1.onmessage = ({data}) => {
console.log(data is DOMException); // false
console.log(data.name); // AbortErr
console.log(data.message); // 'foo'
console.log(data.code); // undefined
};
mc.port1.postMessage(d);
Likewise, AbortError is also not correctly cloneable.
The current way that DOMException is implemented (in JavaScript during the per_context bootstrap), it is not possible for us to use the existing internal/worker/js_transferable mechanisms to make it cloneable as the DOMException is loaded too early.
However, if we reimplement DOMException as a native host object (within a C++ binding extending BaseObject) then we can easily make it cloneable (likewise with AbortError). Before going through that effort, however, I wanted to see what folks thought.
/cc @addaleax @joyeecheung
Currently, custom error objects implemented in JavaScript are not cloneable via postMessage / structuredClone with perfect fidelity.
e.g.
Likewise,
AbortErroris also not correctly cloneable.The current way that
DOMExceptionis implemented (in JavaScript during the per_context bootstrap), it is not possible for us to use the existinginternal/worker/js_transferablemechanisms to make it cloneable as theDOMExceptionis loaded too early.However, if we reimplement
DOMExceptionas a native host object (within a C++ binding extendingBaseObject) then we can easily make it cloneable (likewise withAbortError). Before going through that effort, however, I wanted to see what folks thought./cc @addaleax @joyeecheung