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