You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[js-api] A mutable global import allocates a const global before LinkError #2253
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 varGlobal 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 varGlobal. 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.
Activity
[js-api] Reject a mutable global import before allocating
[js-api] Reject a mutable global import before allocating