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
This commit is contained in:
Lars T Hansen 2019-02-18 17:44:34 +01:00
Родитель 0709795ffe
Коммит 5f15798c2e
2 изменённых файлов: 80 добавлений и 0 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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");