Bug 1253137 - Baldr: add explicit function body count (r=sunfish)
authorLuke Wagner <luke@mozilla.com>
Tue, 08 Mar 2016 13:15:29 -0600
changeset 287360 b2ec1e1d2fe9b0a064fa5a65b7e11aaaa775a744
parent 287359 8fa44c40bd003f82cfe1d199536c4256fdabc3c3
child 287361 bf186476cb90f713243dd1d1d195d25de53914aa
push id30068
push usercbook@mozilla.com
push dateWed, 09 Mar 2016 10:46:58 +0000
treeherdermozilla-central@af7c0cb0798f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1253137
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 1253137 - Baldr: add explicit function body count (r=sunfish) MozReview-Commit-ID: ISyUFSin5Jg
js/src/asmjs/Wasm.cpp
js/src/asmjs/WasmText.cpp
js/src/jit-test/tests/wasm/binary.js
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -1299,17 +1299,24 @@ DecodeFunctionBodies(JSContext* cx, Deco
 
     if (sectionStart == Decoder::NotStarted) {
         if (mg.numFuncSigs() != 0)
             return Fail(cx, d, "expected function bodies");
 
         return mg.finishFuncDefs();
     }
 
-    for (uint32_t funcIndex = 0; funcIndex < mg.numFuncSigs(); funcIndex++) {
+    uint32_t numFuncBodies;
+    if (!d.readVarU32(&numFuncBodies))
+        return Fail(cx, d, "expected function body count");
+
+    if (numFuncBodies != mg.numFuncSigs())
+        return Fail(cx, d, "function body count does not match function signature count");
+
+    for (uint32_t funcIndex = 0; funcIndex < numFuncBodies; funcIndex++) {
         if (!DecodeFunctionBody(cx, d, mg, funcIndex))
             return false;
     }
 
     if (!d.finishSection(sectionStart))
         return Fail(cx, d, "function section byte size mismatch");
 
     return mg.finishFuncDefs();
--- a/js/src/asmjs/WasmText.cpp
+++ b/js/src/asmjs/WasmText.cpp
@@ -3950,16 +3950,19 @@ EncodeFunctionBodies(Encoder& e, WasmAst
 {
     if (module.funcs().empty())
         return true;
 
     size_t offset;
     if (!e.startSection(FunctionBodiesId, &offset))
         return false;
 
+    if (!e.writeVarU32(module.funcs().length()))
+        return false;
+
     for (WasmAstFunc* func : module.funcs()) {
         if (!EncodeFunctionBody(e, *func))
             return false;
     }
 
     e.finishSection(offset);
     return true;
 }
--- a/js/src/jit-test/tests/wasm/binary.js
+++ b/js/src/jit-test/tests/wasm/binary.js
@@ -123,17 +123,17 @@ function funcBody(func) {
     for (let local of func.locals)
         body.push(...varU32(local));
     body = body.concat(...func.body);
     body.splice(0, 0, ...varU32(body.length));
     return body;
 }
 
 function bodySection(bodies) {
-    var body = [].concat(...bodies);
+    var body = varU32(bodies.length).concat(...bodies);
     return { name: functionBodiesId, body };
 }
 
 function importSection(imports) {
     var body = [];
     body.push(...varU32(imports.length));
     for (let imp of imports) {
         body.push(...varU32(imp.sigIndex));