Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,12 @@ To <dfn>instantiate imported strings</dfn> with module |module| and |importedStr
1. Let |index| be the number of external functions in |imports|. This value |index| is known as the <dfn>index of the host function</dfn> |funcaddr|.
1. Let |externfunc| be the [=external value=] [=external value/func=] |funcaddr|.
1. [=list/Append=] |externfunc| to |imports|.
1. If |externtype| is of the form [=external-type/global=] <var ignore>mut</var> |valtype|,
1. If |externtype| is of the form [=external-type/global=] |mut| |valtype|,
1. If |v| [=implements=] {{Global}},
1. Let |globaladdr| be |v|.\[[Global]].
1. Otherwise,
1. If |mut| is [=mut=],
1. Throw a {{LinkError}} exception.
1. If |valtype| is [=i64=] and |v| [=is not a BigInt=],
1. Throw a {{LinkError}} exception.
1. If |valtype| is one of [=i32=], [=f32=] or [=f64=] and |v| [=is not a Number=],
Expand Down Expand Up @@ -552,8 +554,9 @@ To <dfn>instantiate imported strings</dfn> with module |module| and |importedStr
1. [=list/Append=] |externtag| to |imports|.
1. Return |imports|.

Note: This algorithm only verifies the right kind of JavaScript values are passed.
The verification of WebAssembly type requirements is deferred to the
Note: This algorithm verifies the right kind of JavaScript values are passed.
A value that does not [=implement=] {{Global}} can only initialize an immutable global.
The remaining WebAssembly type requirements are deferred to the
"[=instantiate the core of a WebAssembly module=]" algorithm.
</div>

Expand Down
12 changes: 12 additions & 0 deletions test/js-api/bad-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ function test_bad_imports(t) {
"global": global,
},
});

const mutableGlobal = new WebAssembly.Global({ "value": type, "mutable": true }, value);
t(`Importing an ${type} global with a mutable Global object`,
WebAssembly.LinkError,
builder => {
builder.addImportedGlobal("module", "global", value_type(type));
},
{
"module": {
"global": mutableGlobal,
},
});
}

const nonMemories = [
Expand Down
Loading