refactor(zone.js): rename BlacklistedStackFrames to InternalZoneJsStackFrames (#38978)
BlacklistedStackFrames to InternalZoneJsStackFrames along with other related symbols renamed with the same changes (with appropriate casing style). PR Close #38978
This commit is contained in:

committed by
Alex Rickabaugh

parent
4a9f4520ce
commit
cb7164a236
@ -34,15 +34,15 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
|
||||
const enum FrameType {
|
||||
/// Skip this frame when printing out stack
|
||||
blackList,
|
||||
zoneJsInternal,
|
||||
/// This frame marks zone transition
|
||||
transition
|
||||
}
|
||||
|
||||
const blacklistedStackFramesSymbol = api.symbol('blacklistedStackFrames');
|
||||
const zoneJsInternalStackFramesSymbol = api.symbol('zoneJsInternalStackFrames');
|
||||
const NativeError = global[api.symbol('Error')] = global['Error'];
|
||||
// Store the frames which should be removed from the stack frames
|
||||
const blackListedStackFrames: {[frame: string]: FrameType} = {};
|
||||
const zoneJsInternalStackFrames: {[frame: string]: FrameType} = {};
|
||||
// We must find the frame where Error was created, otherwise we assume we don't understand stack
|
||||
let zoneAwareFrame1: string;
|
||||
let zoneAwareFrame2: string;
|
||||
@ -53,9 +53,10 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
global['Error'] = ZoneAwareError;
|
||||
const stackRewrite = 'stackRewrite';
|
||||
|
||||
type BlackListedStackFramesPolicy = 'default'|'disable'|'lazy';
|
||||
const blackListedStackFramesPolicy: BlackListedStackFramesPolicy =
|
||||
global['__Zone_Error_BlacklistedStackFrames_policy'] || 'default';
|
||||
type ZoneJsInternalStackFramesPolicy = 'default'|'disable'|'lazy';
|
||||
const zoneJsInternalStackFramesPolicy: ZoneJsInternalStackFramesPolicy =
|
||||
global['__Zone_Error_BlacklistedStackFrames_policy'] ||
|
||||
global['__Zone_Error_ZoneJsInternalStackFrames_policy'] || 'default';
|
||||
|
||||
interface ZoneFrameName {
|
||||
zoneName: string;
|
||||
@ -88,8 +89,8 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
for (; i < frames.length && zoneFrame; i++) {
|
||||
let frame = frames[i];
|
||||
if (frame.trim()) {
|
||||
switch (blackListedStackFrames[frame]) {
|
||||
case FrameType.blackList:
|
||||
switch (zoneJsInternalStackFrames[frame]) {
|
||||
case FrameType.zoneJsInternal:
|
||||
frames.splice(i, 1);
|
||||
i--;
|
||||
break;
|
||||
@ -124,10 +125,10 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
// Process the stack trace and rewrite the frames.
|
||||
if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
|
||||
let zoneFrame = api.currentZoneFrame();
|
||||
if (blackListedStackFramesPolicy === 'lazy') {
|
||||
if (zoneJsInternalStackFramesPolicy === 'lazy') {
|
||||
// don't handle stack trace now
|
||||
(error as any)[api.symbol('zoneFrameNames')] = buildZoneFrameNames(zoneFrame);
|
||||
} else if (blackListedStackFramesPolicy === 'default') {
|
||||
} else if (zoneJsInternalStackFramesPolicy === 'default') {
|
||||
try {
|
||||
error.stack = error.zoneAwareStack = buildZoneAwareStackFrames(originalStack, zoneFrame);
|
||||
} catch (e) {
|
||||
@ -156,14 +157,13 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
|
||||
// Copy the prototype so that instanceof operator works as expected
|
||||
ZoneAwareError.prototype = NativeError.prototype;
|
||||
(ZoneAwareError as any)[blacklistedStackFramesSymbol] = blackListedStackFrames;
|
||||
(ZoneAwareError as any)[zoneJsInternalStackFramesSymbol] = zoneJsInternalStackFrames;
|
||||
(ZoneAwareError as any)[stackRewrite] = false;
|
||||
|
||||
const zoneAwareStackSymbol = api.symbol('zoneAwareStack');
|
||||
|
||||
// try to define zoneAwareStack property when blackListed
|
||||
// policy is delay
|
||||
if (blackListedStackFramesPolicy === 'lazy') {
|
||||
// try to define zoneAwareStack property when zoneJsInternal frames policy is delay
|
||||
if (zoneJsInternalStackFramesPolicy === 'lazy') {
|
||||
Object.defineProperty(ZoneAwareError.prototype, 'zoneAwareStack', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
@ -253,12 +253,11 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
}
|
||||
});
|
||||
|
||||
if (blackListedStackFramesPolicy === 'disable') {
|
||||
// don't need to run detectZone to populate
|
||||
// blacklisted stack frames
|
||||
if (zoneJsInternalStackFramesPolicy === 'disable') {
|
||||
// don't need to run detectZone to populate zoneJs internal stack frames
|
||||
return;
|
||||
}
|
||||
// Now we need to populate the `blacklistedStackFrames` as well as find the
|
||||
// Now we need to populate the `zoneJsInternalStackFrames` as well as find the
|
||||
// run/runGuarded/runTask frames. This is done by creating a detect zone and then threading
|
||||
// the execution through all of the above methods so that we can look at the stack trace and
|
||||
// find the frames of interest.
|
||||
@ -296,7 +295,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
frame.replace('ZoneAwareError', 'Error.ZoneAwareError');
|
||||
}
|
||||
}
|
||||
blackListedStackFrames[zoneAwareFrame2] = FrameType.blackList;
|
||||
zoneJsInternalStackFrames[zoneAwareFrame2] = FrameType.zoneJsInternal;
|
||||
}
|
||||
if (fnName.indexOf('runGuarded') !== -1) {
|
||||
runGuardedFrame = true;
|
||||
@ -305,9 +304,9 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
} else if (fnName.indexOf('run') !== -1) {
|
||||
runFrame = true;
|
||||
} else {
|
||||
frameType = FrameType.blackList;
|
||||
frameType = FrameType.zoneJsInternal;
|
||||
}
|
||||
blackListedStackFrames[frame] = frameType;
|
||||
zoneJsInternalStackFrames[frame] = frameType;
|
||||
// Once we find all of the frames we can stop looking.
|
||||
if (runFrame && runGuardedFrame && runTaskFrame) {
|
||||
(ZoneAwareError as any)[stackRewrite] = true;
|
||||
@ -320,7 +319,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
}
|
||||
}) as Zone;
|
||||
// carefully constructor a stack frame which contains all of the frames of interest which
|
||||
// need to be detected and blacklisted.
|
||||
// need to be detected and marked as an internal zoneJs frame.
|
||||
|
||||
const childDetectZone = detectZone.fork({
|
||||
name: 'child',
|
||||
@ -351,13 +350,13 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
childDetectZone.runGuarded(() => {
|
||||
const fakeTransitionTo = () => {};
|
||||
childDetectZone.scheduleEventTask(
|
||||
blacklistedStackFramesSymbol,
|
||||
zoneJsInternalStackFramesSymbol,
|
||||
() => {
|
||||
childDetectZone.scheduleMacroTask(
|
||||
blacklistedStackFramesSymbol,
|
||||
zoneJsInternalStackFramesSymbol,
|
||||
() => {
|
||||
childDetectZone.scheduleMicroTask(
|
||||
blacklistedStackFramesSymbol,
|
||||
zoneJsInternalStackFramesSymbol,
|
||||
() => {
|
||||
throw new Error();
|
||||
},
|
||||
@ -367,7 +366,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||
t.invoke();
|
||||
});
|
||||
childDetectZone.scheduleMicroTask(
|
||||
blacklistedStackFramesSymbol,
|
||||
zoneJsInternalStackFramesSymbol,
|
||||
() => {
|
||||
throw Error();
|
||||
},
|
||||
|
Reference in New Issue
Block a user