Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/zone.js/lib/common/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
} else {
data.handle = handleOrId;
// On Node.js a timeout and interval can be restarted over and over again by using the `.refresh` method.
data.isRefreshable = isFunction(handleOrId.refresh);
data.isRefreshable = isFunction(handleOrId?.refresh);
}

return task;
Expand Down
13 changes: 13 additions & 0 deletions packages/zone.js/test/common/setTimeout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,17 @@ describe('setTimeout', function () {
clearTimeout(null as any);
clearTimeout(<any>{});
});

it('should not throw when the native timer returns null', function () {
// A wrapper that blocks a timer (e.g. a browser extension or automation
// harness) can return null instead of a handle, see issue #70044.
const fakeGlobal = {
setTimeout: function () {
return null;
},
clearTimeout: function () {},
};
patchTimer(fakeGlobal, 'set', 'clear', 'Timeout');
expect(() => (fakeGlobal as any).setTimeout(() => {}, 0)).not.toThrow();
});
});