angular-cn/packages/zone.js/lib/common
JiaLiPassion 0652b29f62 fix(zone.js): setTimeout patch should clean tasksByHandleId cache. (#40586)
Close #40387

Currently zone.js patches `setTimeout` and keeps a `tasksByHandleId` map to keep `timerId` <-> `ZoneTask`
relationship. This is needed so that when `clearTimeout(timerId)` is called, zone.js can find the associated
`ZoneTask`. Now zone.js set the `tasksByHandleId` map in the `scheduleTask` function, but if the `setTimeout`
is running in the `FakeAsyncZoneSpec` or any other `ZoneSpec` with `onScheduleTask` hooks. The `scheduleTask`
in `timer` patch may not be invoked.

For example:

```
fakeAsync(() => {
  setTimeout(() => {});
  tick();
});
```

In this case, the `timerId` kept in the `tasksByHandleId` map is not cleared.
This is because the `FakeAsyncZoneSpec` in the `onScheduleTask` hook looks like this.

```
onScheduleTask(delegate, ..., task) {
  fakeAsyncScheduler.setTimeout(task);
  return task;
}
```

Because `FakeAsyncZoneSpec` handles the task itself and it doesn't call `parentDelegate.onScheduleTask`,
therefore the default `scheduleTask` in the `timer` patch is not invoked.

In this commit, the cleanup logic is moved from `scheduleTask` to `setTimeout` patch entry to
avoid the memory leak.

PR Close #40586
2021-02-09 10:43:05 -08:00
..
error-rewrite.ts refactor(zone.js): rename BlacklistedStackFrames to InternalZoneJsStackFrames (#38978) 2020-09-28 16:23:41 -04:00
events.ts refactor(zone.js): remove usages of blacklist related to UNPATCHED_EVENTS (#38930) 2020-09-22 15:05:01 -07:00
fetch.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
promise.ts fix(zone.js): disable wrap uncaught promise rejection should handle primitive value (#38476) 2020-09-24 11:32:44 -04:00
timers.ts fix(zone.js): setTimeout patch should clean tasksByHandleId cache. (#40586) 2021-02-09 10:43:05 -08:00
to-string.ts fix(zone.js): zone.js toString patch should check typeof Promise is function (#38350) 2020-08-25 09:51:50 -07:00
utils.ts fix(zone.js): patch child method that overrides an already patched method (#39850) 2020-12-02 12:52:27 -08:00