Skip to content

Commit

Permalink
Merge wasm reference types tests into the main tests.
Browse files Browse the repository at this point in the history
The proposal was merged in <WebAssembly/spec#1287>.
  • Loading branch information
Ms2ger committed Sep 15, 2021
1 parent 9b40f68 commit 0cc00d2
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 140 deletions.
48 changes: 0 additions & 48 deletions wasm/jsapi/table/constructor-reftypes.tentative.any.js

This file was deleted.

38 changes: 38 additions & 0 deletions 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 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");
42 changes: 0 additions & 42 deletions wasm/jsapi/table/grow-reftypes.tentative.any.js

This file was deleted.

29 changes: 29 additions & 0 deletions 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");
49 changes: 0 additions & 49 deletions wasm/jsapi/table/set-reftypes.tentative.any.js

This file was deleted.

0 comments on commit 0cc00d2

Please sign in to comment.