Bug 1370926 - Fixes function name reference in start section in wast. r=sunfish
authorYury Delendik <ydelendik@mozilla.com>
Wed, 07 Jun 2017 10:32:17 -0500
changeset 410951 24861f3cb85f42d78c64f3f941ba6da02700d6dc
parent 410950 47ddea39b2a66e44e11233941e9afc5fd45a7732
child 410952 2135a8d8bed282a2982703828c503b334653ab2b
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1370926
milestone55.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 1370926 - Fixes function name reference in start section in wast. r=sunfish MozReview-Commit-ID: 52gymoBwomL
js/src/jit-test/tests/wasm/to-text.js
js/src/wasm/WasmBinaryToAST.cpp
js/src/wasm/WasmBinaryToText.cpp
--- a/js/src/jit-test/tests/wasm/to-text.js
+++ b/js/src/jit-test/tests/wasm/to-text.js
@@ -280,8 +280,14 @@ runTest(`(module
                     i32.const 2
                     i32.add
                     set_local $n
                 end
             end $c
         end $outer
     )
 )`);
+
+// Import as a start function.
+runTest(`(module
+    (import "env" "test" (func))
+    (start 0)
+)`);
--- a/js/src/wasm/WasmBinaryToAST.cpp
+++ b/js/src/wasm/WasmBinaryToAST.cpp
@@ -239,16 +239,28 @@ GenerateRef(AstDecodeContext& c, const A
     MOZ_ASSERT(!name.empty());
 
     *ref = AstRef(name);
     ref->setIndex(index);
     return true;
 }
 
 static bool
+GenerateFuncRef(AstDecodeContext& c, uint32_t funcIndex, AstRef* ref)
+{
+    if (funcIndex < c.module().numFuncImports()) {
+        *ref = AstRef(c.module().funcImportNames()[funcIndex]);
+    } else {
+        if (!GenerateRef(c, AstName(u"func"), funcIndex, ref))
+            return false;
+    }
+    return true;
+}
+
+static bool
 AstDecodeCallArgs(AstDecodeContext& c, const SigWithId& sig, AstExprVector* funcArgs)
 {
     MOZ_ASSERT(!c.iter().currentBlockHasPolymorphicBase());
 
     uint32_t numArgs = sig.args().length();
     if (!funcArgs->resize(numArgs))
         return false;
 
@@ -292,22 +304,18 @@ AstDecodeCall(AstDecodeContext& c)
     AstDecodeOpIter::ValueVector unusedArgs;
     if (!c.iter().readCall(&funcIndex, &unusedArgs))
         return false;
 
     if (c.iter().currentBlockHasPolymorphicBase())
         return true;
 
     AstRef funcRef;
-    if (funcIndex < c.module().numFuncImports()) {
-        funcRef = AstRef(c.module().funcImportNames()[funcIndex]);
-    } else {
-        if (!GenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
-            return false;
-    }
+    if (!GenerateFuncRef(c, funcIndex, &funcRef))
+        return false;
 
     const SigWithId* sig = c.env().funcSigs[funcIndex];
 
     AstExprVector args(c.lifo);
     if (!AstDecodeCallArgs(c, *sig, &args))
         return false;
 
     AstCall* call = new(c.lifo) AstCall(Op::Call, sig->ret(), funcRef, Move(args));
@@ -1707,17 +1715,17 @@ AstCreateExports(AstDecodeContext& c)
 
 static bool
 AstCreateStartFunc(AstDecodeContext &c)
 {
     if (!c.env().startFuncIndex)
         return true;
 
     AstRef funcRef;
-    if (!GenerateRef(c, AstName(u"func"), *c.env().startFuncIndex, &funcRef))
+    if (!GenerateFuncRef(c, *c.env().startFuncIndex, &funcRef))
         return false;
 
     c.module().setStartFunc(AstStartFunc(funcRef));
     return true;
 }
 
 static bool
 AstCreateElems(AstDecodeContext &c)
--- a/js/src/wasm/WasmBinaryToText.cpp
+++ b/js/src/wasm/WasmBinaryToText.cpp
@@ -1422,19 +1422,23 @@ RenderImport(WasmRenderContext& c, AstIm
     if (!RenderEscapedString(c, fieldName))
         return false;
 
     if (!c.buffer.append("\" "))
         return false;
 
     switch (import.kind()) {
       case DefinitionKind::Function: {
+        if (!c.buffer.append("(func"))
+            return false;
         const AstSig* sig = module.sigs()[import.funcSig().index()];
         if (!RenderSignature(c, *sig))
             return false;
+        if (!c.buffer.append(")"))
+            return false;
         break;
       }
       case DefinitionKind::Table: {
         if (!RenderResizableTable(c, import.limits()))
             return false;
         break;
       }
       case DefinitionKind::Memory: {