Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit b8ff886

Browse files
committed
test
1 parent 3de8d03 commit b8ff886

File tree

1 file changed

+52
-49
lines changed

1 file changed

+52
-49
lines changed

lib/common/error-rewrite.ts

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
4848
let zoneAwareFrame2: string;
4949
let zoneAwareFrame1WithoutNew: string;
5050
let zoneAwareFrame2WithoutNew: string;
51+
let zoneAwareFrame3WithoutNew: string;
5152

5253
global['Error'] = ZoneAwareError;
5354
const stackRewrite = 'stackRewrite';
@@ -79,7 +80,8 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
7980
let i = 0;
8081
// Find the first frame
8182
while (!(frames[i] === zoneAwareFrame1 || frames[i] === zoneAwareFrame2 ||
82-
frames[i] === zoneAwareFrame1WithoutNew || frames[i] === zoneAwareFrame2WithoutNew) &&
83+
frames[i] === zoneAwareFrame1WithoutNew || frames[i] === zoneAwareFrame2WithoutNew ||
84+
frames[i] === zoneAwareFrame3WithoutNew) &&
8385
i < frames.length) {
8486
i++;
8587
}
@@ -263,59 +265,59 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
263265

264266
let detectZone: Zone = Zone.current.fork({
265267
name: 'detect',
266-
onHandleError: function(parentZD: ZoneDelegate, current: Zone, target: Zone, error: any):
267-
boolean {
268-
if (error.originalStack && Error === ZoneAwareError) {
269-
let frames = error.originalStack.split(/\n/);
270-
let runFrame = false, runGuardedFrame = false, runTaskFrame = false;
271-
while (frames.length) {
272-
let frame = frames.shift();
273-
// On safari it is possible to have stack frame with no line number.
274-
// This check makes sure that we don't filter frames on name only (must have
275-
// line number)
276-
if (/:\d+:\d+/.test(frame)) {
277-
// Get rid of the path so that we don't accidentally find function name in path.
278-
// In chrome the separator is `(` and `@` in FF and safari
279-
// Chrome: at Zone.run (zone.js:100)
280-
// Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
281-
// FireFox: Zone.prototype.run@http://localhost:9876/base/build/lib/zone.js:101:24
282-
// Safari: run@http://localhost:9876/base/build/lib/zone.js:101:24
283-
let fnName: string = frame.split('(')[0].split('@')[0];
284-
let frameType = FrameType.transition;
285-
if (fnName.indexOf('ZoneAwareError') !== -1) {
286-
if (fnName.indexOf('new ZoneAwareError') !== -1) {
287-
zoneAwareFrame1 = frame;
288-
zoneAwareFrame2 = frame.replace('Error.', '');
289-
} else {
290-
zoneAwareFrame1WithoutNew = frame;
291-
zoneAwareFrame2WithoutNew = frame.replace('Error.', '');
292-
}
293-
blackListedStackFrames[zoneAwareFrame2] = FrameType.blackList;
294-
}
295-
if ((ZoneAwareError as any)[stackRewrite] && zoneAwareFrame1 &&
296-
zoneAwareFrame1WithoutNew) {
297-
break;
298-
}
299-
if (fnName.indexOf('runGuarded') !== -1) {
300-
runGuardedFrame = true;
301-
} else if (fnName.indexOf('runTask') !== -1) {
302-
runTaskFrame = true;
303-
} else if (fnName.indexOf('run') !== -1) {
304-
runFrame = true;
305-
} else {
306-
frameType = FrameType.blackList;
307-
}
308-
blackListedStackFrames[frame] = frameType;
309-
// Once we find all of the frames we can stop looking.
310-
if (runFrame && runGuardedFrame && runTaskFrame) {
311-
(ZoneAwareError as any)[stackRewrite] = true;
312-
break;
268+
onHandleError: function(
269+
parentZD: ZoneDelegate, current: Zone, target: Zone, error: any): boolean {
270+
if (error.originalStack && Error === ZoneAwareError) {
271+
let frames = error.originalStack.split(/\n/);
272+
let runFrame = false, runGuardedFrame = false, runTaskFrame = false;
273+
while (frames.length) {
274+
let frame = frames.shift();
275+
// On safari it is possible to have stack frame with no line number.
276+
// This check makes sure that we don't filter frames on name only (must have
277+
// line number)
278+
if (/:\d+:\d+/.test(frame)) {
279+
// Get rid of the path so that we don't accidentally find function name in path.
280+
// In chrome the separator is `(` and `@` in FF and safari
281+
// Chrome: at Zone.run (zone.js:100)
282+
// Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
283+
// FireFox: Zone.prototype.run@http://localhost:9876/base/build/lib/zone.js:101:24
284+
// Safari: run@http://localhost:9876/base/build/lib/zone.js:101:24
285+
let fnName: string = frame.split('(')[0].split('@')[0];
286+
let frameType = FrameType.transition;
287+
if (fnName.indexOf('ZoneAwareError') !== -1) {
288+
if (fnName.indexOf('new ZoneAwareError') !== -1) {
289+
zoneAwareFrame1 = frame;
290+
zoneAwareFrame2 = frame.replace('new ZoneAwareError', 'new Error.ZoneAwareError');
291+
} else {
292+
zoneAwareFrame1WithoutNew = frame;
293+
zoneAwareFrame2WithoutNew = frame.replace('Error.', '');
294+
if (frame.indexOf('Error.ZoneAwareError') === -1) {
295+
zoneAwareFrame3WithoutNew =
296+
frame.replace('ZoneAwareError', 'Error.ZoneAwareError');
313297
}
314298
}
299+
blackListedStackFrames[zoneAwareFrame2] = FrameType.blackList;
300+
}
301+
if (fnName.indexOf('runGuarded') !== -1) {
302+
runGuardedFrame = true;
303+
} else if (fnName.indexOf('runTask') !== -1) {
304+
runTaskFrame = true;
305+
} else if (fnName.indexOf('run') !== -1) {
306+
runFrame = true;
307+
} else {
308+
frameType = FrameType.blackList;
309+
}
310+
blackListedStackFrames[frame] = frameType;
311+
// Once we find all of the frames we can stop looking.
312+
if (runFrame && runGuardedFrame && runTaskFrame) {
313+
(ZoneAwareError as any)[stackRewrite] = true;
314+
break;
315315
}
316316
}
317-
return false;
318317
}
318+
}
319+
return false;
320+
}
319321
}) as Zone;
320322
// carefully constructor a stack frame which contains all of the frames of interest which
321323
// need to be detected and blacklisted.
@@ -395,5 +397,6 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
395397
console.log('zoneAwareFrame2', zoneAwareFrame2);
396398
console.log('zoneAwareFrame1WithoutNew', zoneAwareFrame1WithoutNew);
397399
console.log('zoneAwareFrame2WithoutNew', zoneAwareFrame2WithoutNew);
400+
console.log('zoneAwareFrame3WithoutNew', zoneAwareFrame3WithoutNew);
398401
Error.stackTraceLimit = originalStackTraceLimit;
399402
});

0 commit comments

Comments
 (0)