Skip to content
Merged
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
26 changes: 25 additions & 1 deletion test/js-api/global/constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,29 @@ test(() => {

test(() => {
const argument = { "value": "v128" };
assert_throws_js(TypeError, () =>new WebAssembly.Global(argument));
assert_throws_js(TypeError, () => new WebAssembly.Global(argument));
}, "Construct v128 global");

test(() => {
for (let value of [
undefined,
null,
true,
1,
-0,
1.5,
-2n,
Symbol("test"),
"string",
{"an": "object"},
() => null
]) {
let global = new WebAssembly.Global({value: "externref"}, value);
assert_Global(global, value);
}
}, "externref global");
Comment on lines +185 to +190
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case isn't testing the constructor, which is what this file is for. I believe there's a file for the value getter/setter nearby

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. After checking how I missed that, I realized that I missed one "include" in my invocation for this file and that script was reponsible for actually executing the test cases. (It isn't very obvious to me how to run these scripts in e.g. d8.)

I addressed this issue now by splitting it up into testing the constructor and a separate test case for get-set.


test(() => {
let global = new WebAssembly.Global({value: "externref"});
assert_Global(global, undefined);
}, "externref global with default value");
21 changes: 21 additions & 0 deletions test/js-api/global/value-get-set.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,24 @@ test(() => {
assert_equals(setter.call(global, 1, {}), undefined);
assert_equals(global.value, 1);
}, "Stray argument");

test(() => {
let global = new WebAssembly.Global({value: "externref", mutable: true});
for (let value of [
undefined,
null,
true,
1,
-0,
1.5,
-2n,
Symbol("test"),
"string",
{"an": "object"},
() => null
]) {
global.value = value;
assert_equals(global.value, value);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also #1984 (comment), this tests -0 as one of its inputs. assert_equals already treats 0 and -0 as different values:

assert_equals: expected -0 but got 0

Let me know if this is fine given that the current spec text isn't very precise.

assert_equals(global.valueOf(), value);
}
}, "externref global");