GeezerVison is showing github.com — fix(zone.js): guard against null handle when detecting refreshable ti… · angular/angular@36c2197
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/zone.js/lib/common/timers.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam |
49 | 49 | } else { |
50 | 50 | data.handle = handleOrId; |
51 | 51 | // 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); |
53 | 53 | } |
54 | 54 |
|
55 | 55 | return task; |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/zone.js/test/common/setTimeout.spec.ts +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -151,4 +151,17 @@ describe('setTimeout', function () { |
151 | 151 | clearTimeout(null as any); |
152 | 152 | clearTimeout(<any>{}); |
153 | 153 | }); |
| 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 | + }); |
154 | 167 | }); |