Bug 1317319: Tweak AstDecodeFunctionBody; r=luke
authorBenjamin Bouvier <benj@benj.me>
Wed, 16 Nov 2016 17:47:57 +0100
changeset 323083 eb0e39566b63239abd2b71cba08c5775e48ac1fd
parent 323082 954af429f89cf4e21398fdb30f3062c393baa84c
child 323084 5e51ba71c958fbec2b6774c2d39e22d9e3f9c5fb
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersluke
bugs1317319
milestone53.0a1
Bug 1317319: Tweak AstDecodeFunctionBody; r=luke MozReview-Commit-ID: 1L4vvX2hZVw
js/src/wasm/WasmBinaryToAST.cpp
--- a/js/src/wasm/WasmBinaryToAST.cpp
+++ b/js/src/wasm/WasmBinaryToAST.cpp
@@ -1410,38 +1410,37 @@ AstDecodeExpr(AstDecodeContext& c)
 
     AstExpr* lastExpr = c.top().expr;
     if (lastExpr)
         lastExpr->setOffset(exprOffset);
     return true;
 }
 
 static bool
-AstDecodeFunctionBody(AstDecodeContext &c, uint32_t funcDefIndex, AstFunc** func)
+AstDecodeFunctionBody(AstDecodeContext &c, uint32_t funcIndex, AstFunc** func)
 {
     uint32_t offset = c.d.currentOffset();
     uint32_t bodySize;
     if (!c.d.readVarU32(&bodySize))
         return c.d.fail("expected number of function body bytes");
 
     if (c.d.bytesRemain() < bodySize)
         return c.d.fail("function body length too big");
 
     const uint8_t* bodyBegin = c.d.currentPosition();
     const uint8_t* bodyEnd = bodyBegin + bodySize;
 
-    size_t funcIndex = c.module().numFuncImports() + funcDefIndex;
     const SigWithId* sig = c.funcSigs()[funcIndex];
 
     ValTypeVector locals;
     if (!locals.appendAll(sig->args()))
         return false;
 
     if (!DecodeLocalEntries(c.d, ModuleKind::Wasm, &locals))
-        return c.d.fail("failed decoding local entries");
+        return false;
 
     AstDecodeOpIter iter(c.d);
     c.startFunction(&iter, &locals, sig->ret());
 
     AstName funcName;
     if (!GenerateName(c, AstName(u"func"), funcIndex, &funcName))
         return false;
 
@@ -1810,29 +1809,29 @@ AstDecodeCodeSection(AstDecodeContext &c
     uint32_t sectionStart, sectionSize;
     if (!c.d.startSection(SectionId::Code, &sectionStart, &sectionSize, "code"))
         return false;
 
     if (sectionStart == Decoder::NotStarted) {
         if (c.numFuncDefs() != 0)
             return c.d.fail("expected function bodies");
 
-        return false;
+        return true;
     }
 
     uint32_t numFuncBodies;
     if (!c.d.readVarU32(&numFuncBodies))
         return c.d.fail("expected function body count");
 
     if (numFuncBodies != c.numFuncDefs())
         return c.d.fail("function body count does not match function signature count");
 
     for (uint32_t funcDefIndex = 0; funcDefIndex < numFuncBodies; funcDefIndex++) {
         AstFunc* func;
-        if (!AstDecodeFunctionBody(c, funcDefIndex, &func))
+        if (!AstDecodeFunctionBody(c, c.module().numFuncImports() + funcDefIndex, &func))
             return false;
         if (!c.module().append(func))
             return false;
     }
 
     if (!c.d.finishSection(sectionStart, sectionSize, "code"))
         return false;