From bed9ca3dd3e944f06a3f171fa532e32dfe8e7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Fri, 21 Jun 2024 15:02:18 +0200 Subject: [PATCH] Ensure `Bare.exit()` can be called in `idle` --- src/runtime.c | 4 +++- test/CMakeLists.txt | 1 + test/exit-on-idle.js | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/exit-on-idle.js diff --git a/src/runtime.c b/src/runtime.c index 1bfa9e21..ef4f90a1 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -1168,7 +1168,9 @@ bare_runtime_run (bare_runtime_t *runtime) { if (uv_loop_alive(runtime->loop)) continue; - uv_ref((uv_handle_t *) &runtime->signals.resume); + if (!runtime->terminated) { + uv_ref((uv_handle_t *) &runtime->signals.resume); + } } else { bare_runtime_on_before_exit(runtime); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a16c1a3c..b4c67456 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,7 @@ list(APPEND tests addon-resolve.js argv-empty.c exit-on-before-exit.js + exit-on-idle.js import-addon.cjs import-addon.mjs import-bundle.js diff --git a/test/exit-on-idle.js b/test/exit-on-idle.js new file mode 100644 index 00000000..85021c2e --- /dev/null +++ b/test/exit-on-idle.js @@ -0,0 +1,6 @@ +/* global Bare */ +Bare + .on('idle', () => { + Bare.exit() + }) + .suspend()