-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timers: do not use user object call/apply
Timers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. PR-URL: #12960 Ref: #12956 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
1 parent
74d5cba
commit e8438c1
Showing
2 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Make sure `setTimeout()` and friends don't throw if the user-supplied | ||
// function has .call() and .apply() monkey-patched to undesirable values. | ||
|
||
// Refs: https://github.com/nodejs/node/issues/12956 | ||
|
||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
{ | ||
const fn = common.mustCall(10); | ||
fn.call = 'not a function'; | ||
fn.apply = 'also not a function'; | ||
setTimeout(fn, 1); | ||
setTimeout(fn, 1, 'oneArg'); | ||
setTimeout(fn, 1, 'two', 'args'); | ||
setTimeout(fn, 1, 'three', '(3)', 'args'); | ||
setTimeout(fn, 1, 'more', 'than', 'three', 'args'); | ||
|
||
setImmediate(fn, 1); | ||
setImmediate(fn, 1, 'oneArg'); | ||
setImmediate(fn, 1, 'two', 'args'); | ||
setImmediate(fn, 1, 'three', '(3)', 'args'); | ||
setImmediate(fn, 1, 'more', 'than', 'three', 'args'); | ||
} | ||
|
||
{ | ||
const testInterval = (...args) => { | ||
const fn = common.mustCall(() => { clearInterval(interval); }); | ||
fn.call = 'not a function'; | ||
fn.apply = 'also not a function'; | ||
const interval = setInterval(fn, 1, ...args); | ||
}; | ||
|
||
testInterval(); | ||
testInterval('oneArg'); | ||
testInterval('two', 'args'); | ||
testInterval('three', '(3)', 'args'); | ||
testInterval('more', 'than', 'three', 'args'); | ||
} |