From 041fb5dc02ba3c6e7df46f9f951dc415ff34bdaa Mon Sep 17 00:00:00 2001 From: Christoph Kaser Date: Tue, 28 Feb 2023 22:49:16 +0100 Subject: [PATCH] Fixed order of nextTick processing to match nodejs --- src/low_loop.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/low_loop.cpp b/src/low_loop.cpp index b1b0743..1baa83b 100644 --- a/src/low_loop.cpp +++ b/src/low_loop.cpp @@ -482,9 +482,16 @@ void low_loop_clear_callback(low_t *low, LowLoopCallback *callback) void low_call_next_tick(duk_context *ctx, int num_args) { low_t *low = duk_get_low_context(ctx); + // Push at the top of the stack - this probably is really slow, but it works duk_require_stack(low->next_tick_ctx, num_args + 2); - duk_xmove_top(low->next_tick_ctx, ctx, num_args + 1); duk_push_int(low->next_tick_ctx, num_args); + duk_insert(low->next_tick_ctx, 0); + + duk_xmove_top(low->next_tick_ctx, ctx, num_args + 1); + for (int i = 0; i < num_args + 1; i++) { + duk_insert(low->next_tick_ctx, 0); + } + }