Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Context without the Promise intrinsic leaks async function bytecode and aborts in JS_FreeRuntime

Aperta
#1,762 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
backend, testing

Direzione di ricerca

Start in the runtime class registration and async-function creation paths described in the issue, then inspect the linked PR’s raw_context_async_function test in api-test.c. Reproduce the abort with a raw context that omits the Promise intrinsic and run the API tests. Done means the async-function bytecode is freed and JS_FreeRuntime exits cleanly without requiring the Promise intrinsic, or async syntax is rejected safely.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A context without the Promise intrinsic can still parse async function. The async function object then leaks its bytecode, and JS_FreeRuntime aborts.

Repro (current master, 2f0aa72)
#include "quickjs.h"

int main(void)
{
    JSRuntime *rt = JS_NewRuntime();
    JSContext *ctx = JS_NewContextRaw(rt);
    JS_AddIntrinsicBaseObjects(ctx);
    JS_AddIntrinsicEval(ctx);   // no JS_AddIntrinsicPromise
    const char src[] = "async function f() {}";
    JS_FreeValue(ctx, JS_Eval(ctx, src, sizeof(src) - 1, "<input>", JS_EVAL_TYPE_GLOBAL));
    JS_FreeContext(ctx);
    JS_FreeRuntime(rt);         // aborts here
    return 0;
}

Output:

quickjs.c:2699: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.

With JS_DUMP_LEAKS, the leaked object is a [function bytecode].

Why
  • The parser accepts async function in any context.
  • js_closure tags the function with JS_CLASS_ASYNC_FUNCTION.
  • That class, and the rest of js_async_class_def, is only registered by JS_AddIntrinsicPromise.
  • Without that intrinsic the class has no finalizer, so the function's bytecode is never freed.

Adding JS_AddIntrinsicPromise(ctx) makes the repro exit cleanly. bellard/quickjs is affected the same way.

Possible fixes
  1. Register js_async_class_def (and its .call hooks) in JS_NewRuntime, like js_std_class_def. We tested this: the repro and the whole api-test pass.
  2. Or reject async syntax at compile time when the Promise intrinsic is missing.

A failing test (raw_context_async_function in api-test.c) is in the linked PR. Happy to add either fix there.

We hit this in an embedder that builds minimal sandboxed contexts. Our workaround is to add the Promise intrinsic and then remove the globals.

Lingua principale
C
Stelle
3.9k
Fork
389
Merge medio
4g 1h
PR unite (30g)
24

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quickjs-ng/quickjs

Tutte le issue di quickjs-ng/quickjs

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.