@@ -330,6 +330,44 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
330330 ZoneAwarePromise [ 'all' ] = ZoneAwarePromise . all ;
331331
332332 const NativePromise = global [ symbolPromise ] = global [ 'Promise' ] ;
333+ const ZONE_AWARE_PROMISE = Zone . __symbol__ ( 'ZoneAwarePromise' ) ;
334+
335+ let desc = Object . getOwnPropertyDescriptor ( global , 'Promise' ) ;
336+ if ( ! desc || desc . configurable ) {
337+ desc && delete desc . writable ;
338+ desc && delete desc . value ;
339+ if ( ! desc ) {
340+ desc = { configurable : true , enumerable : true } ;
341+ }
342+ desc . get = function ( ) {
343+ // if we already set ZoneAwarePromise, use patched one
344+ // otherwise return native one.
345+ return global [ ZONE_AWARE_PROMISE ] ? global [ ZONE_AWARE_PROMISE ] : global [ symbolPromise ] ;
346+ } ;
347+ desc . set = function ( NewNativePromise ) {
348+ if ( NewNativePromise === ZoneAwarePromise ) {
349+ // if the NewNativePromise is ZoneAwarePromise
350+ // save to global
351+ global [ ZONE_AWARE_PROMISE ] = NewNativePromise ;
352+ } else {
353+ // if the NewNativePromise is not ZoneAwarePromise
354+ // for example: after load zone.js, some library just
355+ // set es6-promise to global, if we set it to global
356+ // directly, assertZonePatched will fail and angular
357+ // will not loaded, so we just set the NewNativePromise
358+ // to global[symbolPromise], so the result is just like
359+ // we load ES6 Promise before zone.js
360+ global [ symbolPromise ] = NewNativePromise ;
361+ if ( ! NewNativePromise . prototype [ symbolThen ] ) {
362+ patchThen ( NewNativePromise ) ;
363+ }
364+ api . setNativePromise ( NewNativePromise ) ;
365+ }
366+ } ;
367+
368+ Object . defineProperty ( global , 'Promise' , desc ) ;
369+ }
370+
333371 global [ 'Promise' ] = ZoneAwarePromise ;
334372
335373 const symbolThenPatched = __symbol__ ( 'thenPatched' ) ;
0 commit comments