web.timers.js 1.2 KB

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