Skip to content

Commit

Permalink
Use 64-bit time (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager authored Oct 19, 2024
1 parent 24843cb commit abf6124
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
14 changes: 7 additions & 7 deletions binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef struct {
js_ref_t *on_timer;
js_ref_t *on_check;

int32_t next_delay;
int64_t next_delay;
} bare_timer_t;

static void
Expand Down Expand Up @@ -80,8 +80,8 @@ bare_timers__on_timer (uv_timer_t *handle) {

if (err < 0) self->next_delay = 0; // Retrigger on next tick
else {
int32_t next_delay;
err = js_get_value_int32(env, result, &next_delay);
int64_t next_delay;
err = js_get_value_int64(env, result, &next_delay);
assert(err == 0);

if (next_delay < self->next_delay || self->next_delay == -1) {
Expand Down Expand Up @@ -247,8 +247,8 @@ bare_timers_resume (js_env_t *env, js_callback_info_t *info) {
err = js_get_arraybuffer_info(env, argv[0], (void **) &self, NULL);
assert(err == 0);

int32_t ms;
err = js_get_value_int32(env, argv[1], &ms);
int64_t ms;
err = js_get_value_int64(env, argv[1], &ms);
assert(err == 0);

uint32_t ref;
Expand Down Expand Up @@ -334,8 +334,8 @@ bare_timers_start (js_env_t *env, js_callback_info_t *info) {
err = js_get_arraybuffer_info(env, argv[0], (void **) &self, NULL);
assert(err == 0);

int32_t ms;
err = js_get_value_int32(env, argv[1], &ms);
int64_t ms;
err = js_get_value_int64(env, argv[1], &ms);
assert(err == 0);

self->next_delay = ms;
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ function deleteTimerList (list) {

function queueTimer (ms, repeat, fn, args) {
if (typeof fn !== 'function') throw typeError('Callback must be a function', 'ERR_INVALID_CALLBACK')
if (ms < 1 || ms > 0x7fffffff || Number.isNaN(ms)) ms = 1

if (ms < 1 || ms > Number.MAX_SAFE_INTEGER || Number.isNaN(ms)) ms = 1

const now = Date.now()

Expand Down
8 changes: 0 additions & 8 deletions test/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ test('error inside of setTimeout', async function (t) {
})
})

test('setTimeout with big delay', async function (t) {
t.plan(1)

timers.setTimeout(function () {
t.pass()
}, 0x7fffffff + 1)
})

test('setTimeout with zero delay', async function (t) {
t.plan(1)

Expand Down

0 comments on commit abf6124

Please sign in to comment.