@@ -1423,7 +1423,9 @@ const Zone: ZoneType = (function(global: any) {
1423
1423
1424
1424
if ( NativeError . hasOwnProperty ( 'captureStackTrace' ) ) {
1425
1425
Object . defineProperty ( ZoneAwareError , 'captureStackTrace' , {
1426
- value : function ( targetObject : Object , constructorOpt ?: Function ) {
1426
+ // add named function here because we need to remove this
1427
+ // stack frame when prepareStackTrace below
1428
+ value : function zoneCaptureStackTrace ( targetObject : Object , constructorOpt ?: Function ) {
1427
1429
NativeError . captureStackTrace ( targetObject , constructorOpt ) ;
1428
1430
}
1429
1431
} ) ;
@@ -1434,7 +1436,23 @@ const Zone: ZoneType = (function(global: any) {
1434
1436
return NativeError . prepareStackTrace ;
1435
1437
} ,
1436
1438
set : function ( value ) {
1437
- return NativeError . prepareStackTrace = value ;
1439
+ if ( ! value || typeof value !== 'function' ) {
1440
+ return NativeError . prepareStackTrace = value ;
1441
+ }
1442
+ return NativeError . prepareStackTrace = function ( error , structuredStackTrace ) {
1443
+ // remove additional stack information from ZoneAwareError.captureStackTrace
1444
+ if ( structuredStackTrace ) {
1445
+ for ( let i = 0 ; i < structuredStackTrace . length ; i ++ ) {
1446
+ const st = structuredStackTrace [ i ] ;
1447
+ // remove the first function which name is value
1448
+ if ( st . getFunctionName ( ) === 'zoneCaptureStackTrace' ) {
1449
+ structuredStackTrace . splice ( i , 1 ) ;
1450
+ break ;
1451
+ }
1452
+ }
1453
+ }
1454
+ return value . apply ( this , [ error , structuredStackTrace ] ) ;
1455
+ } ;
1438
1456
}
1439
1457
} ) ;
1440
1458
0 commit comments