Skip to content

Commit

Permalink
Bug 1731288 [wpt PR 30805] - Merge wasm reference types tests into th…
Browse files Browse the repository at this point in the history
…e main tests., a=testonly

Automatic update from web-platform-tests
Merge wasm reference types tests into the main tests.

The proposal was merged in <WebAssembly/spec#1287>.

--

wpt-commits: d6752ceced9f95d19e317693d2ba902e9fc9cd35
wpt-pr: 30805
  • Loading branch information
Ms2ger authored and moz-wptsync-bot committed Oct 4, 2021
1 parent bbd0f30 commit 89c3982
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 140 deletions.

This file was deleted.

38 changes: 38 additions & 0 deletions testing/web-platform/tests/wasm/jsapi/table/constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,41 @@ test(() => {
"maximum valueOf",
]);
}, "Order of evaluation for descriptor");

test(() => {
const testObject = {};
const argument = { "element": "externref", "initial": 3 };
const table = new WebAssembly.Table(argument, testObject);
assert_equals(table.length, 3);
assert_equals(table.get(0), testObject);
assert_equals(table.get(1), testObject);
assert_equals(table.get(2), testObject);
}, "initialize externref table with default value");

test(() => {
const argument = { "element": "i32", "initial": 3 };
assert_throws_js(TypeError, () => new WebAssembly.Table(argument));
}, "initialize table with a wrong element value");

test(() => {
const builder = new WasmModuleBuilder();
builder
.addFunction("fn", kSig_v_v)
.addBody([])
.exportFunc();
const bin = builder.toBuffer();
const fn = new WebAssembly.Instance(new WebAssembly.Module(bin)).exports.fn;
const argument = { "element": "anyfunc", "initial": 3 };
const table = new WebAssembly.Table(argument, fn);
assert_equals(table.length, 3);
assert_equals(table.get(0), fn);
assert_equals(table.get(1), fn);
assert_equals(table.get(2), fn);
}, "initialize anyfunc table with default value");

test(() => {
const argument = { "element": "anyfunc", "initial": 3 };
assert_throws_js(TypeError, () => new WebAssembly.Table(argument, {}));
assert_throws_js(TypeError, () => new WebAssembly.Table(argument, "cannot be used as a wasm function"));
assert_throws_js(TypeError, () => new WebAssembly.Table(argument, 37));
}, "initialize anyfunc table with a bad default value");
40 changes: 39 additions & 1 deletion testing/web-platform/tests/wasm/jsapi/table/get-set.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ test(() => {
const argument = { "element": "anyfunc", "initial": 5 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.set());
assert_throws_js(TypeError, () => table.set(0));
}, "Missing arguments: set");

test(t => {
Expand Down Expand Up @@ -223,3 +222,42 @@ test(() => {
assert_equals(table.get(0, {}), null);
assert_equals(table.set(0, fn, {}), undefined);
}, "Stray argument");

test(() => {
const builder = new WasmModuleBuilder();
builder
.addFunction("fn", kSig_v_v)
.addBody([])
.exportFunc();
const bin = builder.toBuffer();
const fn = new WebAssembly.Instance(new WebAssembly.Module(bin)).exports.fn;

const argument = { "element": "anyfunc", "initial": 1 };
const table = new WebAssembly.Table(argument, fn);

assert_equals(table.get(0), fn);
table.set(0);
assert_equals(table.get(0), null);

table.set(0, fn);
assert_equals(table.get(0), fn);

assert_throws_js(TypeError, () => table.set(0, {}));
assert_throws_js(TypeError, () => table.set(0, 37));
}, "Arguments for anyfunc table set");

test(() => {
const testObject = {};
const argument = { "element": "externref", "initial": 1 };
const table = new WebAssembly.Table(argument, testObject);

assert_equals(table.get(0), testObject);
table.set(0);
assert_equals(table.get(0), undefined);

table.set(0, testObject);
assert_equals(table.get(0), testObject);

table.set(0, 37);
assert_equals(table.get(0), 37);
}, "Arguments for externref table set");

This file was deleted.

29 changes: 29 additions & 0 deletions testing/web-platform/tests/wasm/jsapi/table/grow.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ test(() => {
assert_equals(result, 5);
assert_equal_to_array(table, nulls(8), "after");
}, "Stray argument");

test(() => {
const builder = new WasmModuleBuilder();
builder
.addFunction("fn", kSig_v_v)
.addBody([])
.exportFunc();
const bin = builder.toBuffer()
const argument = { "element": "anyfunc", "initial": 1 };
const table = new WebAssembly.Table(argument);
const fn = new WebAssembly.Instance(new WebAssembly.Module(bin)).exports.fn;
const result = table.grow(2, fn);
assert_equals(result, 1);
assert_equals(table.get(0), null);
assert_equals(table.get(1), fn);
assert_equals(table.get(2), fn);
}, "Grow with exported-function argument");

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.grow(2, {}));
}, "Grow with non-function argument");

test(() => {
const argument = { "element": "anyfunc", "initial": 1 };
const table = new WebAssembly.Table(argument);
assert_throws_js(TypeError, () => table.grow(2, () => true));
}, "Grow with JS-function argument");

This file was deleted.

0 comments on commit 89c3982

Please sign in to comment.