@@ -14,29 +14,41 @@ var $toString = callBound('Object.prototype.toString');
1414var stackDesc = gOPD ( $Error . prototype , 'stack' ) ;
1515var stackGetter = stackDesc && stackDesc . get && callBind ( stackDesc . get ) ;
1616
17+ var domExceptionClonable = ! ! ( $structuredClone && $structuredClone ( new DOMException ( ) ) instanceof $Error ) ;
18+
1719module . exports = function isError ( arg ) {
1820 if ( ! arg || ( typeof arg !== 'object' && typeof arg !== 'function' ) ) {
1921 return false ; // step 1
2022 }
2123
22- if ( isNativeError ) { // node 10+
23- return isNativeError ( arg ) ;
24- }
25-
2624 if ( $structuredClone ) {
2725 try {
28- return $structuredClone ( arg ) instanceof $Error ;
26+ if ( $structuredClone ( arg ) instanceof $Error ) {
27+ return true ;
28+ } else if ( domExceptionClonable ) {
29+ return false ;
30+ }
2931 } catch ( e ) {
3032 return false ;
3133 }
3234 }
3335
34- if ( ! hasToStringTag || ! ( Symbol . toStringTag in arg ) ) {
35- var str = $toString ( arg ) ;
36- return str === '[object Error]' // errors
37- || str === '[object DOMException]' // browsers
38- || str === '[object DOMError]' // browsers, deprecated
39- || str === '[object Exception]' ; // sentry
36+ if ( isNativeError && isNativeError ( arg ) ) { // node 10+
37+ return true ;
38+ }
39+
40+ var str = $toString ( arg ) ;
41+
42+ if (
43+ str === '[object DOMException]' // browsers
44+ || ( ( ! hasToStringTag || ! ( Symbol . toStringTag in arg ) )
45+ && (
46+ str === '[object DOMError]' // browsers, deprecated
47+ || str === '[object Exception]' // sentry
48+ )
49+ )
50+ ) {
51+ return true ;
4052 }
4153
4254 // Firefox
@@ -56,5 +68,5 @@ module.exports = function isError(arg) {
5668 }
5769
5870 // fallback for envs with toStringTag but without structuredClone
59- return arg instanceof Error ;
71+ return arg instanceof Error || arg instanceof DOMException ;
6072} ;
0 commit comments