From abf61247dca534c4c1002ce4a1271c9955553857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Sat, 19 Oct 2024 19:45:51 +0200 Subject: [PATCH] Use 64-bit time (#5) --- binding.c | 14 +++++++------- index.js | 3 ++- test/timeout.js | 8 -------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/binding.c b/binding.c index eedb73e..9b3b53e 100644 --- a/binding.c +++ b/binding.c @@ -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 @@ -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) { @@ -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; @@ -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; diff --git a/index.js b/index.js index 7136eda..0c39e95 100644 --- a/index.js +++ b/index.js @@ -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() diff --git a/test/timeout.js b/test/timeout.js index cb95ac5..32693c2 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -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)