11'use strict' ;
22
3+ // TODO(vicb): Create a benchmark for the different methods & the usage of the queue
4+ // see https://github.com/angular/zone.js/issues/97
5+
6+ // It is required to initialize hasNativePromise before requiring es6-promise otherwise es6-promise would
7+ // overwrite the native Promise implementation on v8 and the check would always return false.
8+ // see https://github.com/jakearchibald/es6-promise/issues/140
9+ var hasNativePromise = typeof Promise !== "undefined" &&
10+ Promise . toString ( ) . indexOf ( "[native code]" ) !== - 1 ;
11+
12+ var isFirefox = global . navigator &&
13+ global . navigator . userAgent . toLowerCase ( ) . indexOf ( 'firefox' ) > - 1 ;
14+
15+ var resolvedPromise ;
16+
17+ // TODO(vicb): remove '!isFirefox' when the bug gets fixed:
18+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1162013
19+ if ( hasNativePromise && ! isFirefox ) {
20+ // When available use a native Promise to schedule microtasks.
21+ // When not available, es6-promise fallback will be used
22+ resolvedPromise = Promise . resolve ( ) ;
23+ }
24+
325var es6Promise = require ( 'es6-promise' ) . Promise ;
426
27+ if ( resolvedPromise ) {
28+ es6Promise . _setScheduler ( function ( fn ) {
29+ resolvedPromise . then ( fn ) ;
30+ } ) ;
31+ }
32+
533// es6-promise asap should schedule microtasks via zone.scheduleMicrotask so that any
634// user defined hooks are triggered
735es6Promise . _setAsap ( function ( fn , arg ) {
@@ -25,23 +53,5 @@ module.exports = {
2553 addMicrotaskSupport : addMicrotaskSupport
2654} ;
2755
28- // TODO(vicb): Create a benchmark for the different methods & the usage of the queue
29- // see https://github.com/angular/zone.js/issues/97
3056
31- var hasNativePromise = typeof Promise !== "undefined" &&
32- Promise . toString ( ) . indexOf ( "[native code]" ) !== - 1 ;
33-
34- var isFirefox = global . navigator &&
35- global . navigator . userAgent . toLowerCase ( ) . indexOf ( 'firefox' ) > - 1 ;
36-
37- // TODO(vicb): remove '!isFirefox' when the bug gets fixed:
38- // https://bugzilla.mozilla.org/show_bug.cgi?id=1162013
39- if ( hasNativePromise && ! isFirefox ) {
40- // When available use a native Promise to schedule microtasks.
41- // When not available, es6-promise fallback will be used
42- var resolvedPromise = Promise . resolve ( ) ;
43- es6Promise . _setScheduler ( function ( fn ) {
44- resolvedPromise . then ( fn ) ;
45- } ) ;
46- }
4757
0 commit comments