Skip to content

Commit

Permalink
fix: zero coercion timeout removal bug (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jun 22, 2024
1 parent 4cd78b6 commit 3e5585e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtins/web/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TimerTask final : public api::AsyncTask {
};

std::map<int32_t, PollableHandle> TimerTask::timer_ids_ = {};
int32_t TimerTask::next_timer_id = 0;
int32_t TimerTask::next_timer_id = 1;

namespace builtins::web::timers {

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/timers/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { serveTest } from "../test-server.js";
import { assert, strictEqual, throws, deepStrictEqual, AssertionError } from "../assert.js";

export const handler = serveTest(async (t) => {
await t.asyncTest("clearTimeout invalid", (resolve, reject) => {
// cleartimeout can be called with arbitrary stuff
clearTimeout('blah');

const dontDeleteTimeout = setTimeout(resolve, 100);

// null converts to zero, which must not delete a real timer
clearTimeout(null);
});

await t.asyncTest("setTimeout-order", (resolve, reject) => {
let first = false;
setTimeout(() => {
Expand Down

0 comments on commit 3e5585e

Please sign in to comment.