Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 4a5dd63

Browse files
committed
fix(promise): fix #891, sometimes NativePromise will not ready, and reduce zone.js size
1 parent e5fa562 commit 4a5dd63

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

lib/common/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export function patchEventTarget(
531531
const captureTasks = target[symbolCaptureEventName];
532532

533533
if (tasks) {
534-
const removeTasks = [...tasks];
534+
const removeTasks = tasks.slice();
535535
for (let i = 0; i < removeTasks.length; i++) {
536536
const task = removeTasks[i];
537537
let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
@@ -540,7 +540,7 @@ export function patchEventTarget(
540540
}
541541

542542
if (captureTasks) {
543-
const removeTasks = [...captureTasks];
543+
const removeTasks = captureTasks.slice();
544544
for (let i = 0; i < removeTasks.length; i++) {
545545
const task = removeTasks[i];
546546
let delegate = task.originalDelegate ? task.originalDelegate : task.callback;

lib/common/promise.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
243243
let resolve: (v: any) => void;
244244
let reject: (v: any) => void;
245245
let promise: any = new this((res, rej) => {
246-
[resolve, reject] = [res, rej];
246+
resolve = res;
247+
reject = rej;
247248
});
248249
function onResolve(value: any) {
249250
promise && (promise = null || resolve(value));

lib/zone.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,11 @@ const Zone: ZoneType = (function(global: any) {
13201320
patchOnProperties: noop,
13211321
patchMethod: () => noop,
13221322
setNativePromise: (NativePromise: any) => {
1323-
nativeMicroTaskQueuePromise = NativePromise.resolve(0);
1323+
// sometimes NativePromise lazy load it's prototype
1324+
// so NativePromise.resolve may not be ready at this point
1325+
if (NativePromise && typeof NativePromise.resolve === FUNCTION) {
1326+
nativeMicroTaskQueuePromise = NativePromise.resolve(0);
1327+
}
13241328
},
13251329
};
13261330
let _currentZoneFrame: _ZoneFrame = {parent: null, zone: new Zone(null, null)};

tsconfig-esm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"inlineSourceMap": false,
1010
"inlineSources": false,
1111
"declaration": true,
12+
"downlevelIteration": false,
1213
"noEmitOnError": false,
1314
"stripInternal": true,
1415
"sourceMap": true,

0 commit comments

Comments
 (0)