Bug 1263205 - BaldrMonkey: Update for proposed new section names (r=luke)
authorDan Gohman <sunfish@mozilla.com>
Thu, 28 Apr 2016 10:36:28 -0500
changeset 357633 ec70afdb3fa85b4af5ea887b4149fb70e96fb852
parent 357632 f9942b8651f4c1b1496f79aa666bf1466b668853
child 357634 d01f4f50db3753575a9a094aa28c2e43ab87a742
push id16816
push userbmo:gasolin@mozilla.com
push dateFri, 29 Apr 2016 03:33:20 +0000
reviewersluke
bugs1263205
milestone49.0a1
Bug 1263205 - BaldrMonkey: Update for proposed new section names (r=luke) * * * Bug 1263205 - BaldrMonkey: Add 'form' field to types section (r=bbouvier) MozReview-Commit-ID: fC8KB7ez76
js/src/asmjs/Wasm.cpp
js/src/asmjs/WasmBinary.h
js/src/asmjs/WasmBinaryToText.cpp
js/src/asmjs/WasmTextToBinary.cpp
js/src/jit-test/tests/wasm/binary.js
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -514,20 +514,20 @@ DecodeExpr(FunctionDecoder& f)
 }
 
 /*****************************************************************************/
 // wasm decoding and generation
 
 typedef HashSet<const DeclaredSig*, SigHashPolicy> SigSet;
 
 static bool
