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

[js-api] A mutable global import allocates a const global before LinkError

Aperta
#2,253 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
wasm
Ambito
compilers

Direzione di ricerca

Start with the JS API “read the imports” algorithm and trace its interaction with module_instantiate and global_alloc; compare it with the old ExecuteModule path described in the issue. Done means mismatched mutable/const global imports throw LinkError before allocation, while successful fresh-value allocation uses the import mutability.

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

Descrizione

In read the imports, a global import ignores mut:

If externtype is of the form global mut valtype,
    If v implements Global,
        Let globaladdr be v.[[Global]].
    Otherwise,
        …
        Let (store, globaladdr) be global_alloc(store, const valtype, value).
        Set the surrounding agent's associated store to store.

module_instantiate still rejects a mismatch, so the link fails. The store update happens first.

  • A var import whose value is not a Global allocates a const global, then the type check fails. That global stays in the store and is not exposed to JavaScript.
  • A const import of a var Global reuses that global and fails the same check. Nothing new is allocated.

A number can only successfully import a const global, so the allocation on the var path is always discarded.

This showed up while sharing the reader with ESM integration (discussion). The old ExecuteModule path threw LinkError before allocation when mut was var and the value was not a Global, and when a const import was a var Global. Matching the JS API drops those checks.

Suggested change, before global_alloc:

  • If the value is not a Global and mut is var, throw a LinkError.
  • If the value is a Global, mut is const, and that global is var, throw a LinkError.
  • Otherwise allocate with the import's mut. For a fresh value that is only const.
Lingua principale
WebAssembly
Stelle
3.5k
Fork
539
Merge medio
10h 24m
PR unite (30g)
11

Preparare l'ambiente

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 WebAssembly/spec

Tutte le issue di WebAssembly/spec

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.