Repository navigation
[js-api] Reject a mutable global import before allocating - #2263
chicoxyzzy wants to merge 2 commits into
Conversation
guybedford
left a comment
There was a problem hiding this comment.
Why not also include the case of instantiating a mutable global with an immutable one here? Is there a reason to only support the one direction?
guybedford
left a comment
There was a problem hiding this comment.
Hmm, actually of course most type validations are left for later, but then the converse point would be -
Rather, why do we need to verify that we are not instantiating an immutable global with a mutable global object here - what makes that case special that it can't also be a deferred validation?
If we removed that, the diff here would drop all the inner |mut| checking for implements Global.
|
A The The allocation is the other branch: the value does not implement I'll remove the |
guybedford
left a comment
There was a problem hiding this comment.
While not a bug or major correctness issue, the risk of this is relatively low, and it ensures better hygiene by avoiding an unnecessary global store.
Formally, making the LinkError earlier for this case is an error ordering change, but we don't see strict error ordering in implementations currently anyway - for example, V8 doesn't respect error ordering per the spec (Get's enumerate first in a batch instead of interleaving validation).
LGTM
24b9ae6 to
0902790
Compare
Fixes WebAssembly#2253. A non-Global value for a var import was passed to global_alloc as a const global. module_instantiate then rejected the mutability mismatch and left that global in the store. Throw a LinkError before allocating. A const import of a var Global is the same mismatch. Throw before appending that global. A fresh global is allocated with the import's mut, which is const once the var case has been rejected.
read the imports does not call global_type. A const import of a var Global allocates nothing, and module_instantiate already rejects both mutability mismatches. The LinkError before global_alloc stays when a var import's value is not a Global.
0902790 to
2d1268d
Compare
|
rebased onto main |
Fixes #2253.
read the importsignoredmutand always calledglobal_allocwithconst valtypewhen the value was not aGlobal. Avarimport then failed inmodule_instantiate, and theconstglobal stayed in the store.Throw a
LinkErrorin that case before allocating. Allocate a fresh global with the import'smut. After that rejection,mutisconst.A
Globalis passed through. Mutability mismatches stay inmodule_instantiate, including aconstimport of avarGlobaland avarimport of aconstGlobal.The new test covers a
constimport of a mutableGlobalfori32,i64,f32, andf64. Instantiation still throwsLinkError.