Bug 1511958 - part 6, add tests for Wasm BigInt<->I64 globals draft
authorAsumu Takikawa <asumu@igalia.com>
Thu, 05 Dec 2019 02:52:31 +0000
changeset 2517410 c80776569aec872ba4e74ae76b2f511e9497bce5
parent 2517409 1d3d9411ba9be1cff5ee11b117b10676b796357b
child 2517411 1b2d78f9463f0810df77b8f0df0342bd2ecbb362
push id460517
push userreviewbot
push dateThu, 05 Dec 2019 02:52:52 +0000
treeherdertry@1b2d78f9463f [default view] [failures only]
bugs1511958
milestone73.0a1
Bug 1511958 - part 6, add tests for Wasm BigInt<->I64 globals This adds tests for manipulating globals with I64 values with the Wasm to JS interface. Differential Diff: PHID-DIFF-6q34dhqubkd2fdcatpvo
js/src/jit-test/tests/wasm/bigint/bigint.js
--- a/js/src/jit-test/tests/wasm/bigint/bigint.js
+++ b/js/src/jit-test/tests/wasm/bigint/bigint.js
@@ -174,15 +174,147 @@ function testMixedArgs() {
     )
   )`).exports.f;
 
   testWithJit(() => {
     assertEq(f(1n, 1.3, 1.7, 1, 1n), 5n);
   });
 }
 
+function testGlobalImport() {
+  var imports = {
+    g: {
+      a: 1n,
+      b: 2n ** 63n,
+      c: "123",
+    }
+  };
+
+  var exports = wasmEvalText(`(module
+    (import "g" "a" (global $a i64))
+    (import "g" "b" (global $b i64))
+    (import "g" "c" (global $c i64))
+
+    (export "a" (global $a))
+    (export "b" (global $b))
+    (export "c" (global $c))
+  )`, imports).exports;
+
+  testWithJit(() => {
+    assertEq(exports.a.value, 1n);
+    assertEq(exports.b.value, - (2n ** 63n));
+    assertEq(exports.c.value, 123n);
+  });
+}
+
+function testMutableGlobalImport() {
+  var imports = {
+    g: {
+      a: new WebAssembly.Global({ value: "i64", mutable: true }, 1n),
+      b: new WebAssembly.Global({ value: "i64", mutable: true }, "2"),
+    }
+  };
+
+  var exports = wasmEvalText(`(module
+    (import "g" "a" (global $a (mut i64)))
+    (import "g" "b" (global $b (mut i64)))
+
+    (export "a" (global $a))
+    (export "b" (global $b))
+  )`, imports).exports;
+
+  testWithJit(() => {
+    assertEq(exports.a.value, 1n);
+    assertEq(exports.b.value, 2n);
+  });
+}
+
+function testMutableGlobalImportLiteral() {
+  var imports = {
+    g: { a: 1n }
+  };
+
+  try {
+    wasmEvalText(`(module
+      (import "g" "a" (global $a (mut i64)))
+    )`, imports);
+  } catch(e) {
+    assertEq(e instanceof WebAssembly.LinkError, true);
+    assertEq(e.message, "imported global mutability mismatch");
+  }
+}
+
+function testGlobalBadImportLiteral() {
+  var imports = {
+    g: { a: 1 }
+  };
+
+  try {
+    wasmEvalText(`(module
+      (import "g" "a" (global $a i64))
+      (export "a" (global $a))
+    )`, imports);
+  } catch (e) {
+    assertEq(e instanceof WebAssembly.LinkError, true);
+    assertEq(e.message, "import object field 'a' is not a BigInt");
+  }
+}
+
+
+function testI64Global() {
+  var argument = { "value": "i64", "mutable": true };
+  var global = new WebAssembly.Global(argument);
+
+  assertEq(global.value, 0n); // initial value
+
+  global.value = 123n;
+  assertEq(global.value, 123n);
+
+  global.value = 2n ** 63n;
+  assertEq(global.value, - (2n ** 63n));
+}
+
+function testI64GlobalValueOf() {
+  var argument = { "value": "i64" };
+
+  // as literal
+  var global = new WebAssembly.Global(argument, {
+    valueOf() {
+      return 123n;
+    }
+  });
+  assertEq(global.value, 123n);
+
+  // as string
+  var global2 = new WebAssembly.Global(argument, {
+    valueOf() {
+      return "123";
+    }
+  });
+  assertEq(global.value, 123n);
+}
+
+function testGlobalI64ValueWrongType() {
+  var argument = { "value": "i64" };
+  assertThrowsInstanceOf(() => new WebAssembly.Global(argument, 666), TypeError);
+}
+
+function testGlobalI64SetWrongType() {
+  var argument = { "value": "i64", "mutable": true };
+  var global = new WebAssembly.Global(argument);
+  assertThrowsInstanceOf(() => global.value = 1, TypeError);
+}
+
 testRet();
 testRetPlus();
 testId();
 testIdPlus();
 testManyArgs();
 testImportExport();
 testMixedArgs();
+testGlobalImport();
+testMutableGlobalImport();
+testMutableGlobalImportLiteral();
+testGlobalBadImportLiteral();
+testI64Global();
+testI64GlobalValueOf();
+testGlobalI64ValueWrongType();
+testGlobalI64SetWrongType();