license fileoverview suppress /** Object.getOwnPropertyDescriptor */ export const ObjectGetOwnPropertyDescriptor = Object . getOwnPropertyDescriptor ; /** Object.defineProperty */ export const ObjectDefineProperty = Object . defineProperty ; /** Object.getPrototypeOf */ export const ObjectGetPrototypeOf = Object . getPrototypeOf ; /** Object.create */ export const ObjectCreate = Object . create ; /** Array.prototype.slice */ export const ArraySlice = Array . prototype . slice ; /** addEventListener string const */ export const ADD_EVENT_LISTENER_STR = 'addEventListener' ; /** removeEventListener string const */ export const REMOVE_EVENT_LISTENER_STR = 'removeEventListener' ; /** zoneSymbol addEventListener */ export const ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone . __symbol__ ( ADD_EVENT_LISTENER_STR ) ; /** zoneSymbol removeEventListener */ export const ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone . __symbol__ ( REMOVE_EVENT_LISTENER_STR ) ; /** true string const */ export const TRUE_STR = 'true' ; /** false string const */ export const FALSE_STR = 'false' ; /** Zone symbol prefix string const. */ export const ZONE_SYMBOL_PREFIX = Zone . __symbol__ ( '' ) ; export function wrapWithCurrentZone < T extends Function > ( callback , source ) { return Zone . current . wrap ( callback , source ) ; } export function scheduleMacroTaskWithCurrentZone ( source , callback , data ? , customSchedule ? , customCancel ? ) { return Zone . current . scheduleMacroTask ( source , callback , data , customSchedule , customCancel ) ; } declare const WorkerGlobalScope ; export const zoneSymbol = Zone . __symbol__ ; const isWindowExists = typeof window !== 'undefined' ; const internalWindow = isWindowExists ? window : undefined ; const _global = isWindowExists && internalWindow || typeof self === 'object' && self || global ; const REMOVE_ATTRIBUTE = 'removeAttribute' ; const NULL_ON_PROP_VALUE = [ null ] ; export function bindArguments ( args , source ) { for ( let i = args . length - 1 ; i >= 0 ; i -- ) { if ( typeof args [ i ] === 'function' ) { args [ i ] = wrapWithCurrentZone ( args [ i ] , source + '_' + i ) ; } } return args ; } export function patchPrototype ( prototype , fnNames ) { const source = prototype . constructor [ 'name' ] ; for ( let i = 0 ; i < fnNames . length ; i ++ ) { const name = fnNames [ i ] ; const delegate = prototype [ name ] ; if ( delegate ) { const prototypeDesc = ObjectGetOwnPropertyDescriptor ( prototype , name ) ; if ( ! isPropertyWritable ( prototypeDesc ) ) { continue ; } prototype [ name ] = ( ( delegate ) => { const patched = function ( ) { return delegate . apply ( this , bindArguments ( < any > arguments , source + '.' + name ) ) ; } ; attachOriginToPatched ( patched , delegate ) ; return patched ; } ) ( delegate ) ; } } } export function isPropertyWritable ( propertyDesc ) { if ( ! propertyDesc ) { return true ; } if ( propertyDesc . writable === false ) { return false ; } return ! ( typeof propertyDesc . get === 'function' && typeof propertyDesc . set === 'undefined' ) ; } export const isWebWorker = ( typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ) ; export const isNode = ( ! ( 'nw' in _global ) && typeof _global . process !== 'undefined' && { } . toString . call ( _global . process ) === '[object process]' ) ; export const isBrowser = ! isNode && ! isWebWorker && ! ! ( isWindowExists && internalWindow [ 'HTMLElement' ] ) ; export const isMix = typeof _global . process !== 'undefined' && { } . toString . call ( _global . process ) === '[object process]' && ! isWebWorker && ! ! ( isWindowExists && internalWindow [ 'HTMLElement' ] ) ; const zoneSymbolEventNames = { } ; const wrapFn = function ( event ) { event = event || _global . event ; if ( ! event ) { return ; } let eventNameSymbol = zoneSymbolEventNames [ event . type ] ; if ( ! eventNameSymbol ) { eventNameSymbol = zoneSymbolEventNames [ event . type ] = zoneSymbol ( 'ON_PROPERTY' + event . type ) ; } const target = this || event . target || _global ; const listener = target [ eventNameSymbol ] ; let result ; if ( isBrowser && target === internalWindow && event . type === 'error' ) { const errorEvent = event as any ; result = listener && listener . call ( this , errorEvent . message , errorEvent . filename , errorEvent . lineno , errorEvent . colno , errorEvent . error ) ; if ( result === true ) { event . preventDefault ( ) ; } } else { result = listener && listener . apply ( this , arguments ) ; if ( result != undefined && ! result ) { event . preventDefault ( ) ; } } return result ; } ; export function patchProperty ( obj , prop , prototype ? ) { let desc = ObjectGetOwnPropertyDescriptor ( obj , prop ) ; if ( ! desc && prototype ) { const prototypeDesc = ObjectGetOwnPropertyDescriptor ( prototype , prop ) ; if ( prototypeDesc ) { desc = { enumerable : true , configurable : true } ; } } if ( ! desc || ! desc . configurable ) { return ; } const onPropPatchedSymbol = zoneSymbol ( 'on' + prop + 'patched' ) ; if ( obj . hasOwnProperty ( onPropPatchedSymbol ) && obj [ onPropPatchedSymbol ] ) { return ; } delete desc . writable ; delete desc . value ; const originalDescGet = desc . get ; const originalDescSet = desc . set ; const eventName = prop . substr ( 2 ) ; let eventNameSymbol = zoneSymbolEventNames [ eventName ] ; if ( ! eventNameSymbol ) { eventNameSymbol = zoneSymbolEventNames [ eventName ] = zoneSymbol ( 'ON_PROPERTY' + eventName ) ; } desc . set = function ( newValue ) { let target = this ; if ( ! target && obj === _global ) { target = _global ; } if ( ! target ) { return ; } let previousValue = target [ eventNameSymbol ] ; if ( previousValue ) { target . removeEventListener ( eventName , wrapFn ) ; } if ( originalDescSet ) { originalDescSet . apply ( target , NULL_ON_PROP_VALUE ) ; } if ( typeof newValue === 'function' ) { target [ eventNameSymbol ] = newValue ; target . addEventListener ( eventName , wrapFn , false ) ; } else { target [ eventNameSymbol ] = null ; } } ; desc . get = function ( ) { let target = this ; if ( ! target && obj === _global ) { target = _global ; } if ( ! target ) { return null ; } const listener = target [ eventNameSymbol ] ; if ( listener ) { return listener ; } else if ( originalDescGet ) { let value = originalDescGet && originalDescGet . call ( this ) ; if ( value ) { desc ! . set ! . call ( this , value ) ; if ( typeof target [ REMOVE_ATTRIBUTE ] === 'function' ) { target . removeAttribute ( prop ) ; } return value ; } } return null ; } ; ObjectDefineProperty ( obj , prop , desc ) ; obj [ onPropPatchedSymbol ] = true ; } export function patchOnProperties ( obj , properties , prototype ? ) { if ( properties ) { for ( let i = 0 ; i < properties . length ; i ++ ) { patchProperty ( obj , 'on' + properties [ i ] , prototype ) ; } } else { const onProperties = [ ] ; for ( const prop in obj ) { if ( prop . substr ( 0 , 2 ) == 'on' ) { onProperties . push ( prop ) ; } } for ( let j = 0 ; j < onProperties . length ; j ++ ) { patchProperty ( obj , onProperties [ j ] , prototype ) ; } } } const originalInstanceKey = zoneSymbol ( 'originalInstance' ) ; export function patchClass ( className ) { const OriginalClass = _global [ className ] ; if ( ! OriginalClass ) return ; _global [ zoneSymbol ( className ) ] = OriginalClass ; _global [ className ] = function ( ) { const a = bindArguments ( < any > arguments , className ) ; switch ( a . length ) { case 0 : this [ originalInstanceKey ] = new OriginalClass ( ) ; break ; case 1 : this [ originalInstanceKey ] = new OriginalClass ( a [ 0 ] ) ; break ; case 2 : this [ originalInstanceKey ] = new OriginalClass ( a [ 0 ] , a [ 1 ] ) ; break ; case 3 : this [ originalInstanceKey ] = new OriginalClass ( a [ 0 ] , a [ 1 ] , a [ 2 ] ) ; break ; case 4 : this [ originalInstanceKey ] = new OriginalClass ( a [ 0 ] , a [ 1 ] , a [ 2 ] , a [ 3 ] ) ; break ; default : throw new Error ( 'Arg list too long.' ) ; } } ; attachOriginToPatched ( _global [ className ] , OriginalClass ) ; const instance = new OriginalClass ( function ( ) { } ) ; let prop ; for ( prop in instance ) { if ( className === 'XMLHttpRequest' && prop === 'responseBlob' ) continue ; ( function ( prop ) { if ( typeof instance [ prop ] === 'function' ) { _global [ className ] . prototype [ prop ] = function ( ) { return this [ originalInstanceKey ] [ prop ] . apply ( this [ originalInstanceKey ] , arguments ) ; } ; } else { ObjectDefineProperty ( _global [ className ] . prototype , prop , { set : function ( fn ) { if ( typeof fn === 'function' ) { this [ originalInstanceKey ] [ prop ] = wrapWithCurrentZone ( fn , className + '.' + prop ) ; attachOriginToPatched ( this [ originalInstanceKey ] [ prop ] , fn ) ; } else { this [ originalInstanceKey ] [ prop ] = fn ; } } , get : function ( ) { return this [ originalInstanceKey ] [ prop ] ; } } ) ; } } ( prop ) ) ; } for ( prop in OriginalClass ) { if ( prop !== 'prototype' && OriginalClass . hasOwnProperty ( prop ) ) { _global [ className ] [ prop ] = OriginalClass [ prop ] ; } } } export function copySymbolProperties ( src , dest ) { if ( typeof ( Object as any ) . getOwnPropertySymbols !== 'function' ) { return ; } const symbols = ( Object as any ) . getOwnPropertySymbols ( src ) ; symbols . forEach ( ( symbol ) => { const desc = Object . getOwnPropertyDescriptor ( src , symbol ) ; Object . defineProperty ( dest , symbol , { get : function ( ) { return src [ symbol ] ; } , set : function ( value ) { if ( desc && ( ! desc . writable || typeof desc . set !== 'function' ) ) { return ; } src [ symbol ] = value ; } , enumerable : desc ? desc . enumerable : true , configurable : desc ? desc . configurable : true } ) ; } ) ; } let shouldCopySymbolProperties = false ; export function setShouldCopySymbolProperties ( flag ) { shouldCopySymbolProperties = flag ; } export function patchMethod ( target , name , patchFn ) { let proto = target ; while ( proto && ! proto . hasOwnProperty ( name ) ) { proto = ObjectGetPrototypeOf ( proto ) ; } if ( ! proto && target [ name ] ) { proto = target ; } const delegateName = zoneSymbol ( name ) ; let delegate = null ; if ( proto && ! ( delegate = proto [ delegateName ] ) ) { delegate = proto [ delegateName ] = proto [ name ] ; const desc = proto && ObjectGetOwnPropertyDescriptor ( proto , name ) ; if ( isPropertyWritable ( desc ) ) { const patchDelegate = patchFn ( delegate ! , delegateName , name ) ; proto [ name ] = function ( ) { return patchDelegate ( this , arguments as any ) ; } ; attachOriginToPatched ( proto [ name ] , delegate ) ; if ( shouldCopySymbolProperties ) { copySymbolProperties ( delegate , proto [ name ] ) ; } } } return delegate ; } export interface MacroTaskMeta extends TaskData { name : string ; target : any ; cbIdx : number ; args : any [ ] ; } export function patchMacroTask ( obj , funcName , metaCreator ) { let setNative = null ; function scheduleTask ( task ) { const data = < MacroTaskMeta > task . data ; data . args [ data . cbIdx ] = function ( ) { task . invoke . apply ( this , arguments ) ; } ; setNative ! . apply ( data . target , data . args ) ; return task ; } setNative = patchMethod ( obj , funcName , ( delegate ) => function ( self , args ) { const meta = metaCreator ( self , args ) ; if ( meta . cbIdx >= 0 && typeof args [ meta . cbIdx ] === 'function' ) { return scheduleMacroTaskWithCurrentZone ( meta . name , args [ meta . cbIdx ] , meta , scheduleTask ) ; } else { return delegate . apply ( self , args ) ; } } ) ; } export interface MicroTaskMeta extends TaskData { name : string ; target : any ; cbIdx : number ; args : any [ ] ; } export function patchMicroTask ( obj , funcName , metaCreator ) { let setNative = null ; function scheduleTask ( task ) { const data = < MacroTaskMeta > task . data ; data . args [ data . cbIdx ] = function ( ) { task . invoke . apply ( this , arguments ) ; } ; setNative ! . apply ( data . target , data . args ) ; return task ; } setNative = patchMethod ( obj , funcName , ( delegate ) => function ( self , args ) { const meta = metaCreator ( self , args ) ; if ( meta . cbIdx >= 0 && typeof args [ meta . cbIdx ] === 'function' ) { return Zone . current . scheduleMicroTask ( meta . name , args [ meta . cbIdx ] , meta , scheduleTask ) ; } else { return delegate . apply ( self , args ) ; } } ) ; } export function attachOriginToPatched ( patched , original ) { ( patched as any ) [ zoneSymbol ( 'OriginalDelegate' ) ] = original ; } let isDetectedIEOrEdge = false ; let ieOrEdge = false ; export function isIE ( ) { try { const ua = internalWindow . navigator . userAgent ; if ( ua . indexOf ( 'MSIE ' ) !== - 1 || ua . indexOf ( 'Trident/' ) !== - 1 ) { return true ; } } catch ( error ) { } return false ; } export function isIEOrEdge ( ) { if ( isDetectedIEOrEdge ) { return ieOrEdge ; } isDetectedIEOrEdge = true ; try { const ua = internalWindow . navigator . userAgent ; if ( ua . indexOf ( 'MSIE ' ) !== - 1 || ua . indexOf ( 'Trident/' ) !== - 1 || ua . indexOf ( 'Edge/' ) !== - 1 ) { ieOrEdge = true ; } } catch ( error ) { } return ieOrEdge ; }