Bug 1640845 - change strictness of i64 global import to match the spec tests r=lth
authorAsumu Takikawa <asumu@igalia.com>
Wed, 27 May 2020 08:57:25 +0000
changeset 532343 3406d70ecc4e9ea9b6b38d01da537bee0b2babaa
parent 532342 db9a979064b76dc219f1f8cfb48fb5085b3cbcd9
child 532344 1caff03435d24141061d029f0b0acd8f93b5c759
push id37454
push userccoroiu@mozilla.com
push dateWed, 27 May 2020 16:14:31 +0000
treeherdermozilla-central@a1dd9afbfdf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1640845
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640845 - change strictness of i64 global import to match the spec tests r=lth The JS-API spec for BigInt/I64 conversion requires more strict checking for reading imports that are i64s. This revision implements that behavior to match the spec and the spec tests. Differential Revision: https://phabricator.services.mozilla.com/D76912
js/src/jit-test/tests/wasm/bigint/bigint.js
js/src/wasm/WasmJS.cpp
--- a/js/src/jit-test/tests/wasm/bigint/bigint.js
+++ b/js/src/jit-test/tests/wasm/bigint/bigint.js
@@ -261,23 +261,23 @@ function testGlobalImport() {
       (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))
     )`,
-    { g: { a: 1n, b: 2n ** 63n, c: "123" } }
+    { g: { a: 1n, b: 2n ** 63n, c: -100n } }
   ).exports;
 
   testWithJit(() => {
     assertEq(exports.a.value, 1n);
     assertEq(exports.b.value, -(2n ** 63n));
-    assertEq(exports.c.value, 123n);
+    assertEq(exports.c.value, -100n);
   });
 }
 
 function testMutableGlobalImport() {
   var exports = wasmEvalText(
     `(module
       (import "g" "a" (global $a (mut i64)))
       (import "g" "b" (global $b (mut i64)))
@@ -331,18 +331,18 @@ function testGlobalBadImportLiteral() {
     () =>
       wasmEvalText(
         `(module
           (import "g" "a" (global $a i64))
           (export "a" (global $a))
         )`,
         { g: { a: "foo" } }
       ),
-    SyntaxError,
-    "invalid BigInt syntax"
+    WebAssembly.LinkError,
+    "import object field 'a' is not a BigInt"
   );
 }
 
 // This exercises error code paths that were added due to BigInt/I64
 // conversion, though the test does not directly deal with I64 types.
 function testGlobalBadImportNumber() {
   assertErrorMessage(
     () =>
--- a/js/src/wasm/WasmJS.cpp
+++ b/js/src/wasm/WasmJS.cpp
@@ -543,17 +543,17 @@ bool js::wasm::GetImports(JSContext* cx,
               !imports->globalObjs.resize(index + 1)) {
             ReportOutOfMemory(cx);
             return false;
           }
           imports->globalObjs[index] = obj;
           obj->val(&val);
         } else {
           if (IsNumberType(global.type())) {
-            if (global.type() == ValType::I64 && v.isNumber()) {
+            if (global.type() == ValType::I64 && !v.isBigInt()) {
               return ThrowBadImportType(cx, import.field.get(), "BigInt");
             }
             if (global.type() != ValType::I64 && !v.isNumber()) {
               return ThrowBadImportType(cx, import.field.get(), "Number");
             }
           } else {
             MOZ_ASSERT(global.type().isReference());
             if (!global.type().isAnyRef() && !v.isObjectOrNull()) {