Skip to content

Make DOMException globally available #39098

Closed
@jimmywarting

Description

@jimmywarting

Having to do this is bad code smell

if (!globalThis.DOMException) {
  try {
    const { MessageChannel } = require('worker_threads'),
    port = new MessageChannel().port1,
    ab = new ArrayBuffer()
    port.postMessage(ab, [ab, ab])
  } catch (err) {
    err.constructor.name === 'DOMException' && (
      globalThis.DOMException = err.constructor
    )
  }
}

Since we are aligning more with Web standard APIs now days with the arise of URL, URLSearchParams, Event & EventTarget, MessageChannel, Workers, BroadcastChannel, Blob, File, AbortController, atob, bota, TextEncoder, TextDecoder etc
It would only start to make sense to expose DOMException globally so you are able to check if a error is a instances of DOMException.
Pollyfills need this Error class also.
And more feature web standard apis is probably going to need it.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions