Skip to content

Commit

Permalink
Simplify exiting interpreter with exception
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Jan 6, 2025
1 parent ac4cd17 commit 6a0624a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ typedef struct JSThreadState {
struct list_head port_list; /* list of JSWorkerMessageHandler.link */
int eval_script_recurse; /* only used in the main thread */
int64_t next_timer_id; /* for setTimeout / setInterval */
JSValue exc; /* current exception from one of our handlers */
BOOL can_js_os_poll;
/* not used in the main thread */
JSWorkerMessagePipe *recv_pipe, *send_pipe;
Expand Down Expand Up @@ -2274,12 +2273,8 @@ static int call_handler(JSContext *ctx, JSValue func)
ret = JS_Call(ctx, func1, JS_UNDEFINED, 0, NULL);
JS_FreeValue(ctx, func1);
r = 0;
if (JS_IsException(ret)) {
JSRuntime *rt = JS_GetRuntime(ctx);
JSThreadState *ts = js_get_thread_state(rt);
ts->exc = JS_GetException(ctx);
if (JS_IsException(ret))
r = -1;
}
JS_FreeValue(ctx, ret);
return r;
}
Expand Down Expand Up @@ -4082,7 +4077,6 @@ void js_std_init_handlers(JSRuntime *rt)
init_list_head(&ts->port_list);

ts->next_timer_id = 1;
ts->exc = JS_UNDEFINED;

js_set_thread_state(rt, ts);
JS_AddRuntimeFinalizer(rt, js_std_finalize, ts);
Expand Down Expand Up @@ -4189,10 +4183,8 @@ JSValue js_std_loop(JSContext *ctx)
for(;;) {
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
if (err <= 0) {
if (err < 0) {
ts->exc = JS_GetException(ctx1);
if (err < 0)
goto done;
}
break;
}
}
Expand All @@ -4201,9 +4193,9 @@ JSValue js_std_loop(JSContext *ctx)
break;
}
done:
ret = ts->exc;
ts->exc = JS_UNDEFINED;
return ret;
if (JS_HasException(ctx))
return JS_GetException(ctx);
return JS_UNDEFINED;
}

/* Wait for a promise and execute pending jobs while waiting for
Expand Down

0 comments on commit 6a0624a

Please sign in to comment.