fixed GC logic so that a module can live after a JSContext is destroyed (#280) - update the reference count for the realm in jobs and FinalizationRegistry

This commit is contained in:
Fabrice Bellard
2025-06-28 17:41:58 +02:00
parent 2fd48bf7df
commit 458c34d29d
3 changed files with 96 additions and 61 deletions

View File

@@ -4230,17 +4230,15 @@ static void js_std_promise_rejection_check(JSContext *ctx)
/* main loop which calls the user JS callbacks */
void js_std_loop(JSContext *ctx)
{
JSContext *ctx1;
int err;
for(;;) {
/* execute the pending jobs */
for(;;) {
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (err <= 0) {
if (err < 0) {
js_std_dump_error(ctx1);
}
if (err < 0)
js_std_dump_error(ctx);
break;
}
}
@@ -4271,11 +4269,10 @@ JSValue js_std_await(JSContext *ctx, JSValue obj)
JS_FreeValue(ctx, obj);
break;
} else if (state == JS_PROMISE_PENDING) {
JSContext *ctx1;
int err;
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (err < 0) {
js_std_dump_error(ctx1);
js_std_dump_error(ctx);
}
if (err == 0) {
js_std_promise_rejection_check(ctx);