Description
isError
returns false
for DOMException
instances.
From what I can see, there are three reasons for this:
Error.isError/implementation.js
Lines 22 to 24 in 059b44a
In NodeJS, require('util').types.isNativeError(new DOMException())
gives false
.
Error.isError/implementation.js
Lines 26 to 28 in 059b44a
In current server-side implementations (pending whatwg/webidl#1421), structuredClone(new DOMException())
returns {}
, i.e. a plain JS object.
Error.isError/implementation.js
Lines 34 to 37 in 059b44a
Even if this line was hit (which it won't be because the previous two lines would both return early with false
), Symbol.toStringTag in new DOMException()
returns true
, so the condition fails.
It doesn't seem there's any 100% foolproof way of detecting DOMException
s until whatwg/webidl#1421 lands in implementations, so you could either:
- Be lax with
Symbol.toStringTag
tag specifically in the case ofDOMException
*, which would fail onDOMException
s with spoofedtoStringTag
or other objects withtoStringTag
spoofed as "DOMException" - Bring forward
instanceof
checking specifically in the case ofDOMException
*, which would fail on cross-realmDOMException
s. I guess this can't be tested for in Node asrequire('vm').runInNewContext('new DOMException()')
givesDOMException is not defined
, but such cross-realmDOMException
s are presumably pretty commonplace in browsers (e.g. anyDOMException
originating from aniframe
)
* and maybe DOMError
and/or Exception
too?