1212
1313import { findEventTasks } from '../common/events' ;
1414import { 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' ;
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 as any ) . l ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
22+ Zone . __load_patch ( 'util' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
2323 api . patchOnProperties = patchOnProperties ;
2424 api . patchMethod = patchMethod ;
2525 api . bindArguments = bindArguments ;
2626} ) ;
2727
28- ( Zone as any ) . l ( 'timers' , ( global : any ) => {
28+ Zone . __load_patch ( '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 as any ) . l ( 'requestAnimationFrame' , ( global : any ) => {
36+ Zone . __load_patch ( '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 as any ) . l ( 'blocking' , ( global : any , Zone : ZoneType ) => {
42+ Zone . __load_patch ( '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- // Zone.current.run
49- return ( Zone as any ) . c . r ( delegate , global , args , name ) ;
48+ return Zone . current . run ( delegate , global , args , name ) ;
5049 } ;
5150 } ) ;
5251 }
5352} ) ;
5453
55- ( Zone as any ) . l ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
54+ Zone . __load_patch ( 'EventTarget' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
5655 // load blackListEvents from global
57- // Zone.__symbol__
58- const SYMBOL_BLACK_LISTED_EVENTS = ( Zone as any ) . s ( 'BLACK_LISTED_EVENTS' ) ;
56+ const SYMBOL_BLACK_LISTED_EVENTS = Zone . __symbol__ ( 'BLACK_LISTED_EVENTS' ) ;
5957 if ( global [ SYMBOL_BLACK_LISTED_EVENTS ] ) {
6058 ( Zone as any ) [ SYMBOL_BLACK_LISTED_EVENTS ] = global [ SYMBOL_BLACK_LISTED_EVENTS ] ;
6159 }
@@ -73,25 +71,24 @@ import {registerElementPatch} from './register-element';
7371 patchClass ( 'FileReader' ) ;
7472} ) ;
7573
76- ( Zone as any ) . l ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
74+ Zone . __load_patch ( 'on_property' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
7775 propertyDescriptorPatch ( api , global ) ;
7876 propertyPatch ( ) ;
7977 registerElementPatch ( global ) ;
8078} ) ;
8179
82- ( Zone as any ) . l ( 'canvas' , ( global : any ) => {
80+ Zone . __load_patch ( 'canvas' , ( global : any ) => {
8381 const HTMLCanvasElement = global [ 'HTMLCanvasElement' ] ;
84- // o is 'undefined'
85- if ( typeof HTMLCanvasElement !== o && HTMLCanvasElement . prototype &&
82+ if ( typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement . prototype &&
8683 HTMLCanvasElement . prototype . toBlob ) {
8784 patchMacroTask ( HTMLCanvasElement . prototype , 'toBlob' , ( self : any , args : any [ ] ) => {
8885 return { name : 'HTMLCanvasElement.toBlob' , target : self , cbIdx : 0 , args : args } ;
8986 } ) ;
9087 }
9188} ) ;
9289
93- ( Zone as any ) . l ( 'XHR' , ( global : any , Zone : ZoneType ) => {
94- // Treat XMLHTTPRequest as a macrotask.
90+ Zone . __load_patch ( 'XHR' , ( global : any , Zone : ZoneType ) => {
91+ // Treat XMLHttpRequest as a macrotask.
9592 patchXHR ( global ) ;
9693
9794 const XHR_TASK = zoneSymbol ( 'xhrTask' ) ;
@@ -111,18 +108,17 @@ import {registerElementPatch} from './register-element';
111108 const XMLHttpRequestPrototype : any = XMLHttpRequest . prototype ;
112109
113110 function findPendingTask ( target : any ) {
114- const pendingTask : Task = target [ XHR_TASK ] ;
115- return pendingTask ;
111+ return target [ XHR_TASK ] ;
116112 }
117113
118- let oriAddListener = XMLHttpRequestPrototype [ i ] ;
119- let oriRemoveListener = XMLHttpRequestPrototype [ j ] ;
114+ let oriAddListener = XMLHttpRequestPrototype [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
115+ let oriRemoveListener = XMLHttpRequestPrototype [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
120116 if ( ! oriAddListener ) {
121117 const XMLHttpRequestEventTarget = window [ 'XMLHttpRequestEventTarget' ] ;
122118 if ( XMLHttpRequestEventTarget ) {
123119 const XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget . prototype ;
124- oriAddListener = XMLHttpRequestEventTargetPrototype [ i ] ;
125- oriRemoveListener = XMLHttpRequestEventTargetPrototype [ j ] ;
120+ oriAddListener = XMLHttpRequestEventTargetPrototype [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
121+ oriRemoveListener = XMLHttpRequestEventTargetPrototype [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
126122 }
127123 }
128124
@@ -136,14 +132,12 @@ import {registerElementPatch} from './register-element';
136132 // remove existing event listener
137133 const listener = target [ XHR_LISTENER ] ;
138134 if ( ! oriAddListener ) {
139- // i is addEventListener zoneSymbol
140- // j is removeEventListener zoneSymbol
141- oriAddListener = target [ i ] ;
142- oriRemoveListener = target [ j ] ;
135+ oriAddListener = target [ ZONE_SYMBOL_ADD_EVENT_LISTENER ] ;
136+ oriRemoveListener = target [ ZONE_SYMBOL_REMOVE_EVENT_LISTENER ] ;
143137 }
144138
145139 if ( listener ) {
146- oriRemoveListener . apply ( target , [ READY_STATE_CHANGE , listener ] ) ;
140+ oriRemoveListener . call ( target , READY_STATE_CHANGE , listener ) ;
147141 }
148142 const newListener = target [ XHR_LISTENER ] = ( ) => {
149143 if ( target . readyState === target . DONE ) {
@@ -154,7 +148,7 @@ import {registerElementPatch} from './register-element';
154148 }
155149 }
156150 } ;
157- oriAddListener . apply ( target , [ READY_STATE_CHANGE , newListener ] ) ;
151+ oriAddListener . call ( target , READY_STATE_CHANGE , newListener ) ;
158152
159153 const storedTask : Task = target [ XHR_TASK ] ;
160154 if ( ! storedTask ) {
@@ -185,8 +179,7 @@ import {registerElementPatch} from './register-element';
185179 const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send' ;
186180 const sendNative : Function =
187181 patchMethod ( XMLHttpRequestPrototype , 'send' , ( ) => function ( self : any , args : any [ ] ) {
188- // Zone.current
189- const zone = ( Zone as any ) . c ;
182+ const zone = Zone . current ;
190183 if ( self [ XHR_SYNC ] ) {
191184 // if the XHR is sync there is no task to schedule, just execute the code.
192185 return sendNative . apply ( self , args ) ;
@@ -199,25 +192,22 @@ import {registerElementPatch} from './register-element';
199192 args : args ,
200193 aborted : false
201194 } ;
202- // Zone.scheduleMacroTask
203- return zone . sc (
195+ return zone . scheduleMacroTask (
204196 XMLHTTPREQUEST_SOURCE , placeholderCallback , options , scheduleTask , clearTask ) ;
205197 }
206198 } ) ;
207199
208200 const abortNative = patchMethod ( XMLHttpRequestPrototype , 'abort' , ( ) => function ( self : any ) {
209201 const task : Task = findPendingTask ( self ) ;
210- // r is 'string'
211- if ( task && typeof task . type == r ) {
202+ if ( task && typeof task . type == 'string' ) {
212203 // If the XHR has already completed, do nothing.
213204 // If the XHR has already been aborted, do nothing.
214205 // Fix #569, call abort multiple times before done will cause
215206 // macroTask task count be negative number
216207 if ( task . cancelFn == null || ( task . data && ( < XHROptions > task . data ) . aborted ) ) {
217208 return ;
218209 }
219- // Zone.cancelTask
220- ( task . zone as any ) . ct ( task ) ;
210+ task . zone . cancelTask ( task ) ;
221211 }
222212 // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
223213 // task
@@ -226,14 +216,14 @@ import {registerElementPatch} from './register-element';
226216 }
227217} ) ;
228218
229- ( Zone as any ) . l ( 'geolocation' , ( global : any ) => {
219+ Zone . __load_patch ( 'geolocation' , ( global : any ) => {
230220 /// GEO_LOCATION
231221 if ( global [ 'navigator' ] && global [ 'navigator' ] . geolocation ) {
232222 patchPrototype ( global [ 'navigator' ] . geolocation , [ 'getCurrentPosition' , 'watchPosition' ] ) ;
233223 }
234224} ) ;
235225
236- ( Zone as any ) . l ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType ) => {
226+ Zone . __load_patch ( 'PromiseRejectionEvent' , ( global : any , Zone : ZoneType ) => {
237227 // handle unhandled promise rejection
238228 function findPromiseRejectionHandler ( evtName : string ) {
239229 return function ( e : any ) {
0 commit comments