Skip to content

Commit 320e70a

Browse files
committed
fix(zone.js): enable monkey patching of the queueMicrotask() API in node.js
Similar to the browser, now we also monkey patch `queueMicrotask` in Node.js. This API was added in Node.js 11.
1 parent 6f5dabe commit 320e70a

File tree

11 files changed

+27
-12
lines changed

11 files changed

+27
-12
lines changed

packages/zone.js/karma-build.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ module.exports = function(config) {
1313
config.files.push('build/test/test_fake_polyfill.js');
1414
config.files.push('build/lib/zone.js');
1515
config.files.push('build/lib/common/promise.js');
16+
config.files.push('build/lib/common/queue-microtask.js');
1617
config.files.push('build/test/main.js');
1718
};

packages/zone.js/lib/browser/browser.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ Zone.__load_patch('legacy', (global: any) => {
2525
}
2626
});
2727

28-
Zone.__load_patch('queueMicrotask', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
29-
api.patchMethod(global, 'queueMicrotask', delegate => {
30-
return function(self: any, args: any[]) {
31-
Zone.current.scheduleMicroTask('queueMicrotask', args[0]);
32-
}
33-
});
34-
});
35-
36-
3728
Zone.__load_patch('timers', (global: any) => {
3829
const set = 'set';
3930
const clear = 'clear';

packages/zone.js/lib/browser/rollup-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ import '../zone';
1010
import '../common/promise';
1111
import '../common/to-string';
1212
import './api-util';
13+
import '../common/queue-microtask';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
/**
9+
* @fileoverview
10+
* @suppress {missingRequire}
11+
*/
12+
13+
Zone.__load_patch('queueMicrotask', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
14+
api.patchMethod(global, 'queueMicrotask', delegate => {
15+
return function(self: any, args: any[]) {
16+
Zone.current.scheduleMicroTask('queueMicrotask', args[0]);
17+
}
18+
});
19+
});

packages/zone.js/lib/node/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import './node_util';
1010
import './events';
1111
import './fs';
12+
import '../common/queue-microtask';
1213

1314
import {findEventTasks} from '../common/events';
1415
import {patchTimer} from '../common/timers';

packages/zone.js/lib/zone.configurations.api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ interface ZoneGlobalConfigurations {
296296

297297
/**
298298
*
299-
* Disable the monkey patching of the browser's `queueMicrotask()` API.
299+
* Disable the monkey patching of the `queueMicrotask()` API.
300300
*
301-
* By default, `zone.js` monkey patches the browser's `queueMicrotask()` API
301+
* By default, `zone.js` monkey patches the `queueMicrotask()` API
302302
* to ensure that `queueMicrotask()` callback is invoked in the same zone as zone used to invoke
303303
* `queueMicrotask()`. And also the callback is running as `microTask` like
304304
* `Promise.prototype.then()`.

packages/zone.js/test/browser-zone-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (typeof window !== 'undefined') {
1111
(window as any)[zoneSymbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] = true;
1212
}
1313
import '../lib/common/to-string';
14+
import '../lib/common/queue-microtask';
1415
import '../lib/browser/api-util';
1516
import '../lib/browser/browser-legacy';
1617
import '../lib/browser/browser';

packages/zone.js/test/browser_entry_point.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ import './mocha-patch.spec';
2828
import './jasmine-patch.spec';
2929
import './browser/messageport.spec';
3030
import './extra/cordova.spec';
31-
import './browser/queue-microtask.spec';
File renamed without changes.

packages/zone.js/test/common_tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import './common/zone.spec';
1111
import './common/task.spec';
1212
import './common/util.spec';
1313
import './common/Promise.spec';
14+
import './common/queue-microtask.spec';
1415
import './common/fetch.spec';
1516
import './common/Error.spec';
1617
import './common/setInterval.spec';

0 commit comments

Comments
 (0)