Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#2,253 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
wasm
Domain
compilers

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
WebAssembly
Stars
3.5k
Forks
539
Avg merge
10h 24m
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/spec

All issues in WebAssembly/spec

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.