Bug 1248598 part 2 - Reject wasm i64 imports/exports as JS doesn't have an int64 type. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 20 Feb 2016 14:45:34 +0100
changeset 284933 eae4090bb9c70eee9fcff602f8ee07b8839daf9e
parent 284932 443a0e2860320b03d84d8ffc13c8791de33c34e3
child 284934 7bfe45ec123a47d227147967748ef72a36a378ac
push id30015
push userphilringnalda@gmail.com
push dateSun, 21 Feb 2016 01:23:31 +0000
treeherdermozilla-central@7bfe45ec123a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1248598
milestone47.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 1248598 part 2 - Reject wasm i64 imports/exports as JS doesn't have an int64 type. r=luke
js/src/asmjs/Wasm.cpp
js/src/jit-test/tests/wasm/basic.js
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -842,25 +842,42 @@ DecodeTableSection(JSContext* cx, Decode
         uint32_t funcIndex = elems[elemIndex];
         init->sigToTable[init->funcSigIndex(funcIndex)].elemFuncIndices[elemIndex] = funcIndex;
     }
 
     return true;
 }
 
 static bool
+CheckTypeForJS(JSContext* cx, Decoder& d, const Sig& sig)
+{
+    for (ValType argType : sig.args()) {
+        if (argType == ValType::I64)
+            return Fail(cx, d, "cannot import/export i64 argument");
+    }
+
+    if (sig.ret() == ExprType::I64)
+        return Fail(cx, d, "cannot import/export i64 return type");
+
+    return true;
+}
+
+static bool
 DecodeImport(JSContext* cx, Decoder& d, ModuleGeneratorData* init, ImportNameVector* importNames)
 {
     const DeclaredSig* sig;
     if (!DecodeSignatureIndex(cx, d, *init, &sig))
         return false;
 
     if (!init->imports.emplaceBack(sig))
         return false;
 
+    if (!CheckTypeForJS(cx, d, *sig))
+        return false;
+
     UniqueChars moduleName = d.readCString();
     if (!moduleName)
         return Fail(cx, d, "expected import module name");
 
     if (!*moduleName.get())
         return Fail(cx, d, "module name cannot be empty");
 
     UniqueChars funcName = d.readCString();
@@ -964,16 +981,19 @@ DecodeFunctionExport(JSContext* cx, Deco
 {
     uint32_t funcIndex;
     if (!d.readVarU32(&funcIndex))
         return Fail(cx, d, "expected export internal index");
 
     if (funcIndex >= mg.numFuncSigs())
         return Fail(cx, d, "export function index out of range");
 
+    if (!CheckTypeForJS(cx, d, mg.funcSig(funcIndex)))
+        return false;
+
     UniqueChars fieldName = DecodeFieldName(cx, d, dupSet);
     if (!fieldName)
         return false;
 
     return mg.declareExport(Move(fieldName), funcIndex);
 }
 
 static bool
--- a/js/src/jit-test/tests/wasm/basic.js
+++ b/js/src/jit-test/tests/wasm/basic.js
@@ -343,16 +343,25 @@ assertErrorMessage(() => i2v(4), Error, 
 assertErrorMessage(() => i2v(5), Error, /wasm indirect call signature mismatch/);
 
 for (bad of [6, 7, 100, Math.pow(2,31)-1, Math.pow(2,31), Math.pow(2,31)+1, Math.pow(2,32)-2, Math.pow(2,32)-1]) {
     assertThrowsInstanceOf(() => v2i(bad), RangeError);
     assertThrowsInstanceOf(() => i2i(bad, 0), RangeError);
     assertThrowsInstanceOf(() => i2v(bad, 0), RangeError);
 }
 
+// When the test below starts failing, remove it and uncomment the lines below!
+assertErrorMessage(() => wasmEvalText('(module (func (param i64)))'), TypeError, /NYI/);
+/*
+assertErrorMessage(() => wasmEvalText('(module (func (param i64) (result i32) (i32.const 123)) (export "" 0))'), TypeError, /i64 argument/);
+assertErrorMessage(() => wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" 0))'), TypeError, /i64 return type/);
+assertErrorMessage(() => wasmEvalText('(module (import "a" "" (param i64) (result i32)))'), TypeError, /i64 argument/);
+assertErrorMessage(() => wasmEvalText('(module (import "a" "" (result i64)))'), TypeError, /i64 return type/);
+*/
+
 
 var {v2i, i2i, i2v} = wasmEvalText(`(module
     (type $a (func (result i32)))
     (type $b (func (param i32) (result i32)))
     (type $c (func (param i32)))
     (func $a (type $a) (i32.const 13))
     (func $b (type $a) (i32.const 42))
     (func $c (type $b) (i32.add (get_local 0) (i32.const 1)))