11cb0ef41Sopenharmony_ci// Make sure `setTimeout()` and friends don't throw if the user-supplied
21cb0ef41Sopenharmony_ci// function has .call() and .apply() monkey-patched to undesirable values.
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/12956
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci'use strict';
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst common = require('../common');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci{
111cb0ef41Sopenharmony_ci  const fn = common.mustCall(10);
121cb0ef41Sopenharmony_ci  fn.call = 'not a function';
131cb0ef41Sopenharmony_ci  fn.apply = 'also not a function';
141cb0ef41Sopenharmony_ci  setTimeout(fn, 1);
151cb0ef41Sopenharmony_ci  setTimeout(fn, 1, 'oneArg');
161cb0ef41Sopenharmony_ci  setTimeout(fn, 1, 'two', 'args');
171cb0ef41Sopenharmony_ci  setTimeout(fn, 1, 'three', '(3)', 'args');
181cb0ef41Sopenharmony_ci  setTimeout(fn, 1, 'more', 'than', 'three', 'args');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  setImmediate(fn, 1);
211cb0ef41Sopenharmony_ci  setImmediate(fn, 1, 'oneArg');
221cb0ef41Sopenharmony_ci  setImmediate(fn, 1, 'two', 'args');
231cb0ef41Sopenharmony_ci  setImmediate(fn, 1, 'three', '(3)', 'args');
241cb0ef41Sopenharmony_ci  setImmediate(fn, 1, 'more', 'than', 'three', 'args');
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci{
281cb0ef41Sopenharmony_ci  const testInterval = (...args) => {
291cb0ef41Sopenharmony_ci    const fn = common.mustCall(() => { clearInterval(interval); });
301cb0ef41Sopenharmony_ci    fn.call = 'not a function';
311cb0ef41Sopenharmony_ci    fn.apply = 'also not a function';
321cb0ef41Sopenharmony_ci    const interval = setInterval(fn, 1, ...args);
331cb0ef41Sopenharmony_ci  };
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  testInterval();
361cb0ef41Sopenharmony_ci  testInterval('oneArg');
371cb0ef41Sopenharmony_ci  testInterval('two', 'args');
381cb0ef41Sopenharmony_ci  testInterval('three', '(3)', 'args');
391cb0ef41Sopenharmony_ci  testInterval('more', 'than', 'three', 'args');
401cb0ef41Sopenharmony_ci}
41