aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-11-17 15:12:16 -0500
committerGitHub <noreply@github.com>2019-11-17 15:12:16 -0500
commitd1db623dfc918796ebdfd213f00690cead4cd91a (patch)
treeee7a23b376fe0eb3677db59af1e6c2cd1a14092a /tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js
parenta7008d1cf71c6bcdf49ce41d45178a413199c837 (diff)
parente6e440683de2c29d482c3009a398c8b34edec7d9 (diff)
downloadservo-d1db623dfc918796ebdfd213f00690cead4cd91a.tar.gz
servo-d1db623dfc918796ebdfd213f00690cead4cd91a.zip
Auto merge of #24761 - servo-wpt-sync:wpt_update_17-11-2019, r=jdm
Sync WPT with upstream (17-11-2019) Automated downstream sync of changes from upstream as of 17-11-2019. [no-wpt-sync] r? @servo-wpt-sync
Diffstat (limited to 'tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js')
-rw-r--r--tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js149
1 files changed, 149 insertions, 0 deletions
diff --git a/tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js b/tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js
new file mode 100644
index 00000000000..7fbac5b24f1
--- /dev/null
+++ b/tests/wpt/web-platform-tests/wasm/jsapi/constructor/multi-value.any.js
@@ -0,0 +1,149 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/assertions.js
+
+const type_if_fi = makeSig([kWasmF64, kWasmI32], [kWasmI32, kWasmF64]);
+
+promise_test(async () => {
+ const builder = new WasmModuleBuilder();
+
+ builder
+ .addFunction("swap", type_if_fi)
+ .addBody([
+ kExprGetLocal, 1,
+ kExprGetLocal, 0,
+ kExprReturn,
+ ])
+ .exportFunc();
+
+ const buffer = builder.toBuffer();
+
+ const result = await WebAssembly.instantiate(buffer);
+ const swapped = result.instance.exports.swap(4.2, 7);
+ assert_true(Array.isArray(swapped));
+ assert_equals(Object.getPrototypeOf(swapped), Array.prototype);
+ assert_array_equals(swapped, [7, 4.2]);
+}, "multiple return values from wasm to js");
+
+promise_test(async () => {
+ const builder = new WasmModuleBuilder();
+
+ const swap = builder
+ .addFunction("swap", type_if_fi)
+ .addBody([
+ kExprGetLocal, 1,
+ kExprGetLocal, 0,
+ kExprReturn,
+ ]);
+ builder
+ .addFunction("callswap", kSig_i_v)
+ .addBody([
+ ...wasmF64Const(4.2),
+ ...wasmI32Const(7),
+ kExprCallFunction, swap.index,
+ kExprDrop,
+ kExprReturn,
+ ])
+ .exportFunc();
+
+ const buffer = builder.toBuffer();
+
+ const result = await WebAssembly.instantiate(buffer);
+ const swapped = result.instance.exports.callswap();
+ assert_equals(swapped, 7);
+}, "multiple return values inside wasm");
+
+promise_test(async () => {
+ const builder = new WasmModuleBuilder();
+
+ const fnIndex = builder.addImport("module", "fn", type_if_fi);
+ builder
+ .addFunction("callfn", kSig_i_v)
+ .addBody([
+ ...wasmF64Const(4.2),
+ ...wasmI32Const(7),
+ kExprCallFunction, fnIndex,
+ kExprDrop,
+ kExprReturn,
+ ])
+ .exportFunc();
+
+ const buffer = builder.toBuffer();
+
+ const actual = [];
+ const imports = {
+ "module": {
+ fn(f32, i32) {
+ assert_equals(f32, 4.2);
+ assert_equals(i32, 7);
+ const result = [2, 7.3];
+ let i = 0;
+ return {
+ get [Symbol.iterator]() {
+ actual.push("@@iterator getter");
+ return function iterator() {
+ actual.push("@@iterator call");
+ return {
+ get next() {
+ actual.push("next getter");
+ return function next(...args) {
+ assert_array_equals(args, []);
+ let j = ++i;
+ actual.push(`next call ${j}`);
+ if (j > result.length) {
+ return {
+ get done() {
+ actual.push(`done call ${j}`);
+ return true;
+ }
+ };
+ }
+ return {
+ get done() {
+ actual.push(`done call ${j}`);
+ return false;
+ },
+ get value() {
+ actual.push(`value call ${j}`);
+ return {
+ get valueOf() {
+ actual.push(`valueOf get ${j}`);
+ return function() {
+ actual.push(`valueOf call ${j}`);
+ return result[j - 1];
+ };
+ }
+ };
+ }
+ };
+ };
+ }
+ };
+ }
+ },
+ };
+ },
+ }
+ };
+
+ const { instance } = await WebAssembly.instantiate(buffer, imports);
+ const result = instance.exports.callfn();
+ assert_equals(result, 2);
+ assert_array_equals(actual, [
+ "@@iterator getter",
+ "@@iterator call",
+ "next getter",
+ "next call 1",
+ "done call 1",
+ "value call 1",
+ "next call 2",
+ "done call 2",
+ "value call 2",
+ "next call 3",
+ "done call 3",
+ "valueOf get 1",
+ "valueOf call 1",
+ "valueOf get 2",
+ "valueOf call 2",
+ ]);
+}, "multiple return values from js to wasm");