diff --git a/wasm/jsapi/table/constructor-reftypes.tentative.any.js b/wasm/jsapi/table/constructor-reftypes.tentative.any.js deleted file mode 100644 index 9bac1409f5a289..00000000000000 --- a/wasm/jsapi/table/constructor-reftypes.tentative.any.js +++ /dev/null @@ -1,48 +0,0 @@ -// META: global=window,dedicatedworker,jsshell -// META: script=assertions.js -// META: script=/wasm/jsapi/wasm-module-builder.js - -// Test cases for changes to the WebAssembly.Table constructor API that -// come in with the reftypes proposal: the API takes a default argument, which -// is used as an initializing value for the WebAssembly.Table. -// -// See: -// https://webassembly.github.io/reference-types/js-api/index.html#tables - -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"); diff --git a/wasm/jsapi/table/constructor.any.js b/wasm/jsapi/table/constructor.any.js index 794976e8266f9e..6acb4fc9d5d30c 100644 --- a/wasm/jsapi/table/constructor.any.js +++ b/wasm/jsapi/table/constructor.any.js @@ -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"); diff --git a/wasm/jsapi/table/get-set.any.js b/wasm/jsapi/table/get-set.any.js index 2e16346c6479ec..9301057a533ed4 100644 --- a/wasm/jsapi/table/get-set.any.js +++ b/wasm/jsapi/table/get-set.any.js @@ -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 => { @@ -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"); diff --git a/wasm/jsapi/table/grow-reftypes.tentative.any.js b/wasm/jsapi/table/grow-reftypes.tentative.any.js deleted file mode 100644 index 85dcbd1d00643a..00000000000000 --- a/wasm/jsapi/table/grow-reftypes.tentative.any.js +++ /dev/null @@ -1,42 +0,0 @@ -// META: global=window,dedicatedworker,jsshell -// META: script=assertions.js -// META: script=/wasm/jsapi/wasm-constants.js -// META: script=/wasm/jsapi/wasm-module-builder.js - -// Test cases for changes to the WebAssembly.Table.prototype.grow() API that -// come in with the reftypes proposal: the API takes a default argument, which -// for tables of anyfunc must be either an exported wasm function or null. -// -// See: -// https://github.com/WebAssembly/reference-types -// https://bugzilla.mozilla.org/show_bug.cgi?id=1507491 -// https://github.com/WebAssembly/reference-types/issues/22 - -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"); diff --git a/wasm/jsapi/table/grow.any.js b/wasm/jsapi/table/grow.any.js index 3b2ee5fa8ef66d..a1b19387377e8a 100644 --- a/wasm/jsapi/table/grow.any.js +++ b/wasm/jsapi/table/grow.any.js @@ -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"); diff --git a/wasm/jsapi/table/set-reftypes.tentative.any.js b/wasm/jsapi/table/set-reftypes.tentative.any.js deleted file mode 100644 index e9488d0d4fab68..00000000000000 --- a/wasm/jsapi/table/set-reftypes.tentative.any.js +++ /dev/null @@ -1,49 +0,0 @@ -// META: global=window,dedicatedworker,jsshell -// META: script=assertions.js -// META: script=/wasm/jsapi/wasm-module-builder.js - -// Test cases for changes to the WebAssembly.Table.prototype.set() API that -// come in with the reftypes proposal: the API makes the second argument optional and -// if it is missing we should use DefaultValue of the table's element type. -// -// See: -// https://webassembly.github.io/reference-types/js-api/index.html#tables - -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");