angular-docs-cn/packages/zone.js/test/zone-spec
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
..
async-test.spec.ts build: support building with TypeScript 4.1 (#39571) 2020-11-25 11:10:01 -08:00
fake-async-test.spec.ts fix(zone.js): setTimeout patch should clean tasksByHandleId cache. (#40586) 2021-02-09 10:43:05 -08:00
long-stack-trace-zone.spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
proxy.spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
sync-test.spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
task-tracking.spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00