Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

schedulers-fix.js 1.5KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var globalThis = require('../internals/global-this');
  3. var apply = require('../internals/function-apply');
  4. var isCallable = require('../internals/is-callable');
  5. var ENVIRONMENT = require('../internals/environment');
  6. var USER_AGENT = require('../internals/environment-user-agent');
  7. var arraySlice = require('../internals/array-slice');
  8. var validateArgumentsLength = require('../internals/validate-arguments-length');
  9. var Function = globalThis.Function;
  10. // dirty IE9- and Bun 0.3.0- checks
  11. var WRAP = /MSIE .\./.test(USER_AGENT) || ENVIRONMENT === 'BUN' && (function () {
  12. var version = globalThis.Bun.version.split('.');
  13. return version.length < 3 || version[0] === '0' && (version[1] < 3 || version[1] === '3' && version[2] === '0');
  14. })();
  15. // IE9- / Bun 0.3.0- setTimeout / setInterval / setImmediate additional parameters fix
  16. // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
  17. // https://github.com/oven-sh/bun/issues/1633
  18. module.exports = function (scheduler, hasTimeArg) {
  19. var firstParamIndex = hasTimeArg ? 2 : 1;
  20. return WRAP ? function (handler, timeout /* , ...arguments */) {
  21. var boundArgs = validateArgumentsLength(arguments.length, 1) > firstParamIndex;
  22. var fn = isCallable(handler) ? handler : Function(handler);
  23. var params = boundArgs ? arraySlice(arguments, firstParamIndex) : [];
  24. var callback = boundArgs ? function () {
  25. apply(fn, this, params);
  26. } : fn;
  27. return hasTimeArg ? scheduler(callback, timeout) : scheduler(callback);
  28. } : scheduler;
  29. };