From 5f15798c2eaeeb7e4d91d51e3ae1b3d3bfe00f9c Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Mon, 18 Feb 2019 17:44:34 +0100 Subject: [PATCH] Bug 1507491 - WPTs for new WebAssembly.Table.prototype.grow. r=ms2ger Test cases for evolving JSAPI for the wasm reference types proposal: the grow() method on a table can now take a second argument. It can be null or an exported wasm function and it is used to initialize the new table slots. These tests are set apart from the regular test to make it clear that they are tentative. Once the reftypes proposal ships we should merge them into table/grow.any.js. Differential Revision: https://phabricator.services.mozilla.com/D20192 --HG-- extra : rebase_source : 22c722b567ed8bf6cb159232efbc6a2c04d22e1f extra : amend_source : 3d6de1ce9d5ee43dc0a108cace11bcf6dcefb9c5 --- .../table/grow-reftypes.tentative.any.js.ini | 38 +++++++++++++++++ .../table/grow-reftypes.tentative.any.js | 42 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 testing/web-platform/meta/wasm/jsapi/table/grow-reftypes.tentative.any.js.ini create mode 100644 testing/web-platform/tests/wasm/jsapi/table/grow-reftypes.tentative.any.js diff --git a/testing/web-platform/meta/wasm/jsapi/table/grow-reftypes.tentative.any.js.ini b/testing/web-platform/meta/wasm/jsapi/table/grow-reftypes.tentative.any.js.ini new file mode 100644 index 000000000000..88e5f6434aff --- /dev/null +++ b/testing/web-platform/meta/wasm/jsapi/table/grow-reftypes.tentative.any.js.ini @@ -0,0 +1,38 @@ +[grow.reftypes-tentative.any.js] + [Grow with exported-function argument] + expected: + if release_or_beta: FAIL + + [Grow with non-function argument] + expected: + if release_or_beta: FAIL + + [Grow with JS-function argument] + expected: + if release_or_beta: FAIL + +[grow.reftypes-tentative.any.html] + [Grow with exported-function argument] + expected: + if release_or_beta: FAIL + + [Grow with non-function argument] + expected: + if release_or_beta: FAIL + + [Grow with JS-function argument] + expected: + if release_or_beta: FAIL + +[grow.reftypes-tentative.any.worker.html] + [Grow with exported-function argument] + expected: + if release_or_beta: FAIL + + [Grow with non-function argument] + expected: + if release_or_beta: FAIL + + [Grow with JS-function argument] + expected: + if release_or_beta: FAIL diff --git a/testing/web-platform/tests/wasm/jsapi/table/grow-reftypes.tentative.any.js b/testing/web-platform/tests/wasm/jsapi/table/grow-reftypes.tentative.any.js new file mode 100644 index 000000000000..807aea991bbc --- /dev/null +++ b/testing/web-platform/tests/wasm/jsapi/table/grow-reftypes.tentative.any.js @@ -0,0 +1,42 @@ +// META: global=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([kExprEnd]) + .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(new TypeError(), () => table.grow(2, {})); +}, "Grow with non-function argument"); + +test(() => { + const argument = { "element": "anyfunc", "initial": 1 }; + const table = new WebAssembly.Table(argument); + assert_throws(new TypeError(), () => table.grow(2, () => true)); +}, "Grow with JS-function argument");