- Notifications
You must be signed in to change notification settings - Fork 204
Closed
Description
Original issue I posted here bellard/quickjs#341
Test Code
#include <gtest/gtest.h> #include <quickjs.h> #define MAX_VAL 100 static int timeout_interrupt_handler(JSRuntime *rt, void *opaque) { int *time = (int *)opaque; if (*time == MAX_VAL) { std::cout << "Timeout" << std::endl; } if (*time <= MAX_VAL) { *time += 1; } return *time > MAX_VAL; } TEST(QuickJS, timeout_interrupt) { const char *code = "(async function() { \ const loop = async () => { \ await Promise.resolve(); \ while (true) {} \ }; \ while (true) { \ await loop().catch(() => {}); \ } \ })();"; JSRuntime *rt = JS_NewRuntime(); JSContext *ctx = JS_NewContext(rt); int time = 0; JS_SetInterruptHandler(rt, timeout_interrupt_handler, &time); JSValue ret = JS_Eval(ctx, code, strlen(code), "<input>", JS_EVAL_TYPE_GLOBAL); EXPECT_FALSE(JS_IsException(ret)); JS_FreeValue(ctx, ret); EXPECT_TRUE(JS_IsJobPending(rt)); int r = 0; while (JS_IsJobPending(rt)) { r = JS_ExecutePendingJob(rt, &ctx); } EXPECT_GT(time, MAX_VAL); EXPECT_FALSE(JS_IsJobPending(rt)); EXPECT_EQ(r, -1); EXPECT_TRUE(JS_HasException(ctx)); JS_FreeContext(ctx); JS_FreeRuntime(rt); }
Expected
It should end when timeout occurs.
Actual
It never ends.
Metadata
Metadata
Assignees
Labels
No labels