12
12
13
13
import { findEventTasks } from '../common/events' ;
14
14
import { patchTimer } from '../common/timers' ;
15
- import { bindArguments , i , j , o , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , r , zoneSymbol } from '../common/utils' ;
15
+ import { bindArguments , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , ZONE_SYMBOL_ADD_EVENT_LISTENER , ZONE_SYMBOL_REMOVE_EVENT_LISTENER , zoneSymbol } from '../common/utils' ;
16
16
17
17
import { propertyPatch } from './define-property' ;
18
18
import { eventTargetPatch , patchEvent } from './event-target' ;
19
19
import { propertyDescriptorPatch } from './property-descriptor' ;
20
20
import { registerElementPatch } from './register-element' ;
21
21
22
- ( Zone as any ) . l ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
22
+ Zone . __load_patch ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
23
23
api . patchOnProperties = patchOnProperties ;
24
24
api . patchMethod = patchMethod ;
25
25
api . bindArguments = bindArguments ;
26
26
} ) ;
27
27
28
- ( Zone as any ) . l ( 'timers' , ( global : any ) => {
28
+ Zone . __load_patch ( 'timers' , ( global : any ) => {
29
29
const set = 'set' ;
30
30
const clear = 'clear' ;
31
31
patchTimer ( global , set , clear , 'Timeout' ) ;
32
32
patchTimer ( global , set , clear , 'Interval' ) ;
33
33
patchTimer ( global , set , clear , 'Immediate' ) ;
34
34
} ) ;
35
35
36
- ( Zone as any ) . l ( 'requestAnimationFrame' , ( global : any ) => {
36
+ Zone . __load_patch ( 'requestAnimationFrame' , ( global : any ) => {
37
37
patchTimer ( global , 'request' , 'cancel' , 'AnimationFrame' ) ;
38
38
patchTimer ( global , 'mozRequest' , 'mozCancel' , 'AnimationFrame' ) ;
39
39
patchTimer ( global , 'webkitRequest' , 'webkitCancel' , 'AnimationFrame' ) ;
40
40
} ) ;
41
41
42
- ( Zone as any ) . l ( 'blocking' , ( global : any , Zone : ZoneType ) => {
42
+ Zone . __load_patch ( 'blocking' , ( global : any , Zone : ZoneType ) => {
43
43
const blockingMethods = [ 'alert' , 'prompt' , 'confirm' ] ;
44
44
for ( let i = 0 ; i < blockingMethods . length ; i ++ ) {
45
45
const name = blockingMethods [ i ] ;
46
46
patchMethod ( global , name , ( delegate , symbol , name ) => {
47
47
return function ( s : any , args : any [ ] ) {
48
- // Zone.current.run
49
- return ( Zone as any ) . c . r ( delegate , global , args , name ) ;
48
+ return Zone . current . run ( delegate , global , args , name ) ;
50
49
} ;
51
50
} ) ;
52
51
}
53
52
} ) ;
54
53
55
- ( Zone as any ) . l ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
54
+ Zone . __load_patch ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
56
55
// load blackListEvents from global
57
56
// Zone.__symbol__
58
- const SYMBOL_BLACK_LISTED_EVENTS = ( Zone as any ) . s ( 'BLACK_LISTED_EVENTS' ) ;
57
+ const SYMBOL_BLACK_LISTED_EVENTS = Zone . __symbol__ ( 'BLACK_LISTED_EVENTS' ) ;
59
58
if ( global [ SYMBOL_BLACK_LISTED_EVENTS ] ) {
60
59
( Zone as any ) [ SYMBOL_BLACK_LISTED_EVENTS ] = global [ SYMBOL_BLACK_LISTED_EVENTS ] ;
61
60
}
@@ -73,25 +72,25 @@ import {registerElementPatch} from './register-element';
73
72
patchClass ( 'FileReader' ) ;
74
73
} ) ;
75
74
76
- ( Zone as any ) . l ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
75
+ Zone . __load_patch ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
77
76
propertyDescriptorPatch ( api , global ) ;
78
77
propertyPatch ( ) ;
79
78
registerElementPatch ( global ) ;
80
79
} ) ;
81
80
82
- ( Zone as any ) . l ( 'canvas' , ( global : any ) => {
81
+ Zone . __load_patch ( 'canvas' , ( global : any ) => {
83
82
const HTMLCanvasElement = global [ 'HTMLCanvasElement' ] ;
84
83
// o is 'undefined'
85
- if ( typeof HTMLCanvasElement !== o && HTMLCanvasElement . prototype &&
84
+ if ( typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement . prototype &&
86
85
HTMLCanvasElement . prototype . toBlob ) {
87
86
patchMacroTask ( HTMLCanvasElement . prototype , 'toBlob' , ( self : any , args : any [ ] ) => {
88
87
return { name : 'HTMLCanvasElement.toBlob' , target : self , cbIdx : 0 , args : args } ;
89
88
} ) ;
90
89
}
91
90
} ) ;
92
91
93
- ( Zone as any ) . l ( 'XHR' , ( global : any , Zone : ZoneType ) => {
94
- // Treat XMLHTTPRequest as a macrotask.
92
+ Zone . __load_patch ( 'XHR' , ( global : any , Zone : ZoneType ) => {
93
+ // Treat XMLHttpRequest as a macrotask.
95
94
patchXHR ( global ) ;
96
95
97
96
const XHR_TASK = zoneSymbol ( 'xhrTask' ) ;
@@ -111,18 +110,17 @@ import {registerElementPatch} from './register-element';
111
110
const XMLHttpRequestPrototype : any = XMLHttpRequest . prototype ;
112
111
113
112
function findPendingTask ( target : any ) {
114
- const pendingTask : Task = target [ XHR_TASK ] ;
115
- return pendingTask ;
113
+ return target [ XHR_TASK ] ;
116
114
}
117
115
118
- let oriAddListener = XMLHttpRequestPrototype [ i ] ;
119
- let oriRemoveListener = XMLHttpRequestPrototype [ j ] ;
116
+ let oriAddListener = XMLHttpRequestPrototype [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
117
+ let oriRemoveListener = XMLHttpRequestPrototype [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
120
118
if ( ! oriAddListener ) {
121
119
const XMLHttpRequestEventTarget = window [ 'XMLHttpRequestEventTarget' ] ;
122
120
if ( XMLHttpRequestEventTarget ) {
123
121
const XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget . prototype ;
124
- oriAddListener = XMLHttpRequestEventTargetPrototype [ i ] ;
125
- oriRemoveListener = XMLHttpRequestEventTargetPrototype [ j ] ;
122
+ oriAddListener = XMLHttpRequestEventTargetPrototype [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
123
+ oriRemoveListener = XMLHttpRequestEventTargetPrototype [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
126
124
}
127
125
}
128
126
@@ -136,14 +134,12 @@ import {registerElementPatch} from './register-element';
136
134
// remove existing event listener
137
135
const listener = target [ XHR_LISTENER ] ;
138
136
if ( ! oriAddListener ) {
139
- // i is addEventListener zoneSymbol
140
- // j is removeEventListener zoneSymbol
141
- oriAddListener = target [ i ] ;
142
- oriRemoveListener = target [ j ] ;
137
+ oriAddListener = target [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
138
+ oriRemoveListener = target [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
143
139
}
144
140
145
141
if ( listener ) {
146
- oriRemoveListener . apply ( target , [ READY_STATE_CHANGE , listener ] ) ;
142
+ oriRemoveListener . call ( target , READY_STATE_CHANGE , listener ) ;
147
143
}
148
144
const newListener = target [ XHR_LISTENER ] = ( ) => {
149
145
if ( target . readyState === target . DONE ) {
@@ -154,7 +150,7 @@ import {registerElementPatch} from './register-element';
154
150
}
155
151
}
156
152
} ;
157
- oriAddListener . apply ( target , [ READY_STATE_CHANGE , newListener ] ) ;
153
+ oriAddListener . call ( target , READY_STATE_CHANGE , newListener ) ;
158
154
159
155
const storedTask : Task = target [ XHR_TASK ] ;
160
156
if ( ! storedTask ) {
@@ -186,7 +182,7 @@ import {registerElementPatch} from './register-element';
186
182
const sendNative : Function =
187
183
patchMethod ( XMLHttpRequestPrototype , 'send' , ( ) => function ( self : any , args : any [ ] ) {
188
184
// Zone.current
189
- const zone = ( Zone as any ) . c ;
185
+ const zone = Zone . current ;
190
186
if ( self [ XHR_SYNC ] ) {
191
187
// if the XHR is sync there is no task to schedule, just execute the code.
192
188
return sendNative . apply ( self , args ) ;
@@ -199,16 +195,15 @@ import {registerElementPatch} from './register-element';
199
195
args : args ,
200
196
aborted : false
201
197
} ;
202
- // Zone.scheduleMacroTask
203
- return zone . sc (
198
+ return zone . scheduleMacroTask (
204
199
XMLHTTPREQUEST_SOURCE , placeholderCallback , options , scheduleTask , clearTask ) ;
205
200
}
206
201
} ) ;
207
202
208
203
const abortNative = patchMethod ( XMLHttpRequestPrototype , 'abort' , ( ) => function ( self : any ) {
209
204
const task : Task = findPendingTask ( self ) ;
210
205
// r is 'string'
211
- if ( task && typeof task . type == r ) {
206
+ if ( task && typeof task . type == 'string' ) {
212
207
// If the XHR has already completed, do nothing.
213
208
// If the XHR has already been aborted, do nothing.
214
209
// Fix #569, call abort multiple times before done will cause
@@ -217,7 +212,7 @@ import {registerElementPatch} from './register-element';
217
212
return ;
218
213
}
219
214
// Zone.cancelTask
220
- ( task . zone as any ) . ct ( task ) ;
215
+ task . zone . cancelTask ( task ) ;
221
216
}
222
217
// Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
223
218
// task
@@ -226,14 +221,14 @@ import {registerElementPatch} from './register-element';
226
221
}
227
222
} ) ;
228
223
229
- ( Zone as any ) . l ( 'geolocation' , ( global : any ) => {
224
+ Zone . __load_patch ( 'geolocation' , ( global : any ) => {
230
225
/// GEO_LOCATION
231
226
if ( global [ 'navigator' ] && global [ 'navigator' ] . geolocation ) {
232
227
patchPrototype ( global [ 'navigator' ] . geolocation , [ 'getCurrentPosition' , 'watchPosition' ] ) ;
233
228
}
234
229
} ) ;
235
230
236
- ( Zone as any ) . l ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType ) => {
231
+ Zone . __load_patch ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType ) => {
237
232
// handle unhandled promise rejection
238
233
function findPromiseRejectionHandler ( evtName : string ) {
239
234
return function ( e : any ) {
0 commit comments