(Zone: ZoneType)
| 13 | import {ZoneType} from '../zone-impl'; |
| 14 | |
| 15 | export function patchError(Zone: ZoneType): void { |
| 16 | Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => { |
| 17 | /* |
| 18 | * This code patches Error so that: |
| 19 | * - It ignores un-needed stack frames. |
| 20 | * - It Shows the associated Zone for reach frame. |
| 21 | */ |
| 22 | |
| 23 | const enum FrameType { |
| 24 | /// Skip this frame when printing out stack |
| 25 | zoneJsInternal, |
| 26 | /// This frame marks zone transition |
| 27 | transition, |
| 28 | } |
| 29 | |
| 30 | const zoneJsInternalStackFramesSymbol = api.symbol('zoneJsInternalStackFrames'); |
| 31 | const NativeError = (global[api.symbol('Error')] = global['Error']); |
| 32 | // Store the frames which should be removed from the stack frames |
| 33 | const zoneJsInternalStackFrames: {[frame: string]: FrameType} = {}; |
| 34 | // We must find the frame where Error was created, otherwise we assume we don't understand stack |
| 35 | let zoneAwareFrame1: string; |
| 36 | let zoneAwareFrame2: string; |
| 37 | let zoneAwareFrame1WithoutNew: string; |
| 38 | let zoneAwareFrame2WithoutNew: string; |
| 39 | let zoneAwareFrame3WithoutNew: string; |
| 40 | |
| 41 | global['Error'] = ZoneAwareError; |
| 42 | const stackRewrite = 'stackRewrite'; |
| 43 | |
| 44 | type ZoneJsInternalStackFramesPolicy = 'default' | 'disable' | 'lazy'; |
| 45 | const zoneJsInternalStackFramesPolicy: ZoneJsInternalStackFramesPolicy = |
| 46 | global['__Zone_Error_BlacklistedStackFrames_policy'] || |
| 47 | global['__Zone_Error_ZoneJsInternalStackFrames_policy'] || |
| 48 | 'default'; |
| 49 | |
| 50 | interface ZoneFrameName { |
| 51 | zoneName: string; |
| 52 | parent?: ZoneFrameName; |
| 53 | } |
| 54 | |
| 55 | function buildZoneFrameNames(zoneFrame: _ZoneFrame) { |
| 56 | let zoneFrameName: ZoneFrameName = {zoneName: zoneFrame.zone.name}; |
| 57 | let result = zoneFrameName; |
| 58 | while (zoneFrame.parent) { |
| 59 | zoneFrame = zoneFrame.parent; |
| 60 | const parentZoneFrameName = {zoneName: zoneFrame.zone.name}; |
| 61 | zoneFrameName.parent = parentZoneFrameName; |
| 62 | zoneFrameName = parentZoneFrameName; |
| 63 | } |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | function buildZoneAwareStackFrames( |
| 68 | originalStack: string, |
| 69 | zoneFrame: _ZoneFrame | ZoneFrameName | null, |
| 70 | isZoneFrame = true, |
| 71 | ) { |
| 72 | let frames: string[] = originalStack.split('\n'); |
no test coverage detected
searching dependent graphs…