1010 * @suppress {globalThis}
1111 */
1212
13- import { isBrowser , isMix , isNode , ObjectDefineProperty , ObjectGetOwnPropertyDescriptor , patchClass , patchOnProperties , wrapWithCurrentZone , zoneSymbol } from '../common/utils' ;
14-
15- import { eventNames , filterProperties , IgnoreProperty } from './property-descriptor' ;
1613import * as webSocketPatch from './websocket' ;
1714
18- export function patchFilteredProperties (
19- target : any , onProperties : string [ ] , ignoreProperties : IgnoreProperty [ ] , prototype ?: any ) {
20- // check whether target is available, sometimes target will be undefined
21- // because different browser or some 3rd party plugin.
22- if ( ! target ) {
23- return ;
24- }
25- const filteredProperties : string [ ] = filterProperties ( target , onProperties , ignoreProperties ) ;
26- patchOnProperties ( target , filteredProperties , prototype ) ;
27- }
28-
2915export function propertyDescriptorLegacyPatch ( api : _ZonePrivate , _global : any ) {
16+ const { isNode, isMix} = api . getGlobalObjects ( ) ! ;
3017 if ( isNode && ! isMix ) {
3118 return ;
3219 }
3320
3421 const supportsWebSocket = typeof WebSocket !== 'undefined' ;
35- if ( ! canPatchViaPropertyDescriptor ( ) ) {
22+ if ( ! canPatchViaPropertyDescriptor ( api ) ) {
3623 // Safari, Android browsers (Jelly Bean)
37- patchViaCapturingAllTheEvents ( ) ;
38- patchClass ( 'XMLHttpRequest' ) ;
24+ patchViaCapturingAllTheEvents ( api ) ;
25+ api . patchClass ( 'XMLHttpRequest' ) ;
3926 if ( supportsWebSocket ) {
4027 webSocketPatch . apply ( api , _global ) ;
4128 }
4229 ( Zone as any ) [ api . symbol ( 'patchEvents' ) ] = true ;
4330 }
4431}
4532
46- function canPatchViaPropertyDescriptor ( ) {
47- if ( ( isBrowser || isMix ) && ! ObjectGetOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) &&
33+ function canPatchViaPropertyDescriptor ( api : _ZonePrivate ) {
34+ const { isBrowser, isMix} = api . getGlobalObjects ( ) ! ;
35+ if ( ( isBrowser || isMix ) &&
36+ ! api . ObjectGetOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) &&
4837 typeof Element !== 'undefined' ) {
4938 // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
5039 // IDL interface attributes are not configurable
51- const desc = ObjectGetOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
40+ const desc = api . ObjectGetOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
5241 if ( desc && ! desc . configurable ) return false ;
5342 }
5443
5544 const ON_READY_STATE_CHANGE = 'onreadystatechange' ;
5645 const XMLHttpRequestPrototype = XMLHttpRequest . prototype ;
5746
58- const xhrDesc = ObjectGetOwnPropertyDescriptor ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE ) ;
47+ const xhrDesc =
48+ api . ObjectGetOwnPropertyDescriptor ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE ) ;
5949
6050 // add enumerable and configurable here because in opera
6151 // by default XMLHttpRequest.prototype.onreadystatechange is undefined
@@ -64,7 +54,7 @@ function canPatchViaPropertyDescriptor() {
6454 // and if XMLHttpRequest.prototype.onreadystatechange is undefined,
6555 // we should set a real desc instead a fake one
6656 if ( xhrDesc ) {
67- ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
57+ api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
6858 enumerable : true ,
6959 configurable : true ,
7060 get : function ( ) {
@@ -74,11 +64,11 @@ function canPatchViaPropertyDescriptor() {
7464 const req = new XMLHttpRequest ( ) ;
7565 const result = ! ! req . onreadystatechange ;
7666 // restore original desc
77- ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , xhrDesc || { } ) ;
67+ api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , xhrDesc || { } ) ;
7868 return result ;
7969 } else {
80- const SYMBOL_FAKE_ONREADYSTATECHANGE = zoneSymbol ( 'fake' ) ;
81- ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
70+ const SYMBOL_FAKE_ONREADYSTATECHANGE = api . symbol ( 'fake' ) ;
71+ api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
8272 enumerable : true ,
8373 configurable : true ,
8474 get : function ( ) {
@@ -97,12 +87,12 @@ function canPatchViaPropertyDescriptor() {
9787 }
9888}
9989
100- const unboundKey = zoneSymbol ( 'unbound' ) ;
101-
10290// Whenever any eventListener fires, we check the eventListener target and all parents
10391// for `onwhatever` properties and replace them with zone-bound functions
10492// - Chrome (for now)
105- function patchViaCapturingAllTheEvents ( ) {
93+ function patchViaCapturingAllTheEvents ( api : _ZonePrivate ) {
94+ const { eventNames} = api . getGlobalObjects ( ) ! ;
95+ const unboundKey = api . symbol ( 'unbound' ) ;
10696 for ( let i = 0 ; i < eventNames . length ; i ++ ) {
10797 const property = eventNames [ i ] ;
10898 const onproperty = 'on' + property ;
@@ -115,7 +105,7 @@ function patchViaCapturingAllTheEvents() {
115105 }
116106 while ( elt ) {
117107 if ( elt [ onproperty ] && ! elt [ onproperty ] [ unboundKey ] ) {
118- bound = wrapWithCurrentZone ( elt [ onproperty ] , source ) ;
108+ bound = api . wrapWithCurrentZone ( elt [ onproperty ] , source ) ;
119109 bound [ unboundKey ] = elt [ onproperty ] ;
120110 elt [ onproperty ] = bound ;
121111 }
0 commit comments