10
10
* @suppress {globalThis}
11
11
*/
12
12
13
- import { isBrowser , isMix , isNode , ObjectDefineProperty , ObjectGetOwnPropertyDescriptor , patchClass , patchOnProperties , wrapWithCurrentZone , zoneSymbol } from '../common/utils' ;
14
-
15
- import { eventNames , filterProperties , IgnoreProperty } from './property-descriptor' ;
16
13
import * as webSocketPatch from './websocket' ;
17
14
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
-
29
15
export function propertyDescriptorLegacyPatch ( api : _ZonePrivate , _global : any ) {
16
+ const { isNode, isMix} = api . getGlobalObjects ( ) ! ;
30
17
if ( isNode && ! isMix ) {
31
18
return ;
32
19
}
33
20
34
21
const supportsWebSocket = typeof WebSocket !== 'undefined' ;
35
- if ( ! canPatchViaPropertyDescriptor ( ) ) {
22
+ if ( ! canPatchViaPropertyDescriptor ( api ) ) {
36
23
// Safari, Android browsers (Jelly Bean)
37
- patchViaCapturingAllTheEvents ( ) ;
38
- patchClass ( 'XMLHttpRequest' ) ;
24
+ patchViaCapturingAllTheEvents ( api ) ;
25
+ api . patchClass ( 'XMLHttpRequest' ) ;
39
26
if ( supportsWebSocket ) {
40
27
webSocketPatch . apply ( api , _global ) ;
41
28
}
42
29
( Zone as any ) [ api . symbol ( 'patchEvents' ) ] = true ;
43
30
}
44
31
}
45
32
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' ) &&
48
37
typeof Element !== 'undefined' ) {
49
38
// WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
50
39
// IDL interface attributes are not configurable
51
- const desc = ObjectGetOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
40
+ const desc = api . ObjectGetOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
52
41
if ( desc && ! desc . configurable ) return false ;
53
42
}
54
43
55
44
const ON_READY_STATE_CHANGE = 'onreadystatechange' ;
56
45
const XMLHttpRequestPrototype = XMLHttpRequest . prototype ;
57
46
58
- const xhrDesc = ObjectGetOwnPropertyDescriptor ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE ) ;
47
+ const xhrDesc =
48
+ api . ObjectGetOwnPropertyDescriptor ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE ) ;
59
49
60
50
// add enumerable and configurable here because in opera
61
51
// by default XMLHttpRequest.prototype.onreadystatechange is undefined
@@ -64,7 +54,7 @@ function canPatchViaPropertyDescriptor() {
64
54
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
65
55
// we should set a real desc instead a fake one
66
56
if ( xhrDesc ) {
67
- ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
57
+ api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , {
68
58
enumerable : true ,
69
59
configurable : true ,
70
60
get : function ( ) {
@@ -74,11 +64,11 @@ function canPatchViaPropertyDescriptor() {
74
64
const req = new XMLHttpRequest ( ) ;
75
65
const result = ! ! req . onreadystatechange ;
76
66
// restore original desc
77
- ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , xhrDesc || { } ) ;
67
+ api . ObjectDefineProperty ( XMLHttpRequestPrototype , ON_READY_STATE_CHANGE , xhrDesc || { } ) ;
78
68
return result ;
79
69
} 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 , {
82
72
enumerable : true ,
83
73
configurable : true ,
84
74
get : function ( ) {
@@ -97,12 +87,12 @@ function canPatchViaPropertyDescriptor() {
97
87
}
98
88
}
99
89
100
- const unboundKey = zoneSymbol ( 'unbound' ) ;
101
-
102
90
// Whenever any eventListener fires, we check the eventListener target and all parents
103
91
// for `onwhatever` properties and replace them with zone-bound functions
104
92
// - Chrome (for now)
105
- function patchViaCapturingAllTheEvents ( ) {
93
+ function patchViaCapturingAllTheEvents ( api : _ZonePrivate ) {
94
+ const { eventNames} = api . getGlobalObjects ( ) ! ;
95
+ const unboundKey = api . symbol ( 'unbound' ) ;
106
96
for ( let i = 0 ; i < eventNames . length ; i ++ ) {
107
97
const property = eventNames [ i ] ;
108
98
const onproperty = 'on' + property ;
@@ -115,7 +105,7 @@ function patchViaCapturingAllTheEvents() {
115
105
}
116
106
while ( elt ) {
117
107
if ( elt [ onproperty ] && ! elt [ onproperty ] [ unboundKey ] ) {
118
- bound = wrapWithCurrentZone ( elt [ onproperty ] , source ) ;
108
+ bound = api . wrapWithCurrentZone ( elt [ onproperty ] , source ) ;
119
109
bound [ unboundKey ] = elt [ onproperty ] ;
120
110
elt [ onproperty ] = bound ;
121
111
}
0 commit comments