12
12
13
13
import { findEventTasks } from '../common/events' ;
14
14
import { patchTimer } from '../common/timers' ;
15
- import { patchArguments , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , wrapFunctionArgs , zoneSymbol } from '../common/utils' ;
15
+ import { bindArguments , i , j , o , patchClass , patchMacroTask , patchMethod , patchOnProperties , patchPrototype , r , 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 . __load_patch ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
22
+ ( Zone as any ) . l ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
23
23
api . patchOnProperties = patchOnProperties ;
24
24
api . patchMethod = patchMethod ;
25
- api . patchArguments = patchArguments ;
25
+ api . bindArguments = bindArguments ;
26
26
} ) ;
27
27
28
- Zone . __load_patch ( 'timers' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
28
+ ( Zone as any ) . l ( '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 . __load_patch ( 'requestAnimationFrame' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
36
+ ( Zone as any ) . l ( '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 . __load_patch ( 'blocking' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
42
+ ( Zone as any ) . l ( '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
- return Zone . current . run ( delegate , global , args , name ) ;
48
+ return ( Zone as any ) . c . r ( delegate , global , args , name ) ;
49
49
} ;
50
50
} ) ;
51
51
}
52
52
} ) ;
53
53
54
- Zone . __load_patch ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
54
+ ( Zone as any ) . l ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
55
55
// load blackListEvents from global
56
- const SYMBOL_BLACK_LISTED_EVENTS = Zone . __symbol__ ( 'BLACK_LISTED_EVENTS' ) ;
56
+ const SYMBOL_BLACK_LISTED_EVENTS = ( Zone as any ) . s ( 'BLACK_LISTED_EVENTS' ) ;
57
57
if ( global [ SYMBOL_BLACK_LISTED_EVENTS ] ) {
58
58
( Zone as any ) [ SYMBOL_BLACK_LISTED_EVENTS ] = global [ SYMBOL_BLACK_LISTED_EVENTS ] ;
59
59
}
@@ -71,23 +71,23 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
71
71
patchClass ( 'FileReader' ) ;
72
72
} ) ;
73
73
74
- Zone . __load_patch ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
74
+ ( Zone as any ) . l ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
75
75
propertyDescriptorPatch ( api , global ) ;
76
76
propertyPatch ( ) ;
77
77
registerElementPatch ( global ) ;
78
78
} ) ;
79
79
80
- Zone . __load_patch ( 'canvas' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
80
+ ( Zone as any ) . l ( 'canvas' , ( global : any ) => {
81
81
const HTMLCanvasElement = global [ 'HTMLCanvasElement' ] ;
82
- if ( typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement . prototype &&
82
+ if ( typeof HTMLCanvasElement !== o && HTMLCanvasElement . prototype &&
83
83
HTMLCanvasElement . prototype . toBlob ) {
84
84
patchMacroTask ( HTMLCanvasElement . prototype , 'toBlob' , ( self : any , args : any [ ] ) => {
85
- return { name : 'HTMLCanvasElement.toBlob' , target : self , callbackIndex : 0 , args : args } ;
85
+ return { name : 'HTMLCanvasElement.toBlob' , target : self , cbIdx : 0 , args : args } ;
86
86
} ) ;
87
87
}
88
88
} ) ;
89
89
90
- Zone . __load_patch ( 'XHR' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
90
+ ( Zone as any ) . l ( 'XHR' , ( global : any , Zone : ZoneType ) => {
91
91
// Treat XMLHTTPRequest as a macrotask.
92
92
patchXHR ( global ) ;
93
93
@@ -105,21 +105,21 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
105
105
}
106
106
107
107
function patchXHR ( window : any ) {
108
+ const XMLHttpRequestPrototype : any = XMLHttpRequest . prototype ;
109
+
108
110
function findPendingTask ( target : any ) {
109
111
const pendingTask : Task = target [ XHR_TASK ] ;
110
112
return pendingTask ;
111
113
}
112
114
113
- const SYMBOL_ADDEVENTLISTENER = zoneSymbol ( 'addEventListener' ) ;
114
- const SYMBOL_REMOVEEVENTLISTENER = zoneSymbol ( 'removeEventListener' ) ;
115
-
116
- let oriAddListener = ( XMLHttpRequest . prototype as any ) [ SYMBOL_ADDEVENTLISTENER ] ;
117
- let oriRemoveListener = ( XMLHttpRequest . prototype as any ) [ SYMBOL_REMOVEEVENTLISTENER ] ;
115
+ let oriAddListener = XMLHttpRequestPrototype [ i ] ;
116
+ let oriRemoveListener = XMLHttpRequestPrototype [ j ] ;
118
117
if ( ! oriAddListener ) {
119
118
const XMLHttpRequestEventTarget = window [ 'XMLHttpRequestEventTarget' ] ;
120
119
if ( XMLHttpRequestEventTarget ) {
121
- oriAddListener = XMLHttpRequestEventTarget . prototype [ SYMBOL_ADDEVENTLISTENER ] ;
122
- oriRemoveListener = XMLHttpRequestEventTarget . prototype [ SYMBOL_REMOVEEVENTLISTENER ] ;
120
+ const XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget . prototype ;
121
+ oriAddListener = XMLHttpRequestEventTargetPrototype [ i ] ;
122
+ oriRemoveListener = XMLHttpRequestEventTargetPrototype [ j ] ;
123
123
}
124
124
}
125
125
@@ -133,8 +133,8 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
133
133
// remove existing event listener
134
134
const listener = target [ XHR_LISTENER ] ;
135
135
if ( ! oriAddListener ) {
136
- oriAddListener = target [ SYMBOL_ADDEVENTLISTENER ] ;
137
- oriRemoveListener = target [ SYMBOL_REMOVEEVENTLISTENER ] ;
136
+ oriAddListener = target [ i ] ;
137
+ oriRemoveListener = target [ j ] ;
138
138
}
139
139
140
140
if ( listener ) {
@@ -170,17 +170,17 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
170
170
return abortNative . apply ( data . target , data . args ) ;
171
171
}
172
172
173
- const openNative : Function = patchMethod (
174
- window . XMLHttpRequest . prototype , 'open' , ( ) => function ( self : any , args : any [ ] ) {
173
+ const openNative : Function =
174
+ patchMethod ( XMLHttpRequestPrototype , 'open' , ( ) => function ( self : any , args : any [ ] ) {
175
175
self [ XHR_SYNC ] = args [ 2 ] == false ;
176
176
self [ XHR_URL ] = args [ 1 ] ;
177
177
return openNative . apply ( self , args ) ;
178
178
} ) ;
179
179
180
180
const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send' ;
181
- const sendNative : Function = patchMethod (
182
- window . XMLHttpRequest . prototype , 'send' , ( ) => function ( self : any , args : any [ ] ) {
183
- const zone = Zone . current ;
181
+ const sendNative : Function =
182
+ patchMethod ( XMLHttpRequestPrototype , 'send' , ( ) => function ( self : any , args : any [ ] ) {
183
+ const zone = ( Zone as any ) . c ;
184
184
if ( self [ XHR_SYNC ] ) {
185
185
// if the XHR is sync there is no task to schedule, just execute the code.
186
186
return sendNative . apply ( self , args ) ;
@@ -193,49 +193,38 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
193
193
args : args ,
194
194
aborted : false
195
195
} ;
196
- return zone . scheduleMacroTask (
196
+ return zone . sc (
197
197
XMLHTTPREQUEST_SOURCE , placeholderCallback , options , scheduleTask , clearTask ) ;
198
198
}
199
199
} ) ;
200
200
201
- const STRING_TYPE = 'string' ;
202
-
203
- const abortNative = patchMethod (
204
- window . XMLHttpRequest . prototype , 'abort' ,
205
- ( delegate : Function ) => function ( self : any , args : any [ ] ) {
206
- const task : Task = findPendingTask ( self ) ;
207
- if ( task && typeof task . type == STRING_TYPE ) {
208
- // If the XHR has already completed, do nothing.
209
- // If the XHR has already been aborted, do nothing.
210
- // Fix #569, call abort multiple times before done will cause
211
- // macroTask task count be negative number
212
- if ( task . cancelFn == null || ( task . data && ( < XHROptions > task . data ) . aborted ) ) {
213
- return ;
214
- }
215
- task . zone . cancelTask ( task ) ;
216
- }
217
- // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
218
- // task
219
- // to cancel. Do nothing.
220
- } ) ;
201
+ const abortNative = patchMethod ( XMLHttpRequestPrototype , 'abort' , ( ) => function ( self : any ) {
202
+ const task : Task = findPendingTask ( self ) ;
203
+ if ( task && typeof task . type == r ) {
204
+ // If the XHR has already completed, do nothing.
205
+ // If the XHR has already been aborted, do nothing.
206
+ // Fix #569, call abort multiple times before done will cause
207
+ // macroTask task count be negative number
208
+ if ( task . cancelFn == null || ( task . data && ( < XHROptions > task . data ) . aborted ) ) {
209
+ return ;
210
+ }
211
+ ( task . zone as any ) . ct ( task ) ;
212
+ }
213
+ // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
214
+ // task
215
+ // to cancel. Do nothing.
216
+ } ) ;
221
217
}
222
218
} ) ;
223
219
224
- Zone . __load_patch ( 'geolocation' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
220
+ ( Zone as any ) . l ( 'geolocation' , ( global : any ) => {
225
221
/// GEO_LOCATION
226
222
if ( global [ 'navigator' ] && global [ 'navigator' ] . geolocation ) {
227
223
patchPrototype ( global [ 'navigator' ] . geolocation , [ 'getCurrentPosition' , 'watchPosition' ] ) ;
228
224
}
229
225
} ) ;
230
226
231
- Zone . __load_patch ( 'getUserMedia' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
232
- let navigator = global [ 'navigator' ] ;
233
- if ( navigator && navigator . getUserMedia ) {
234
- navigator . getUserMedia = wrapFunctionArgs ( navigator . getUserMedia ) ;
235
- }
236
- } ) ;
237
-
238
- Zone . __load_patch ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
227
+ ( Zone as any ) . l ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType ) => {
239
228
// handle unhandled promise rejection
240
229
function findPromiseRejectionHandler ( evtName : string ) {
241
230
return function ( e : any ) {
0 commit comments