Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 47962df

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(patch): check timer patch return undefined (#628)
1 parent f300658 commit 47962df

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: lib/common/timers.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
5252
return task;
5353
}
5454
// Node.js must additionally support the ref and unref functions.
55-
const handle = (<TimerOptions>task.data).handleId;
56-
if ((<any>handle).ref && (<any>handle).unref) {
55+
const handle: any = (<TimerOptions>task.data).handleId;
56+
// check whether handle is null, because some polyfill or browser
57+
// may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
58+
if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
59+
typeof handle.unref === 'function') {
5760
(<any>task).ref = (<any>handle).ref.bind(handle);
5861
(<any>task).unref = (<any>handle).unref.bind(handle);
5962
}

0 commit comments

Comments
 (0)