license fileoverview suppress import * as webSocketPatch from './websocket' ; export function propertyDescriptorLegacyPatch ( api , _global ) { const { isNode , isMix } = api . getGlobalObjects ( ) ! ; if ( isNode && ! isMix ) { return ; } if ( ! canPatchViaPropertyDescriptor ( api , _global ) ) { const supportsWebSocket = typeof WebSocket !== 'undefined' ; patchViaCapturingAllTheEvents ( api ) ; api . patchClass ( 'XMLHttpRequest' ) ; if ( supportsWebSocket ) { webSocketPatch . apply ( api , _global ) ; } ( Zone as any ) [ api . symbol ( 'patchEvents' ) ] = true ; } } function canPatchViaPropertyDescriptor ( api , _global ) { const { isBrowser , isMix } = api . getGlobalObjects ( ) ! ; if ( ( isBrowser || isMix ) && ! api . ObjectGetOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) && typeof Element !== 'undefined' ) { const desc = api . ObjectGetOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ; if ( desc && ! desc . configurable ) return false ; if ( desc ) { api . ObjectDefineProperty ( Element . prototype , 'onclick' , { enumerable : true , configurable : true , get : function ( ) { return true ; } } ) ; const div = document . createElement ( 'div' ) ; const result = ! ! div . onclick ; api . ObjectDefineProperty ( Element . prototype , 'onclick' , desc ) ; return result ; } } const XMLHttpRequest = _global [ 'XMLHttpRequest' ] ; if ( ! XMLHttpRequest ) { return false ; } const ON_READY_STATE_CHANGE = 'onreadystatechange' ; const XMLHttpRequestPrototype = XMLHttpRequest . prototype ; const xhrDesc = api . ObjectGetOwnPropertyDescriptor ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE ) ; if ( xhrDesc ) { api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , { enumerable : true , configurable : true , get : function ( ) { return true ; } } ) ; const req = new XMLHttpRequest ( ) ; const result = ! ! req . onreadystatechange ; api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , xhrDesc || { } ) ; return result ; } else { const SYMBOL_FAKE_ONREADYSTATECHANGE = api . symbol ( 'fake' ) ; api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , { enumerable : true , configurable : true , get : function ( ) { return this [ SYMBOL_FAKE_ONREADYSTATECHANGE ] ; } , set : function ( value ) { this [ SYMBOL_FAKE_ONREADYSTATECHANGE ] = value ; } } ) ; const req = new XMLHttpRequest ( ) ; const detectFunc = ( ) => { } ; req . onreadystatechange = detectFunc ; const result = ( req as any ) [ SYMBOL_FAKE_ONREADYSTATECHANGE ] === detectFunc ; req . onreadystatechange = null as any ; return result ; } } function patchViaCapturingAllTheEvents ( api ) { const { eventNames } = api . getGlobalObjects ( ) ! ; const unboundKey = api . symbol ( 'unbound' ) ; for ( let i = 0 ; i < eventNames . length ; i ++ ) { const property = eventNames [ i ] ; const onproperty = 'on' + property ; self . addEventListener ( property , function ( event ) { let elt = < Node > event . target , bound , source ; if ( elt ) { source = elt . constructor [ 'name' ] + '.' + onproperty ; } else { source = 'unknown.' + onproperty ; } while ( elt ) { if ( elt [ onproperty ] && ! elt [ onproperty ] [ unboundKey ] ) { bound = api . wrapWithCurrentZone ( elt [ onproperty ] , source ) ; bound [ unboundKey ] = elt [ onproperty ] ; elt [ onproperty ] = bound ; } elt = elt . parentElement ; } } , true ) ; } }