es-shims / es-shims/Error.isError
`isError` returns `false` for `DOMException` instances
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
`isError` returns `false` for `DOMException` instances.
From what I can see, there are three reasons for this:
https://github.com/es-shims/Error.isError/blob/059b44a2f0a334a1b7abc3e297a4af91643d1e1f/implementation.js#L22-L24
In NodeJS, `require('util').types.isNativeError(new DOMException())` gives `false`.
https://github.com/es-shims/Error.isError/blob/059b44a2f0a334a1b7abc3e297a4af91643d1e1f/implementation.js#L26-L28
In current server-side implementations (pending https://github.com/whatwg/webidl/pull/1421), `structuredClone(new DOMException())` returns `{}`, i.e. a plain JS object.
https://github.com/es-shims/Error.isError/blob/059b44a2f0a334a1b7abc3e297a4af91643d1e1f/implementation.js#L34-L37
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 https://github.com/whatwg/webidl/pull/1421 lands in implementations, so you could either:
* Be lax with `Symbol.toStringTag` tag specifically in the case of `DOMException`*, which would fail on `DOMException`s with spoofed `toStringTag` or other objects with `toStringTag` spoofed as "DOMException"
* Bring forward `instanceof` checking specifically in the case of `DOMException`*, which would fail on cross-realm `DOMException`s. I guess this can't be tested for in Node as `require('vm').runInNewContext('new DOMException()')` gives `DOMException is not defined`, but such cross-realm `DOMException`s are presumably pretty commonplace in browsers (e.g. any `DOMException` originating from an `iframe`)
\* and maybe `DOMError` and/or `Exception` too?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.