diff --git a/src/private.h b/src/private.h index 5b744ca5..b89bb224 100644 --- a/src/private.h +++ b/src/private.h @@ -84,8 +84,6 @@ JSValue tjs_throw_errno(JSContext *ctx, int err); JSValue tjs_new_pipe(JSContext *ctx); uv_stream_t *tjs_pipe_get_stream(JSContext *ctx, JSValueConst obj); -void tjs_execute_jobs(JSContext *ctx); - JSModuleDef *tjs__load_builtin(JSContext *ctx, const char *name); int tjs__load_file(JSContext *ctx, DynBuf *dbuf, const char *filename); JSModuleDef *tjs_module_loader(JSContext *ctx, const char *module_name, void *opaque); diff --git a/src/timers.c b/src/timers.c index d7467857..0bc84a73 100644 --- a/src/timers.c +++ b/src/timers.c @@ -70,10 +70,6 @@ static void uv__timer_cb(uv_timer_t *handle) { TJSTimer *th = handle->data; CHECK_NOT_NULL(th); - /* Timer always executes before check phase in libuv, - so clear the microtask queue here before running setTimeout macrotasks */ - tjs_execute_jobs(th->ctx); - call_timer(th); if (!th->interval) clear_timer(th); diff --git a/src/vm.c b/src/vm.c index 461f3e8e..7336aa8b 100644 --- a/src/vm.c +++ b/src/vm.c @@ -303,7 +303,7 @@ static void uv__prepare_cb(uv_prepare_t *handle) { uv__maybe_idle(qrt); } -void tjs_execute_jobs(JSContext *ctx) { +static void tjs__execute_jobs(JSContext *ctx) { JSContext *ctx1; int err; @@ -322,7 +322,7 @@ static void uv__check_cb(uv_check_t *handle) { TJSRuntime *qrt = handle->data; CHECK_NOT_NULL(qrt); - tjs_execute_jobs(qrt->ctx); + tjs__execute_jobs(qrt->ctx); uv__maybe_idle(qrt); } @@ -347,9 +347,11 @@ int TJS_Run(TJSRuntime *qrt) { if (ret != 0) return ret; - uv__maybe_idle(qrt); - - uv_run(&qrt->loop, UV_RUN_DEFAULT); + int r; + do { + uv__maybe_idle(qrt); + r = uv_run(&qrt->loop, UV_RUN_DEFAULT); + } while (r == 0 && JS_IsJobPending(qrt->rt)); JSValue exc = JS_GetException(qrt->ctx); if (!JS_IsNull(exc)) {