@@ -161,7 +161,6 @@ typedef struct JSThreadState {
161161 struct list_head port_list ; /* list of JSWorkerMessageHandler.link */
162162 int eval_script_recurse ; /* only used in the main thread */
163163 int64_t next_timer_id ; /* for setTimeout / setInterval */
164- JSValue exc ; /* current exception from one of our handlers */
165164 BOOL can_js_os_poll ;
166165 /* not used in the main thread */
167166 JSWorkerMessagePipe * recv_pipe , * send_pipe ;
@@ -2274,12 +2273,8 @@ static int call_handler(JSContext *ctx, JSValue func)
22742273 ret = JS_Call (ctx , func1 , JS_UNDEFINED , 0 , NULL );
22752274 JS_FreeValue (ctx , func1 );
22762275 r = 0 ;
2277- if (JS_IsException (ret )) {
2278- JSRuntime * rt = JS_GetRuntime (ctx );
2279- JSThreadState * ts = js_get_thread_state (rt );
2280- ts -> exc = JS_GetException (ctx );
2276+ if (JS_IsException (ret ))
22812277 r = -1 ;
2282- }
22832278 JS_FreeValue (ctx , ret );
22842279 return r ;
22852280}
@@ -3543,10 +3538,10 @@ static void *worker_func(void *opaque)
35433538 js_std_dump_error (ctx );
35443539 JS_FreeValue (ctx , val );
35453540
3546- JS_FreeValue ( ctx , js_std_loop (ctx ) );
3541+ js_std_loop (ctx );
35473542
3548- JS_FreeContext (ctx );
35493543 js_std_free_handlers (rt );
3544+ JS_FreeContext (ctx );
35503545 JS_FreeRuntime (rt );
35513546 return NULL ;
35523547}
@@ -4082,7 +4077,6 @@ void js_std_init_handlers(JSRuntime *rt)
40824077 init_list_head (& ts -> port_list );
40834078
40844079 ts -> next_timer_id = 1 ;
4085- ts -> exc = JS_UNDEFINED ;
40864080
40874081 js_set_thread_state (rt , ts );
40884082 JS_AddRuntimeFinalizer (rt , js_std_finalize , ts );
@@ -4140,7 +4134,7 @@ static void js_dump_obj(JSContext *ctx, FILE *f, JSValue val)
41404134 }
41414135}
41424136
4143- void js_std_dump_error1 (JSContext * ctx , JSValue exception_val )
4137+ static void js_std_dump_error1 (JSContext * ctx , JSValue exception_val )
41444138{
41454139 JSValue val ;
41464140 BOOL is_error ;
@@ -4178,23 +4172,20 @@ void js_std_promise_rejection_tracker(JSContext *ctx, JSValue promise,
41784172}
41794173
41804174/* main loop which calls the user JS callbacks */
4181- JSValue js_std_loop (JSContext * ctx )
4175+ int js_std_loop (JSContext * ctx )
41824176{
41834177 JSRuntime * rt = JS_GetRuntime (ctx );
41844178 JSThreadState * ts = js_get_thread_state (rt );
41854179 JSContext * ctx1 ;
4186- JSValue ret ;
41874180 int err ;
41884181
41894182 for (;;) {
41904183 /* execute the pending jobs */
41914184 for (;;) {
41924185 err = JS_ExecutePendingJob (JS_GetRuntime (ctx ), & ctx1 );
41934186 if (err <= 0 ) {
4194- if (err < 0 ) {
4195- ts -> exc = JS_GetException (ctx1 );
4187+ if (err < 0 )
41964188 goto done ;
4197- }
41984189 break ;
41994190 }
42004191 }
@@ -4203,9 +4194,7 @@ JSValue js_std_loop(JSContext *ctx)
42034194 break ;
42044195 }
42054196done :
4206- ret = ts -> exc ;
4207- ts -> exc = JS_UNDEFINED ;
4208- return ret ;
4197+ return JS_HasException (ctx );
42094198}
42104199
42114200/* Wait for a promise and execute pending jobs while waiting for
0 commit comments