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`. | ||||
| 
 | ||||
|   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. | ||||
| 
 | ||||
|     ``` | ||||
| @ -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 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 | ||||
|      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 | ||||
|      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 | ||||
|       `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 | ||||
|      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 { | ||||
|     /// 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(); | ||||
|                       }, | ||||
|  | ||||
| @ -19,13 +19,13 @@ __karma__.loaded = function() {}; | ||||
| let entryPoint = 'browser_entry_point'; | ||||
| 
 | ||||
| if (typeof __karma__ !== 'undefined') { | ||||
|   (window as any)['__Zone_Error_BlacklistedStackFrames_policy'] = | ||||
|   (window as any)['__Zone_Error_ZoneJsInternalStackFrames_policy'] = | ||||
|       (__karma__ as any).config.errorpolicy; | ||||
|   if ((__karma__ as any).config.entrypoint) { | ||||
|     entryPoint = (__karma__ as any).config.entrypoint; | ||||
|   } | ||||
| } 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) { | ||||
|     entryPoint = process.env.entrypoint; | ||||
|   } | ||||
|  | ||||
| @ -6,6 +6,6 @@ | ||||
|  * 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'; | ||||
| import './node_error_entry_point'; | ||||
|  | ||||
| @ -14,7 +14,7 @@ import '../lib/zone'; | ||||
| import '../lib/common/promise'; | ||||
| 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'; | ||||
| // Setup test environment
 | ||||
| require('@bazel/jasmine').boot(); | ||||
|  | ||||
| @ -6,5 +6,6 @@ | ||||
|  * 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'; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user