1
1
'use strict' ;
2
2
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
+
3
25
var es6Promise = require ( 'es6-promise' ) . Promise ;
4
26
27
+ if ( resolvedPromise ) {
28
+ es6Promise . _setScheduler ( function ( fn ) {
29
+ resolvedPromise . then ( fn ) ;
30
+ } ) ;
31
+ }
32
+
5
33
// es6-promise asap should schedule microtasks via zone.scheduleMicrotask so that any
6
34
// user defined hooks are triggered
7
35
es6Promise . _setAsap ( function ( fn , arg ) {
@@ -25,23 +53,5 @@ module.exports = {
25
53
addMicrotaskSupport : addMicrotaskSupport
26
54
} ;
27
55
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
30
56
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
- }
47
57
0 commit comments