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:
parent
4a9f4520ce
commit
cb7164a236
|
@ -102,7 +102,7 @@ This package will provide following functionality.
|
||||||
|
|
||||||
without `zone-error` patch, the example above will output `false`, with the patch, the reuslt will be `true`.
|
without `zone-error` patch, the example above will output `false`, with the patch, the reuslt will be `true`.
|
||||||
|
|
||||||
2. BlacklistZoneStackFrames: remove zone.js stack from `stackTrace`, and add `zone` information. Without this patch, a lot of `zone.js` invocation stack will be shown
|
2. ZoneJsInternalStackFrames: remove zone.js stack from `stackTrace`, and add `zone` information. Without this patch, a lot of `zone.js` invocation stack will be shown
|
||||||
in stack frames.
|
in stack frames.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -123,18 +123,18 @@ This package will provide following functionality.
|
||||||
```
|
```
|
||||||
|
|
||||||
The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
|
The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
|
||||||
The flag is `__Zone_Error_BlacklistedStackFrames_policy`. And the available options is:
|
The flag is `__Zone_Error_ZoneJsInternalStackFrames_policy`. And the available options is:
|
||||||
|
|
||||||
1. default: this is the default one, if you load `zone.js/dist/zone-error` without
|
1. default: this is the default one, if you load `zone.js/dist/zone-error` without
|
||||||
setting the flag, `default` will be used, and `BlackListStackFrames` will be available
|
setting the flag, `default` will be used, and `ZoneJsInternalStackFrames` will be available
|
||||||
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
|
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
|
||||||
will slow down `new Error()` a little bit.
|
will slow down `new Error()` a little bit.
|
||||||
|
|
||||||
2. disable: this will disable `BlackListZoneStackFrame` feature, and if you load
|
2. disable: this will disable `ZoneJsInternalStackFrames` feature, and if you load
|
||||||
`zone.js/dist/zone-error`, you will only get a `wrapped Error` which can handle
|
`zone.js/dist/zone-error`, you will only get a `wrapped Error` which can handle
|
||||||
`Error inherit` issue.
|
`Error inherit` issue.
|
||||||
|
|
||||||
3. lazy: this is a feature to let you be able to get `BlackListZoneStackFrame` feature,
|
3. lazy: this is a feature to let you be able to get `ZoneJsInternalStackFrames` feature,
|
||||||
but not impact performance. But as a trade off, you can't get the `zone free stack
|
but not impact performance. But as a trade off, you can't get the `zone free stack
|
||||||
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.
|
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.
|
||||||
|
|
||||||
|
|
|
@ -34,15 +34,15 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
|
|
||||||
const enum FrameType {
|
const enum FrameType {
|
||||||
/// Skip this frame when printing out stack
|
/// Skip this frame when printing out stack
|
||||||
blackList,
|
zoneJsInternal,
|
||||||
/// This frame marks zone transition
|
/// This frame marks zone transition
|
||||||
transition
|
transition
|
||||||
}
|
}
|
||||||
|
|
||||||
const blacklistedStackFramesSymbol = api.symbol('blacklistedStackFrames');
|
const zoneJsInternalStackFramesSymbol = api.symbol('zoneJsInternalStackFrames');
|
||||||
const NativeError = global[api.symbol('Error')] = global['Error'];
|
const NativeError = global[api.symbol('Error')] = global['Error'];
|
||||||
// Store the frames which should be removed from the stack frames
|
// 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
|
// We must find the frame where Error was created, otherwise we assume we don't understand stack
|
||||||
let zoneAwareFrame1: string;
|
let zoneAwareFrame1: string;
|
||||||
let zoneAwareFrame2: string;
|
let zoneAwareFrame2: string;
|
||||||
|
@ -53,9 +53,10 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
global['Error'] = ZoneAwareError;
|
global['Error'] = ZoneAwareError;
|
||||||
const stackRewrite = 'stackRewrite';
|
const stackRewrite = 'stackRewrite';
|
||||||
|
|
||||||
type BlackListedStackFramesPolicy = 'default'|'disable'|'lazy';
|
type ZoneJsInternalStackFramesPolicy = 'default'|'disable'|'lazy';
|
||||||
const blackListedStackFramesPolicy: BlackListedStackFramesPolicy =
|
const zoneJsInternalStackFramesPolicy: ZoneJsInternalStackFramesPolicy =
|
||||||
global['__Zone_Error_BlacklistedStackFrames_policy'] || 'default';
|
global['__Zone_Error_BlacklistedStackFrames_policy'] ||
|
||||||
|
global['__Zone_Error_ZoneJsInternalStackFrames_policy'] || 'default';
|
||||||
|
|
||||||
interface ZoneFrameName {
|
interface ZoneFrameName {
|
||||||
zoneName: string;
|
zoneName: string;
|
||||||
|
@ -88,8 +89,8 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
for (; i < frames.length && zoneFrame; i++) {
|
for (; i < frames.length && zoneFrame; i++) {
|
||||||
let frame = frames[i];
|
let frame = frames[i];
|
||||||
if (frame.trim()) {
|
if (frame.trim()) {
|
||||||
switch (blackListedStackFrames[frame]) {
|
switch (zoneJsInternalStackFrames[frame]) {
|
||||||
case FrameType.blackList:
|
case FrameType.zoneJsInternal:
|
||||||
frames.splice(i, 1);
|
frames.splice(i, 1);
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
|
@ -124,10 +125,10 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
// Process the stack trace and rewrite the frames.
|
// Process the stack trace and rewrite the frames.
|
||||||
if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
|
if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
|
||||||
let zoneFrame = api.currentZoneFrame();
|
let zoneFrame = api.currentZoneFrame();
|
||||||
if (blackListedStackFramesPolicy === 'lazy') {
|
if (zoneJsInternalStackFramesPolicy === 'lazy') {
|
||||||
// don't handle stack trace now
|
// don't handle stack trace now
|
||||||
(error as any)[api.symbol('zoneFrameNames')] = buildZoneFrameNames(zoneFrame);
|
(error as any)[api.symbol('zoneFrameNames')] = buildZoneFrameNames(zoneFrame);
|
||||||
} else if (blackListedStackFramesPolicy === 'default') {
|
} else if (zoneJsInternalStackFramesPolicy === 'default') {
|
||||||
try {
|
try {
|
||||||
error.stack = error.zoneAwareStack = buildZoneAwareStackFrames(originalStack, zoneFrame);
|
error.stack = error.zoneAwareStack = buildZoneAwareStackFrames(originalStack, zoneFrame);
|
||||||
} catch (e) {
|
} 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
|
// Copy the prototype so that instanceof operator works as expected
|
||||||
ZoneAwareError.prototype = NativeError.prototype;
|
ZoneAwareError.prototype = NativeError.prototype;
|
||||||
(ZoneAwareError as any)[blacklistedStackFramesSymbol] = blackListedStackFrames;
|
(ZoneAwareError as any)[zoneJsInternalStackFramesSymbol] = zoneJsInternalStackFrames;
|
||||||
(ZoneAwareError as any)[stackRewrite] = false;
|
(ZoneAwareError as any)[stackRewrite] = false;
|
||||||
|
|
||||||
const zoneAwareStackSymbol = api.symbol('zoneAwareStack');
|
const zoneAwareStackSymbol = api.symbol('zoneAwareStack');
|
||||||
|
|
||||||
// try to define zoneAwareStack property when blackListed
|
// try to define zoneAwareStack property when zoneJsInternal frames policy is delay
|
||||||
// policy is delay
|
if (zoneJsInternalStackFramesPolicy === 'lazy') {
|
||||||
if (blackListedStackFramesPolicy === 'lazy') {
|
|
||||||
Object.defineProperty(ZoneAwareError.prototype, 'zoneAwareStack', {
|
Object.defineProperty(ZoneAwareError.prototype, 'zoneAwareStack', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
|
@ -253,12 +253,11 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (blackListedStackFramesPolicy === 'disable') {
|
if (zoneJsInternalStackFramesPolicy === 'disable') {
|
||||||
// don't need to run detectZone to populate
|
// don't need to run detectZone to populate zoneJs internal stack frames
|
||||||
// blacklisted stack frames
|
|
||||||
return;
|
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
|
// 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
|
// the execution through all of the above methods so that we can look at the stack trace and
|
||||||
// find the frames of interest.
|
// find the frames of interest.
|
||||||
|
@ -296,7 +295,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
frame.replace('ZoneAwareError', 'Error.ZoneAwareError');
|
frame.replace('ZoneAwareError', 'Error.ZoneAwareError');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blackListedStackFrames[zoneAwareFrame2] = FrameType.blackList;
|
zoneJsInternalStackFrames[zoneAwareFrame2] = FrameType.zoneJsInternal;
|
||||||
}
|
}
|
||||||
if (fnName.indexOf('runGuarded') !== -1) {
|
if (fnName.indexOf('runGuarded') !== -1) {
|
||||||
runGuardedFrame = true;
|
runGuardedFrame = true;
|
||||||
|
@ -305,9 +304,9 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
} else if (fnName.indexOf('run') !== -1) {
|
} else if (fnName.indexOf('run') !== -1) {
|
||||||
runFrame = true;
|
runFrame = true;
|
||||||
} else {
|
} else {
|
||||||
frameType = FrameType.blackList;
|
frameType = FrameType.zoneJsInternal;
|
||||||
}
|
}
|
||||||
blackListedStackFrames[frame] = frameType;
|
zoneJsInternalStackFrames[frame] = frameType;
|
||||||
// Once we find all of the frames we can stop looking.
|
// Once we find all of the frames we can stop looking.
|
||||||
if (runFrame && runGuardedFrame && runTaskFrame) {
|
if (runFrame && runGuardedFrame && runTaskFrame) {
|
||||||
(ZoneAwareError as any)[stackRewrite] = true;
|
(ZoneAwareError as any)[stackRewrite] = true;
|
||||||
|
@ -320,7 +319,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
}
|
}
|
||||||
}) as Zone;
|
}) as Zone;
|
||||||
// carefully constructor a stack frame which contains all of the frames of interest which
|
// 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({
|
const childDetectZone = detectZone.fork({
|
||||||
name: 'child',
|
name: 'child',
|
||||||
|
@ -351,13 +350,13 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
childDetectZone.runGuarded(() => {
|
childDetectZone.runGuarded(() => {
|
||||||
const fakeTransitionTo = () => {};
|
const fakeTransitionTo = () => {};
|
||||||
childDetectZone.scheduleEventTask(
|
childDetectZone.scheduleEventTask(
|
||||||
blacklistedStackFramesSymbol,
|
zoneJsInternalStackFramesSymbol,
|
||||||
() => {
|
() => {
|
||||||
childDetectZone.scheduleMacroTask(
|
childDetectZone.scheduleMacroTask(
|
||||||
blacklistedStackFramesSymbol,
|
zoneJsInternalStackFramesSymbol,
|
||||||
() => {
|
() => {
|
||||||
childDetectZone.scheduleMicroTask(
|
childDetectZone.scheduleMicroTask(
|
||||||
blacklistedStackFramesSymbol,
|
zoneJsInternalStackFramesSymbol,
|
||||||
() => {
|
() => {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
},
|
},
|
||||||
|
@ -367,7 +366,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
|
||||||
t.invoke();
|
t.invoke();
|
||||||
});
|
});
|
||||||
childDetectZone.scheduleMicroTask(
|
childDetectZone.scheduleMicroTask(
|
||||||
blacklistedStackFramesSymbol,
|
zoneJsInternalStackFramesSymbol,
|
||||||
() => {
|
() => {
|
||||||
throw Error();
|
throw Error();
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,13 +19,13 @@ __karma__.loaded = function() {};
|
||||||
let entryPoint = 'browser_entry_point';
|
let entryPoint = 'browser_entry_point';
|
||||||
|
|
||||||
if (typeof __karma__ !== 'undefined') {
|
if (typeof __karma__ !== 'undefined') {
|
||||||
(window as any)['__Zone_Error_BlacklistedStackFrames_policy'] =
|
(window as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] =
|
||||||
(__karma__ as any).config.errorpolicy;
|
(__karma__ as any).config.errorpolicy;
|
||||||
if ((__karma__ as any).config.entrypoint) {
|
if ((__karma__ as any).config.entrypoint) {
|
||||||
entryPoint = (__karma__ as any).config.entrypoint;
|
entryPoint = (__karma__ as any).config.entrypoint;
|
||||||
}
|
}
|
||||||
} else if (typeof process !== 'undefined') {
|
} else if (typeof process !== 'undefined') {
|
||||||
(window as any)['__Zone_Error_BlacklistedStackFrames_policy'] = process.env.errorpolicy;
|
(window as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] = process.env.errorpolicy;
|
||||||
if (process.env.entrypoint) {
|
if (process.env.entrypoint) {
|
||||||
entryPoint = process.env.entrypoint;
|
entryPoint = process.env.entrypoint;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] =
|
process.env['errorpolicy'] = (global as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] =
|
||||||
'disable';
|
'disable';
|
||||||
import './node_error_entry_point';
|
import './node_error_entry_point';
|
||||||
|
|
|
@ -14,7 +14,7 @@ import '../lib/zone';
|
||||||
import '../lib/common/promise';
|
import '../lib/common/promise';
|
||||||
import '../lib/common/to-string';
|
import '../lib/common/to-string';
|
||||||
|
|
||||||
process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] =
|
process.env['errorpolicy'] = (global as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] =
|
||||||
'disable';
|
'disable';
|
||||||
// Setup test environment
|
// Setup test environment
|
||||||
require('@bazel/jasmine').boot();
|
require('@bazel/jasmine').boot();
|
||||||
|
|
|
@ -6,5 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] = 'lazy';
|
process.env['errorpolicy'] = (global as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] =
|
||||||
|
'lazy';
|
||||||
import './node_error_entry_point';
|
import './node_error_entry_point';
|
||||||
|
|
Loading…
Reference in New Issue