-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
set(Timeout|Interval|Immediate)
extra arguments fix for Bun (si…
…milarly to IE9-) oven-sh/bun#1633
- Loading branch information
Showing
8 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* global Bun -- Deno case */ | ||
module.exports = typeof Bun == 'function' && Bun && typeof Bun.version == 'string'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
'use strict'; | ||
var global = require('../internals/global'); | ||
var apply = require('../internals/function-apply'); | ||
var isCallable = require('../internals/is-callable'); | ||
var userAgent = require('../internals/engine-user-agent'); | ||
var ENGINE_IS_BUN = require('../internals/engine-is-bun'); | ||
var USER_AGENT = require('../internals/engine-user-agent'); | ||
var arraySlice = require('../internals/array-slice'); | ||
var validateArgumentsLength = require('../internals/validate-arguments-length'); | ||
|
||
var MSIE = /MSIE .\./.test(userAgent); // <- dirty ie9- check | ||
var Function = global.Function; | ||
// dirty IE9- and Bun 0.3.0- checks | ||
var WRAP = /MSIE .\./.test(USER_AGENT) || ENGINE_IS_BUN && (function () { | ||
var version = global.Bun.version.split('.'); | ||
return version.length < 3 || version[0] == 0 && (version[1] < 3 || version[1] == 3 && version[2] == 0); | ||
}); | ||
|
||
var wrap = function (scheduler) { | ||
return MSIE ? function (handler, timeout /* , ...arguments */) { | ||
var boundArgs = validateArgumentsLength(arguments.length, 1) > 2; | ||
// IE9- / Bun 0.3.0- setTimeout / setInterval / setImmediate additional parameters fix | ||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers | ||
// https://github.com/oven-sh/bun/issues/1633 | ||
module.exports = function (scheduler, hasTimeArg) { | ||
var firstParamIndex = hasTimeArg ? 2 : 1; | ||
return WRAP ? function (handler, timeout /* , ...arguments */) { | ||
var boundArgs = validateArgumentsLength(arguments.length, 1) > firstParamIndex; | ||
var fn = isCallable(handler) ? handler : Function(handler); | ||
var args = boundArgs ? arraySlice(arguments, 2) : undefined; | ||
return scheduler(boundArgs ? function () { | ||
apply(fn, this, args); | ||
} : fn, timeout); | ||
var params = boundArgs ? arraySlice(arguments, firstParamIndex) : []; | ||
var callback = boundArgs ? function () { | ||
apply(fn, this, params); | ||
} : fn; | ||
return hasTimeArg ? scheduler(callback, timeout) : scheduler(callback); | ||
} : scheduler; | ||
}; | ||
|
||
// ie9- setTimeout & setInterval additional parameters fix | ||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers | ||
module.exports = { | ||
// `setTimeout` method | ||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout | ||
setTimeout: wrap(global.setTimeout), | ||
// `setInterval` method | ||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval | ||
setInterval: wrap(global.setInterval) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters