demo · v134 · javascript
Test Suite
Sixteen pathological inputs. For each, we run Error.isError(x), x instanceof Error, Object.prototype.toString.call(x) === "[object Error]", and x.constructor?.name?.endsWith("Error"). Side-by-side scoreboard so you can see which check actually does what people expect.
| input | Error.isError | instanceof Error | toString tag | name endsWith |
|---|
why the other checks fail
- instanceof Error — false for errors from other realms (iframe, Worker, vm context). The constructor's prototype chain is a different
Error.prototypeobject. - toString tag — works for native errors but is forgeable via
Symbol.toStringTag. - name endsWith "Error" — useful heuristic but trips on anything called
MyCustomErrorthat doesn't actually derive fromError, and missesDOMException. - Error.isError — defined by spec to check the internal
[[ErrorData]]slot. True only for real errors regardless of realm, false for fakes regardless of how convincing.
see also
- Error.isError — feature index
- Error.isError basics
- Cross-realm error check
- TC39 proposal