schedulers-fix.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. var global = require('../internals/global');
  2. var apply = require('../internals/function-apply');
  3. var isCallable = require('../internals/is-callable');
  4. var userAgent = require('../internals/engine-user-agent');
  5. var arraySlice = require('../internals/array-slice');
  6. var validateArgumentsLength = require('../internals/validate-arguments-length');
  7. var MSIE = /MSIE .\./.test(userAgent); // <- dirty ie9- check
  8. var Function = global.Function;
  9. var wrap = function (scheduler) {
  10. return MSIE ? function (handler, timeout /* , ...arguments */) {
  11. var boundArgs = validateArgumentsLength(arguments.length, 1) > 2;
  12. var fn = isCallable(handler) ? handler : Function(handler);
  13. var args = boundArgs ? arraySlice(arguments, 2) : undefined;
  14. return scheduler(boundArgs ? function () {
  15. apply(fn, this, args);
  16. } : fn, timeout);
  17. } : scheduler;
  18. };
  19. // ie9- setTimeout & setInterval additional parameters fix
  20. // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
  21. module.exports = {
  22. // `setTimeout` method
  23. // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
  24. setTimeout: wrap(global.setTimeout),
  25. // `setInterval` method
  26. // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
  27. setInterval: wrap(global.setInterval)
  28. };