Skip to content

Making DOMException and AbortError cloneable #41038

@jasnell

Description

@jasnell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions