demo · v133

Cross-realm errors — where instanceof breaks

The TC39 proposal's motivating bug: an Error object thrown inside an iframe fails err instanceof Error in the parent, because each realm has its own Error intrinsic. Error.isError is a brand check — it works regardless of realm.

valuetypeofinstanceof ErrorError.isError

the cases that bite

Library code (loggers, serialisers, error-boundary frameworks) needs a reliable "is this thing an error?" check. instanceof fails across realms (iframes, Workers, vm.runInContext). It also fails on Proxy-wrapped errors. Userland workarounds compared Object.prototype.toString.call(x) against "[object Error]" — which used to work, but stopped being reliable when Symbol.toStringTag became spoofable. Error.isError is a real brand check that the engine can answer truthfully no matter where the error was born.

// What the engine actually checks
Error.isError(x);
// true iff x is an object with the [[ErrorData]] internal slot
// → matches Error, TypeError, RangeError, DOMException, AggregateError, …
// → from any realm
// → through Proxy wrappers

see also