1// Make sure `setTimeout()` and friends don't throw if the user-supplied 2// function has .call() and .apply() monkey-patched to undesirable values. 3 4// Refs: https://github.com/nodejs/node/issues/12956 5 6'use strict'; 7 8const common = require('../common'); 9 10{ 11 const fn = common.mustCall(10); 12 fn.call = 'not a function'; 13 fn.apply = 'also not a function'; 14 setTimeout(fn, 1); 15 setTimeout(fn, 1, 'oneArg'); 16 setTimeout(fn, 1, 'two', 'args'); 17 setTimeout(fn, 1, 'three', '(3)', 'args'); 18 setTimeout(fn, 1, 'more', 'than', 'three', 'args'); 19 20 setImmediate(fn, 1); 21 setImmediate(fn, 1, 'oneArg'); 22 setImmediate(fn, 1, 'two', 'args'); 23 setImmediate(fn, 1, 'three', '(3)', 'args'); 24 setImmediate(fn, 1, 'more', 'than', 'three', 'args'); 25} 26 27{ 28 const testInterval = (...args) => { 29 const fn = common.mustCall(() => { clearInterval(interval); }); 30 fn.call = 'not a function'; 31 fn.apply = 'also not a function'; 32 const interval = setInterval(fn, 1, ...args); 33 }; 34 35 testInterval(); 36 testInterval('oneArg'); 37 testInterval('two', 'args'); 38 testInterval('three', '(3)', 'args'); 39 testInterval('more', 'than', 'three', 'args'); 40} 41