1212
1313import { findEventTasks } from '../common/events' ;
1414import { 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' ;
1616
1717import { propertyPatch } from './define-property' ;
1818import { eventTargetPatch , patchEvent } from './event-target' ;
1919import { propertyDescriptorPatch } from './property-descriptor' ;
2020import { registerElementPatch } from './register-element' ;
2121
22- Zone . __load_patch ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
22+ ( Zone as any ) . l ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
2323 api . patchOnProperties = patchOnProperties ;
2424 api . patchMethod = patchMethod ;
25- api . patchArguments = patchArguments ;
25+ api . bindArguments = bindArguments ;
2626} ) ;
2727
28- Zone . __load_patch ( 'timers' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
28+ ( Zone as any ) . l ( 'timers' , ( global : any ) => {
2929 const set = 'set' ;
3030 const clear = 'clear' ;
3131 patchTimer ( global , set , clear , 'Timeout' ) ;
3232 patchTimer ( global , set , clear , 'Interval' ) ;
3333 patchTimer ( global , set , clear , 'Immediate' ) ;
3434} ) ;
3535
36- Zone . __load_patch ( 'requestAnimationFrame' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
36+ ( Zone as any ) . l ( 'requestAnimationFrame' , ( global : any ) => {
3737 patchTimer ( global , 'request' , 'cancel' , 'AnimationFrame' ) ;
3838 patchTimer ( global , 'mozRequest' , 'mozCancel' , 'AnimationFrame' ) ;
3939 patchTimer ( global , 'webkitRequest' , 'webkitCancel' , 'AnimationFrame' ) ;
4040} ) ;
4141
42- Zone . __load_patch ( 'blocking' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
42+ ( Zone as any ) . l ( 'blocking' , ( global : any , Zone : ZoneType ) => {
4343 const blockingMethods = [ 'alert' , 'prompt' , 'confirm' ] ;
4444 for ( let i = 0 ; i < blockingMethods . length ; i ++ ) {
4545 const name = blockingMethods [ i ] ;
4646 patchMethod ( global , name , ( delegate , symbol , name ) => {
4747 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 ) ;
4949 } ;
5050 } ) ;
5151 }
5252} ) ;
5353
54- Zone . __load_patch ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
54+ ( Zone as any ) . l ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
5555 // 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' ) ;
5757 if ( global [ SYMBOL_BLACK_LISTED_EVENTS ] ) {
5858 ( Zone as any ) [ SYMBOL_BLACK_LISTED_EVENTS ] = global [ SYMBOL_BLACK_LISTED_EVENTS ] ;
5959 }
@@ -71,23 +71,23 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
7171 patchClass ( 'FileReader' ) ;
7272} ) ;
7373
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 ) => {
7575 propertyDescriptorPatch ( api , global ) ;
7676 propertyPatch ( ) ;
7777 registerElementPatch ( global ) ;
7878} ) ;
7979
80- Zone . __load_patch ( 'canvas' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
80+ ( Zone as any ) . l ( 'canvas' , ( global : any ) => {
8181 const HTMLCanvasElement = global [ 'HTMLCanvasElement' ] ;
82- if ( typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement . prototype &&
82+ if ( typeof HTMLCanvasElement !== o && HTMLCanvasElement . prototype &&
8383 HTMLCanvasElement . prototype . toBlob ) {
8484 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 } ;
8686 } ) ;
8787 }
8888} ) ;
8989
90- Zone . __load_patch ( 'XHR' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
90+ ( Zone as any ) . l ( 'XHR' , ( global : any , Zone : ZoneType ) => {
9191 // Treat XMLHTTPRequest as a macrotask.
9292 patchXHR ( global ) ;
9393
@@ -105,21 +105,21 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
105105 }
106106
107107 function patchXHR ( window : any ) {
108+ const XMLHttpRequestPrototype : any = XMLHttpRequest . prototype ;
109+
108110 function findPendingTask ( target : any ) {
109111 const pendingTask : Task = target [ XHR_TASK ] ;
110112 return pendingTask ;
111113 }
112114
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 ] ;
118117 if ( ! oriAddListener ) {
119118 const XMLHttpRequestEventTarget = window [ 'XMLHttpRequestEventTarget' ] ;
120119 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 ] ;
123123 }
124124 }
125125
@@ -133,8 +133,8 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
133133 // remove existing event listener
134134 const listener = target [ XHR_LISTENER ] ;
135135 if ( ! oriAddListener ) {
136- oriAddListener = target [ SYMBOL_ADDEVENTLISTENER ] ;
137- oriRemoveListener = target [ SYMBOL_REMOVEEVENTLISTENER ] ;
136+ oriAddListener = target [ i ] ;
137+ oriRemoveListener = target [ j ] ;
138138 }
139139
140140 if ( listener ) {
@@ -170,17 +170,17 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
170170 return abortNative . apply ( data . target , data . args ) ;
171171 }
172172
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 [ ] ) {
175175 self [ XHR_SYNC ] = args [ 2 ] == false ;
176176 self [ XHR_URL ] = args [ 1 ] ;
177177 return openNative . apply ( self , args ) ;
178178 } ) ;
179179
180180 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 ;
184184 if ( self [ XHR_SYNC ] ) {
185185 // if the XHR is sync there is no task to schedule, just execute the code.
186186 return sendNative . apply ( self , args ) ;
@@ -193,49 +193,38 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
193193 args : args ,
194194 aborted : false
195195 } ;
196- return zone . scheduleMacroTask (
196+ return zone . sc (
197197 XMLHTTPREQUEST_SOURCE , placeholderCallback , options , scheduleTask , clearTask ) ;
198198 }
199199 } ) ;
200200
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+ } ) ;
221217 }
222218} ) ;
223219
224- Zone . __load_patch ( 'geolocation' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
220+ ( Zone as any ) . l ( 'geolocation' , ( global : any ) => {
225221 /// GEO_LOCATION
226222 if ( global [ 'navigator' ] && global [ 'navigator' ] . geolocation ) {
227223 patchPrototype ( global [ 'navigator' ] . geolocation , [ 'getCurrentPosition' , 'watchPosition' ] ) ;
228224 }
229225} ) ;
230226
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 ) => {
239228 // handle unhandled promise rejection
240229 function findPromiseRejectionHandler ( evtName : string ) {
241230 return function ( e : any ) {
0 commit comments