summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-03-20 13:22:50 +0530
committerGitHub <noreply@github.com>2024-03-20 07:52:50 +0000
commitfb0744f4e1ad08597d194fdf99f5a786cd62569c (patch)
tree1526df346f6e941c117b050537e49e452454f648
parent724cdcec7bcee49fdd0f34b35fbfbbf556c7eda3 (diff)
fix(ext/node): spread args in setImmediate (#22998)
Closes https://github.com/denoland/deno/issues/22997 Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
-rw-r--r--ext/node/polyfills/internal/timers.mjs4
-rw-r--r--tests/unit_node/timers_test.ts17
2 files changed, 18 insertions, 3 deletions
diff --git a/ext/node/polyfills/internal/timers.mjs b/ext/node/polyfills/internal/timers.mjs
index bdaf95d91..bdf258de6 100644
--- a/ext/node/polyfills/internal/timers.mjs
+++ b/ext/node/polyfills/internal/timers.mjs
@@ -117,8 +117,8 @@ Timeout.prototype[Symbol.toPrimitive] = function () {
};
// Immediate constructor function.
-export function Immediate(callback, args) {
- this._immediateId = setImmediate_(callback, args);
+export function Immediate(callback, ...args) {
+ this._immediateId = setImmediate_(callback, ...args);
}
// Make sure the linked list only shows the minimal necessary information.
diff --git a/tests/unit_node/timers_test.ts b/tests/unit_node/timers_test.ts
index c0b49c998..5a7668be7 100644
--- a/tests/unit_node/timers_test.ts
+++ b/tests/unit_node/timers_test.ts
@@ -30,7 +30,7 @@ Deno.test("[node/timers setInterval]", () => {
}
});
-Deno.test("[node/timers setImmediate]", () => {
+Deno.test("[node/timers setImmediate]", async () => {
{
const { clearImmediate, setImmediate } = timers;
const imm = setImmediate(() => {});
@@ -41,6 +41,21 @@ Deno.test("[node/timers setImmediate]", () => {
const imm = timers.setImmediate(() => {});
timers.clearImmediate(imm);
}
+
+ {
+ const deffered = Promise.withResolvers<void>();
+ const imm = timers.setImmediate(
+ (a, b) => {
+ assert(a === 1);
+ assert(b === 2);
+ deffered.resolve();
+ },
+ 1,
+ 2,
+ );
+ await deffered;
+ timers.clearImmediate(imm);
+ }
});
Deno.test("[node/timers/promises setTimeout]", () => {