File tree Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -4,14 +4,15 @@ function isObject(what) {
4
4
return typeof what === 'object' && what !== null ;
5
5
}
6
6
7
- // Sorta yanked from https://github.com/joyent/node/blob/aa3b4b4/lib/util.js#L560
7
+ // Yanked from https://git.io/vS8DV re-used under CC0
8
8
// with some tiny modifications
9
- function isError ( what ) {
10
- var toString = { } . toString . call ( what ) ;
11
- return isObject ( what ) &&
12
- toString === '[object Error]' ||
13
- toString === '[object Exception]' || // Firefox NS_ERROR_FAILURE Exceptions
14
- what instanceof Error ;
9
+ function isError ( value ) {
10
+ switch ( { } . toString . call ( value ) ) {
11
+ case '[object Error]' : return true ;
12
+ case '[object Exception]' : return true ;
13
+ case '[object DOMException]' : return true ;
14
+ default : return value instanceof Error ;
15
+ }
15
16
}
16
17
17
18
module . exports = {
Original file line number Diff line number Diff line change @@ -66,11 +66,39 @@ describe('utils', function () {
66
66
} ) ;
67
67
68
68
describe ( 'isError' , function ( ) {
69
+ function testErrorFromDifferentContext ( createError ) {
70
+ var iframe = document . createElement ( 'iframe' ) ;
71
+ document . body . appendChild ( iframe ) ;
72
+ try {
73
+ return createError ( iframe . contentWindow ) ;
74
+ } finally {
75
+ iframe . parentElement . removeChild ( iframe ) ;
76
+ }
77
+ }
78
+
79
+ function fromContext ( win ) {
80
+ return new win . Error ( ) ;
81
+ }
82
+
83
+ function domException ( win ) {
84
+ try {
85
+ win . document . querySelectorAll ( '' ) ;
86
+ } catch ( e ) {
87
+ return e ;
88
+ }
89
+ }
90
+
69
91
it ( 'should work as advertised' , function ( ) {
70
92
assert . isTrue ( isError ( new Error ( ) ) ) ;
71
93
assert . isTrue ( isError ( new ReferenceError ( ) ) ) ;
72
94
assert . isTrue ( isError ( new RavenConfigError ( ) ) ) ;
95
+ assert . isTrue ( isError ( testErrorFromDifferentContext ( fromContext ) ) ) ;
96
+ assert . isTrue ( isError ( testErrorFromDifferentContext ( domException ) ) ) ;
73
97
assert . isFalse ( isError ( { } ) ) ;
98
+ assert . isFalse ( isError ( {
99
+ message : 'A fake error' ,
100
+ stack : 'no stack here'
101
+ } ) ) ;
74
102
assert . isFalse ( isError ( '' ) ) ;
75
103
assert . isFalse ( isError ( true ) ) ;
76
104
} ) ;
You can’t perform that action at this time.
0 commit comments