This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +15
-7
lines changed
2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -1312,13 +1312,14 @@ const Zone: ZoneType = (function(global: any) {
1312
1312
function ZoneAwareError ( ) {
1313
1313
// Create an Error.
1314
1314
let error : Error = NativeError . apply ( this , arguments ) ;
1315
+ this . message = error . message ;
1315
1316
1316
1317
// Save original stack trace
1317
- error . originalStack = error . stack ;
1318
+ this . originalStack = error . stack ;
1318
1319
1319
1320
// Process the stack trace and rewrite the frames.
1320
- if ( ZoneAwareError [ stackRewrite ] && error . originalStack ) {
1321
- let frames : string [ ] = error . originalStack . split ( '\n' ) ;
1321
+ if ( ZoneAwareError [ stackRewrite ] && this . originalStack ) {
1322
+ let frames : string [ ] = this . originalStack . split ( '\n' ) ;
1322
1323
let zoneFrame = _currentZoneFrame ;
1323
1324
let i = 0 ;
1324
1325
// Find the first frame
@@ -1346,13 +1347,12 @@ const Zone: ZoneType = (function(global: any) {
1346
1347
}
1347
1348
}
1348
1349
}
1349
- error . stack = error . zoneAwareStack = frames . join ( '\n' ) ;
1350
+ this . stack = this . zoneAwareStack = frames . join ( '\n' ) ;
1350
1351
}
1351
- return error ;
1352
- }
1352
+ } ;
1353
1353
1354
1354
// Copy the prototype so that instanceof operator works as expected
1355
- ZoneAwareError . prototype = NativeError . prototype ;
1355
+ ZoneAwareError . prototype = Object . create ( NativeError . prototype ) ;
1356
1356
ZoneAwareError [ Zone . __symbol__ ( 'blacklistedStackFrames' ) ] = blackListedStackFrames ;
1357
1357
ZoneAwareError [ stackRewrite ] = false ;
1358
1358
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ describe('ZoneAwareError', () => {
11
11
// and there is no point in running them.
12
12
if ( ! Error [ 'stackRewrite' ] ) return ;
13
13
14
+ it ( 'should keep error prototype chain correctly' , ( ) => {
15
+ class MyError extends Error { }
16
+ const myError = new MyError ( ) ;
17
+ expect ( myError instanceof Error ) . toBe ( true ) ;
18
+ expect ( myError instanceof MyError ) . toBe ( true ) ;
19
+ expect ( myError . stack ) . not . toBe ( undefined ) ;
20
+ } ) ;
21
+
14
22
it ( 'should show zone names in stack frames and remove extra frames' , ( ) => {
15
23
const rootZone = getRootZone ( ) ;
16
24
const innerZone = rootZone . fork ( { name : 'InnerZone' } ) ;
You can’t perform that action at this time.
0 commit comments