Visitar URL original
fix(zone.js): guard against null handle when detecting refreshable ti… · angular/angular@36c2197 · GitHub
Skip to content

Commit 36c2197

Browse files
lazergthePunderWoman
authored andcommitted
fix(zone.js): guard against null handle when detecting refreshable timers
A timer wrapper such as a browser extension, policy, or automation harness can block a call and return null instead of a handle. patchTimer then read `.refresh` on that null value and threw synchronously. Treat a nullish handle as non-refreshable so the patched timer keeps working. Fixes #70044
1 parent c9c4f2a commit 36c2197

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎packages/zone.js/lib/common/timers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
4949
} else {
5050
data.handle = handleOrId;
5151
// On Node.js a timeout and interval can be restarted over and over again by using the `.refresh` method.
52-
data.isRefreshable = isFunction(handleOrId.refresh);
52+
data.isRefreshable = isFunction(handleOrId?.refresh);
5353
}
5454

5555
return task;

‎packages/zone.js/test/common/setTimeout.spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ describe('setTimeout', function () {
151151
clearTimeout(null as any);
152152
clearTimeout(<any>{});
153153
});
154+
155+
it('should not throw when the native timer returns null', function () {
156+
// A wrapper that blocks a timer (e.g. a browser extension or automation
157+
// harness) can return null instead of a handle, see issue #70044.
158+
const fakeGlobal = {
159+
setTimeout: function () {
160+
return null;
161+
},
162+
clearTimeout: function () {},
163+
};
164+
patchTimer(fakeGlobal, 'set', 'clear', 'Timeout');
165+
expect(() => (fakeGlobal as any).setTimeout(() => {}, 0)).not.toThrow();
166+
});
154167
});

0 commit comments

Comments
 (0)