-DecodeSignatures(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
+DecodeTypeSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(SignaturesId, &sectionStart, &sectionSize))
+    if (!d.startSection(TypeSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numSigs;
     if (!d.readVarU32(&numSigs))
         return Fail(cx, d, "expected number of signatures");
 
@@ -597,20 +597,20 @@ DecodeSignatureIndex(JSContext* cx, Deco
     if (sigIndex >= init.sigs.length())
         return Fail(cx, d, "signature index out of range");
 
     *sig = &init.sigs[sigIndex];
     return true;
 }
 
 static bool
-DecodeFunctionSignatures(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
+DecodeFunctionSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(FunctionSignaturesId, &sectionStart, &sectionSize))
+    if (!d.startSection(FunctionSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numDecls;
     if (!d.readVarU32(&numDecls))
         return Fail(cx, d, "expected number of declarations");
 
@@ -627,20 +627,20 @@ DecodeFunctionSignatures(JSContext* cx, 
 
     if (!d.finishSection(sectionStart, sectionSize))
         return Fail(cx, d, "decls section byte size mismatch");
 
     return true;
 }
 
 static bool
-DecodeFunctionTable(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
+DecodeTableSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(FunctionTableId, &sectionStart, &sectionSize))
+    if (!d.startSection(TableSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     if (!d.readVarU32(&init->numTableElems))
         return Fail(cx, d, "expected number of table elems");
 
     if (init->numTableElems > MaxTableElems)
@@ -748,20 +748,20 @@ DecodeImport(JSContext* cx, Decoder& d, 
     Bytes funcName;
     if (!d.readBytes(&funcName))
         return Fail(cx, d, "expected import func name");
 
     return importNames->emplaceBack(Move(moduleName), Move(funcName));
 }
 
 static bool
-DecodeImportTable(JSContext* cx, Decoder& d, ModuleGeneratorData* init, ImportNameVector* importNames)
+DecodeImportSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init, ImportNameVector* importNames)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(ImportTableId, &sectionStart, &sectionSize))
+    if (!d.startSection(ImportSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numImports;
     if (!d.readVarU32(&numImports))
         return Fail(cx, d, "failed to read number of imports");
 
@@ -775,20 +775,20 @@ DecodeImportTable(JSContext* cx, Decoder
 
     if (!d.finishSection(sectionStart, sectionSize))
         return Fail(cx, d, "import section byte size mismatch");
 
     return true;
 }
 
 static bool
-DecodeMemory(JSContext* cx, Decoder& d, ModuleGenerator& mg, MutableHandle<ArrayBufferObject*> heap)
+DecodeMemorySection(JSContext* cx, Decoder& d, ModuleGenerator& mg, MutableHandle<ArrayBufferObject*> heap)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(MemoryId, &sectionStart, &sectionSize))
+    if (!d.startSection(MemorySectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t initialSizePages;
     if (!d.readVarU32(&initialSizePages))
         return Fail(cx, d, "expected initial memory size");
 
@@ -879,20 +879,20 @@ DecodeFunctionExport(JSContext* cx, Deco
     UniqueChars fieldName = DecodeExportName(cx, d, dupSet);
     if (!fieldName)
         return false;
 
     return mg.declareExport(Move(fieldName), funcIndex);
 }
 
 static bool
-DecodeExportTable(JSContext* cx, Decoder& d, ModuleGenerator& mg)
+DecodeExportSection(JSContext* cx, Decoder& d, ModuleGenerator& mg)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(ExportTableId, &sectionStart, &sectionSize))
+    if (!d.startSection(ExportSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     CStringSet dupSet(cx);
     if (!dupSet.init())
         return false;
 
@@ -968,23 +968,23 @@ DecodeFunctionBody(JSContext* cx, Decode
 
     int64_t after = PRMJ_Now();
     unsigned generateTime = (after - before) / PRMJ_USEC_PER_MSEC;
 
     return mg.finishFuncDef(funcIndex, generateTime, &fg);
 }
 
 static bool
-DecodeFunctionBodies(JSContext* cx, Decoder& d, ModuleGenerator& mg)
+DecodeCodeSection(JSContext* cx, Decoder& d, ModuleGenerator& mg)
 {
     if (!mg.startFuncDefs())
         return false;
 
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(FunctionBodiesId, &sectionStart, &sectionSize))
+    if (!d.startSection(CodeSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
 
     if (sectionStart == Decoder::NotStarted) {
         if (mg.numFuncSigs() != 0)
             return Fail(cx, d, "expected function bodies");
 
         return mg.finishFuncDefs();
     }
@@ -1003,20 +1003,20 @@ DecodeFunctionBodies(JSContext* cx, Deco
 
     if (!d.finishSection(sectionStart, sectionSize))
         return Fail(cx, d, "function section byte size mismatch");
 
     return mg.finishFuncDefs();
 }
 
 static bool
-DecodeDataSegments(JSContext* cx, Decoder& d, Handle<ArrayBufferObject*> heap)
+DecodeDataSection(JSContext* cx, Decoder& d, Handle<ArrayBufferObject*> heap)
 {
     uint32_t sectionStart, sectionSize;
-    if (!d.startSection(DataSegmentsId, &sectionStart, &sectionSize))
+    if (!d.startSection(DataSectionId, &sectionStart, &sectionSize))
         return Fail(cx, d, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     if (!heap)
         return Fail(cx, d, "data section requires a memory section");
 
     uint32_t numSegments;
@@ -1069,42 +1069,42 @@ DecodeModule(JSContext* cx, UniqueChars 
 
     if (!d.readFixedU32(&u32) || u32 != EncodingVersion)
         return Fail(cx, d, "failed to match binary version");
 
     UniqueModuleGeneratorData init = js::MakeUnique<ModuleGeneratorData>(cx);
     if (!init)
         return false;
 
-    if (!DecodeSignatures(cx, d, init.get()))
+    if (!DecodeTypeSection(cx, d, init.get()))
         return false;
 
-    if (!DecodeImportTable(cx, d, init.get(), importNames))
+    if (!DecodeImportSection(cx, d, init.get(), importNames))
         return false;
 
-    if (!DecodeFunctionSignatures(cx, d, init.get()))
+    if (!DecodeFunctionSection(cx, d, init.get()))
         return false;
 
-    if (!DecodeFunctionTable(cx, d, init.get()))
+    if (!DecodeTableSection(cx, d, init.get()))
         return false;
 
     ModuleGenerator mg(cx);
     if (!mg.init(Move(init), Move(file)))
         return false;
 
-    if (!DecodeMemory(cx, d, mg, heap))
+    if (!DecodeMemorySection(cx, d, mg, heap))
         return false;
 
-    if (!DecodeExportTable(cx, d, mg))
+    if (!DecodeExportSection(cx, d, mg))
         return false;
 
-    if (!DecodeFunctionBodies(cx, d, mg))
+    if (!DecodeCodeSection(cx, d, mg))
         return false;
 
-    if (!DecodeDataSegments(cx, d, heap))
+    if (!DecodeDataSection(cx, d, heap))
         return false;
 
     CacheableCharsVector funcNames;
 
     while (!d.done()) {
         if (!d.skipSection())
             return Fail(cx, d, "failed to skip unknown section at end");
     }
--- a/js/src/asmjs/WasmBinary.h
+++ b/js/src/asmjs/WasmBinary.h
@@ -22,24 +22,24 @@
 #include "builtin/SIMD.h"
 
 namespace js {
 namespace wasm {
 
 static const uint32_t MagicNumber        = 0x6d736100; // "\0asm"
 static const uint32_t EncodingVersion    = 0x0b;
 
-static const char SignaturesId[]         = "signatures";
-static const char ImportTableId[]        = "import_table";
-static const char FunctionSignaturesId[] = "function_signatures";
-static const char FunctionTableId[]      = "function_table";
-static const char MemoryId[]             = "memory";
-static const char ExportTableId[]        = "export_table";
-static const char FunctionBodiesId[]     = "function_bodies";
-static const char DataSegmentsId[]       = "data_segments";
+static const char TypeSectionId[]        = "type";
+static const char ImportSectionId[]      = "import";
+static const char FunctionSectionId[]    = "function";
+static const char TableSectionId[]       = "table";
+static const char MemorySectionId[]      = "memory";
+static const char ExportSectionId[]      = "export";
+static const char CodeSectionId[]        = "code";
+static const char DataSectionId[]        = "data";
 
 enum class ValType : uint8_t
 {
     // 0x00 is reserved for ExprType::Void in the binary encoding. See comment
     // below about ExprType going away.
 
     I32                                  = 0x01,
     I64                                  = 0x02,
--- a/js/src/asmjs/WasmBinaryToText.cpp
+++ b/js/src/asmjs/WasmBinaryToText.cpp
@@ -1246,20 +1246,20 @@ RenderSignature(WasmRenderContext& c, co
             return false;
         if (!c.buffer.append(")"))
             return false;
     }
     return true;
 }
 
 static bool
-RenderSignatures(WasmRenderContext& c)
+RenderTypeSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(SignaturesId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(TypeSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numSigs;
     if (!c.d.readVarU32(&numSigs))
         return RenderFail(c, "expected number of signatures");
 
@@ -1304,20 +1304,20 @@ RenderSignatures(WasmRenderContext& c)
 
     if (!c.d.finishSection(sectionStart, sectionSize))
         return RenderFail(c, "decls section byte size mismatch");
 
     return true;
 }
 
 static bool
-RenderFunctionSignatures(WasmRenderContext& c)
+RenderFunctionSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(FunctionSignaturesId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(FunctionSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numDecls;
     if (!c.d.readVarU32(&numDecls))
         return RenderFail(c, "expected number of declarations");
 
@@ -1333,20 +1333,20 @@ RenderFunctionSignatures(WasmRenderConte
 
     if (!c.d.finishSection(sectionStart, sectionSize))
         return RenderFail(c, "decls section byte size mismatch");
 
     return true;
 }
 
 static bool
-RenderFunctionTable(WasmRenderContext& c)
+RenderTableSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(FunctionTableId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(TableSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numTableElems;
     if (!c.d.readVarU32(&numTableElems))
         return RenderFail(c, "expected number of table elems");
 
@@ -1418,20 +1418,20 @@ RenderImport(WasmRenderContext& c, uint3
     if (!c.buffer.append(")\n"))
         return false;
 
     return true;
 }
 
 
 static bool
-RenderImportTable(WasmRenderContext& c)
+RenderImportSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(ImportTableId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(ImportSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numImports;
     if (!c.d.readVarU32(&numImports))
         return RenderFail(c, "failed to read number of imports");
 
@@ -1445,23 +1445,23 @@ RenderImportTable(WasmRenderContext& c)
 
     if (!c.d.finishSection(sectionStart, sectionSize))
         return RenderFail(c, "import section byte size mismatch");
 
     return true;
 }
 
 static bool
-RenderMemory(WasmRenderContext& c, uint32_t* memInitial, uint32_t* memMax)
+RenderMemorySection(WasmRenderContext& c, uint32_t* memInitial, uint32_t* memMax)
 {
     *memInitial = 0;
     *memMax = 0;
 
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(MemoryId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(MemorySectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t initialSizePages;
     if (!c.d.readVarU32(&initialSizePages))
         return RenderFail(c, "expected initial memory size");
     *memInitial = initialSizePages;
@@ -1523,20 +1523,20 @@ RenderFunctionExport(WasmRenderContext& 
         return false;
     if (!c.buffer.append(")\n"))
         return false;
 
     return true;
 }
 
 static bool
-RenderExportTable(WasmRenderContext& c)
+RenderExportSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(ExportTableId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(ExportSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numExports;
     if (!c.d.readVarU32(&numExports))
         return RenderFail(c, "failed to read number of exports");
 
@@ -1607,20 +1607,20 @@ RenderFunctionBody(WasmRenderContext& c,
         return RenderFail(c, "function body length mismatch");
 
     c.indent--;
 
     return true;
 }
 
 static bool
-RenderFunctionBodies(WasmRenderContext& c)
+RenderCodeSection(WasmRenderContext& c)
 {
     uint32_t sectionStart, sectionSize;
-    if (!c.d.startSection(FunctionBodiesId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(CodeSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
 
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t numFuncSigs = c.funcSigs.length();
 
     uint32_t numFuncBodies;
@@ -1659,17 +1659,17 @@ RenderFunctionBodies(WasmRenderContext& 
     if (!c.d.finishSection(sectionStart, sectionSize))
         return RenderFail(c, "function section byte size mismatch");
 
    return true;
 }
 
 
 static bool
-RenderDataSegments(WasmRenderContext& c, uint32_t memInitial, uint32_t memMax)
+RenderDataSection(WasmRenderContext& c, uint32_t memInitial, uint32_t memMax)
 {
     if (!RenderIndent(c))
         return false;
     if (!c.buffer.append("(memory "))
         return false;
     if (!RenderInt32(c, memInitial))
        return false;
     if (memMax != 0 && ~memMax != 0) {
@@ -1677,17 +1677,17 @@ RenderDataSegments(WasmRenderContext& c,
             return false;
         if (!RenderInt32(c, memMax))
             return false;
     }
 
     c.indent++;
     uint32_t sectionStart;
     uint32_t sectionSize;
-    if (!c.d.startSection(DataSegmentsId, &sectionStart, &sectionSize))
+    if (!c.d.startSection(DataSectionId, &sectionStart, &sectionSize))
         return RenderFail(c, "failed to start section");
     if (sectionStart == Decoder::NotStarted) {
       if (!c.buffer.append(")\n"))
           return false;
       return true;
     }
     if (!c.buffer.append("\n"))
         return false;
@@ -1744,39 +1744,39 @@ RenderModule(WasmRenderContext& c)
     if (!c.d.readFixedU32(&u32) || u32 != EncodingVersion)
         return RenderFail(c, "failed to match binary version");
 
     if (!c.buffer.append("(module\n"))
         return false;
 
     c.indent++;
 
-    if (!RenderSignatures(c))
+    if (!RenderTypeSection(c))
         return false;
 
-    if (!RenderImportTable(c))
+    if (!RenderImportSection(c))
         return false;
 
-    if (!RenderFunctionSignatures(c))
+    if (!RenderFunctionSection(c))
         return false;
 
-    if (!RenderFunctionTable(c))
+    if (!RenderTableSection(c))
         return false;
 
     uint32_t memInitial, memMax;
-    if (!RenderMemory(c, &memInitial, &memMax))
+    if (!RenderMemorySection(c, &memInitial, &memMax))
         return false;
 
-    if (!RenderExportTable(c))
+    if (!RenderExportSection(c))
         return false;
 
-    if (!RenderFunctionBodies(c))
+    if (!RenderCodeSection(c))
         return false;
 
-    if (!RenderDataSegments(c, memInitial, memMax))
+    if (!RenderDataSection(c, memInitial, memMax))
         return false;
 
     c.indent--;
 
     if (!c.buffer.append(")"))
         return false;
 
     return true;
--- a/js/src/asmjs/WasmTextToBinary.cpp
+++ b/js/src/asmjs/WasmTextToBinary.cpp
@@ -3946,23 +3946,23 @@ EncodeExpr(Encoder& e, WasmAstExpr& expr
     }
     MOZ_CRASH("Bad expr kind");
 }
 
 /*****************************************************************************/
 // wasm AST binary serialization
 
 static bool
-EncodeSignatures(Encoder& e, WasmAstModule& module)
+EncodeTypeSection(Encoder& e, WasmAstModule& module)
 {
     if (module.sigs().empty())
         return true;
 
     size_t offset;
-    if (!e.startSection(SignaturesId, &offset))
+    if (!e.startSection(TypeSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(module.sigs().length()))
         return false;
 
     for (WasmAstSig* sig : module.sigs()) {
         if (!e.writeVarU32(sig->args().length()))
             return false;
@@ -3976,23 +3976,23 @@ EncodeSignatures(Encoder& e, WasmAstModu
         }
     }
 
     e.finishSection(offset);
     return true;
 }
 
 static bool
-EncodeFunctionSignatures(Encoder& e, WasmAstModule& module)
+EncodeFunctionSection(Encoder& e, WasmAstModule& module)
 {
     if (module.funcs().empty())
         return true;
 
     size_t offset;
-    if (!e.startSection(FunctionSignaturesId, &offset))
+    if (!e.startSection(FunctionSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(module.funcs().length()))
         return false;
 
     for (WasmAstFunc* func : module.funcs()) {
         if (!e.writeVarU32(func->sig().index()))
             return false;
@@ -4021,45 +4021,45 @@ EncodeImport(Encoder& e, WasmAstImport& 
 
     if (!EncodeBytes(e, imp.func()))
         return false;
 
     return true;
 }
 
 static bool
-EncodeImportTable(Encoder& e, WasmAstModule& module)
+EncodeImportSection(Encoder& e, WasmAstModule& module)
 {
     if (module.imports().empty())
         return true;
 
     size_t offset;
-    if (!e.startSection(ImportTableId, &offset))
+    if (!e.startSection(ImportSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(module.imports().length()))
         return false;
 
     for (WasmAstImport* imp : module.imports()) {
         if (!EncodeImport(e, *imp))
             return false;
     }
 
     e.finishSection(offset);
     return true;
 }
 
 static bool
-EncodeMemory(Encoder& e, WasmAstModule& module)
+EncodeMemorySection(Encoder& e, WasmAstModule& module)
 {
     if (!module.maybeMemory())
         return true;
 
     size_t offset;
-    if (!e.startSection(MemoryId, &offset))
+    if (!e.startSection(MemorySectionId, &offset))
         return false;
 
     WasmAstMemory& memory = *module.maybeMemory();
 
     if (!e.writeVarU32(memory.initialSize()))
         return false;
 
     uint32_t maxSize = memory.maxSize() ? *memory.maxSize() : memory.initialSize();
@@ -4089,29 +4089,29 @@ EncodeFunctionExport(Encoder& e, WasmAst
 
     if (!EncodeBytes(e, exp.name()))
         return false;
 
     return true;
 }
 
 static bool
-EncodeExportTable(Encoder& e, WasmAstModule& module)
+EncodeExportSection(Encoder& e, WasmAstModule& module)
 {
     uint32_t numFuncExports = 0;
     for (WasmAstExport* exp : module.exports()) {
         if (exp->kind() == WasmAstExportKind::Func)
             numFuncExports++;
     }
 
     if (!numFuncExports)
         return true;
 
     size_t offset;
-    if (!e.startSection(ExportTableId, &offset))
+    if (!e.startSection(ExportSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(numFuncExports))
         return false;
 
     for (WasmAstExport* exp : module.exports()) {
         switch (exp->kind()) {
           case WasmAstExportKind::Func:
@@ -4123,23 +4123,23 @@ EncodeExportTable(Encoder& e, WasmAstMod
         }
     }
 
     e.finishSection(offset);
     return true;
 }
 
 static bool
-EncodeFunctionTable(Encoder& e, WasmAstModule& module)
+EncodeTableSection(Encoder& e, WasmAstModule& module)
 {
     if (!module.maybeTable())
         return true;
 
     size_t offset;
-    if (!e.startSection(FunctionTableId, &offset))
+    if (!e.startSection(TableSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(module.maybeTable()->elems().length()))
         return false;
 
     for (WasmRef& ref : module.maybeTable()->elems()) {
         if (!e.writeVarU32(ref.index()))
             return false;
@@ -4169,23 +4169,23 @@ EncodeFunctionBody(Encoder& e, WasmAstFu
             return false;
     }
 
     e.patchVarU32(bodySizeAt, e.currentOffset() - beforeBody);
     return true;
 }
 
 static bool
-EncodeFunctionBodies(Encoder& e, WasmAstModule& module)
+EncodeCodeSection(Encoder& e, WasmAstModule& module)
 {
     if (module.funcs().empty())
         return true;
 
     size_t offset;
-    if (!e.startSection(FunctionBodiesId, &offset))
+    if (!e.startSection(CodeSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(module.funcs().length()))
         return false;
 
     for (WasmAstFunc* func : module.funcs()) {
         if (!EncodeFunctionBody(e, *func))
             return false;
@@ -4217,25 +4217,25 @@ EncodeDataSegment(Encoder& e, WasmAstSeg
 
     if (!e.writeBytes(bytes.begin(), bytes.length()))
         return false;
 
     return true;
 }
 
 static bool
-EncodeDataSegments(Encoder& e, WasmAstModule& module)
+EncodeDataSection(Encoder& e, WasmAstModule& module)
 {
     if (!module.maybeMemory() || module.maybeMemory()->segments().empty())
         return true;
 
     const WasmAstSegmentVector& segments = module.maybeMemory()->segments();
 
     size_t offset;
-    if (!e.startSection(DataSegmentsId, &offset))
+    if (!e.startSection(DataSectionId, &offset))
         return false;
 
     if (!e.writeVarU32(segments.length()))
         return false;
 
     for (WasmAstSegment* segment : segments) {
         if (!EncodeDataSegment(e, *segment))
             return false;
@@ -4251,38 +4251,38 @@ EncodeModule(WasmAstModule& module, Byte
     Encoder e(*bytes);
 
     if (!e.writeFixedU32(MagicNumber))
         return false;
 
     if (!e.writeFixedU32(EncodingVersion))
         return false;
 
-    if (!EncodeSignatures(e, module))
+    if (!EncodeTypeSection(e, module))
         return false;
 
-    if (!EncodeImportTable(e, module))
+    if (!EncodeImportSection(e, module))
         return false;
 
-    if (!EncodeFunctionSignatures(e, module))
+    if (!EncodeFunctionSection(e, module))
         return false;
 
-    if (!EncodeFunctionTable(e, module))
+    if (!EncodeTableSection(e, module))
         return false;
 
-    if (!EncodeMemory(e, module))
+    if (!EncodeMemorySection(e, module))
         return false;
 
-    if (!EncodeExportTable(e, module))
+    if (!EncodeExportSection(e, module))
         return false;
 
-    if (!EncodeFunctionBodies(e, module))
+    if (!EncodeCodeSection(e, module))
         return false;
 
-    if (!EncodeDataSegments(e, module))
+    if (!EncodeDataSection(e, module))
         return false;
 
     return true;
 }
 
 /*****************************************************************************/
 
 bool
--- a/js/src/jit-test/tests/wasm/binary.js
+++ b/js/src/jit-test/tests/wasm/binary.js
@@ -8,23 +8,23 @@ const magic3 = 0x6d;  // 'm'
 
 // EncodingVersion = 11 (unofficial; to be reset at some point in the future)
 const ver0 = 0x0b;
 const ver1 = 0x00;
 const ver2 = 0x00;
 const ver3 = 0x00;
 
 // Section names
-const sigId                = "signatures";
-const importId             = "import_table";
-const functionSignaturesId = "function_signatures";
-const functionTableId      = "function_table";
-const exportTableId        = "export_table";
-const functionBodiesId     = "function_bodies";
-const dataSegmentsId       = "data_segments";
+const sigId                = "type";
+const importId             = "import";
+const functionSignaturesId = "function";
+const functionTableId      = "table";
+const exportTableId        = "export";
+const functionBodiesId     = "code";
+const dataSegmentsId       = "data";
 
 const magicError = /failed to match magic number/;
 const versionError = /failed to match binary version/;
 const unknownSectionError = /failed to skip unknown section at end/;
 const sectionError = /failed to start section/;
 
 const VoidCode = 0;
 const I32Code = 1;