Skip to content

Making DOMException and AbortError cloneable #41038

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions