From 31ba17fbcbd678bbab6707fd7499317f9ff66288 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 26 Sep 2016 10:33:06 +0200 Subject: [PATCH] Bug 1305097: Enhance error reporting from the ToAST transformation; r=luke --- js/src/asmjs/WasmBinary.cpp | 1 + js/src/asmjs/WasmBinary.h | 2 +- js/src/asmjs/WasmBinaryToAST.cpp | 28 +++++++++++-------- js/src/asmjs/WasmBinaryToAST.h | 3 +- js/src/asmjs/WasmBinaryToExperimentalText.cpp | 3 +- .../tests/wasm/to-text-experimental.js | 2 ++ js/src/jit-test/tests/wasm/to-text.js | 2 ++ 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/js/src/asmjs/WasmBinary.cpp b/js/src/asmjs/WasmBinary.cpp index 56e3bfb15dda..a3ece8f23088 100644 --- a/js/src/asmjs/WasmBinary.cpp +++ b/js/src/asmjs/WasmBinary.cpp @@ -40,6 +40,7 @@ Decoder::fail(const char* msg, ...) { bool Decoder::fail(UniqueChars msg) { + MOZ_ASSERT(error_); UniqueChars strWithOffset(JS_smprintf("at offset %zu: %s", currentOffset(), msg.get())); if (!strWithOffset) return false; diff --git a/js/src/asmjs/WasmBinary.h b/js/src/asmjs/WasmBinary.h index 0875fe72084b..b537dccb38f7 100644 --- a/js/src/asmjs/WasmBinary.h +++ b/js/src/asmjs/WasmBinary.h @@ -770,7 +770,7 @@ class Decoder static const size_t ExprLimit = 2 * UINT8_MAX - 1; public: - Decoder(const uint8_t* begin, const uint8_t* end, UniqueChars* error = nullptr) + Decoder(const uint8_t* begin, const uint8_t* end, UniqueChars* error) : beg_(begin), end_(end), cur_(begin), diff --git a/js/src/asmjs/WasmBinaryToAST.cpp b/js/src/asmjs/WasmBinaryToAST.cpp index d1cf1a9f4c86..61f89aa9b538 100644 --- a/js/src/asmjs/WasmBinaryToAST.cpp +++ b/js/src/asmjs/WasmBinaryToAST.cpp @@ -46,16 +46,20 @@ struct AstDecodeStackItem ExprType type; explicit AstDecodeStackItem() - : expr(nullptr), - terminationKind(AstDecodeTerminationKind::Unknown), - type(ExprType::Limit) {} - explicit AstDecodeStackItem(AstDecodeTerminationKind terminationKind, - ExprType type) - : expr(nullptr), terminationKind(terminationKind), type(type) {} + : expr(nullptr), + terminationKind(AstDecodeTerminationKind::Unknown), + type(ExprType::Limit) + {} + explicit AstDecodeStackItem(AstDecodeTerminationKind terminationKind, ExprType type) + : expr(nullptr), + terminationKind(terminationKind), + type(type) + {} explicit AstDecodeStackItem(AstExpr* expr) - : expr(expr), - terminationKind(AstDecodeTerminationKind::Unknown), - type(ExprType::Limit) {} + : expr(expr), + terminationKind(AstDecodeTerminationKind::Unknown), + type(ExprType::Limit) + {} }; // We don't define a Value type because ExprIter doesn't push void values, which @@ -97,7 +101,8 @@ class AstDecodeContext ExprType retType_; public: - AstDecodeContext(JSContext* cx, LifoAlloc& lifo, Decoder& d, AstModule& module, bool generateNames) + AstDecodeContext(JSContext* cx, LifoAlloc& lifo, Decoder& d, AstModule& module, + bool generateNames) : cx(cx), lifo(lifo), d(d), @@ -1469,7 +1474,6 @@ AstDecodeFunctionSection(AstDecodeContext& c) if (numDecls > MaxFuncs) return c.d.fail("too many functions"); - if (!c.funcSigs().resize(numDecls)) return false; @@ -2147,6 +2151,8 @@ wasm::BinaryToAst(JSContext* cx, const uint8_t* bytes, uint32_t length, return false; } + MOZ_ASSERT(!error, "unreported error in decoding"); + *module = result; return true; } diff --git a/js/src/asmjs/WasmBinaryToAST.h b/js/src/asmjs/WasmBinaryToAST.h index 8994f1c30b7d..79607d97ba33 100644 --- a/js/src/asmjs/WasmBinaryToAST.h +++ b/js/src/asmjs/WasmBinaryToAST.h @@ -28,7 +28,8 @@ namespace js { namespace wasm { bool -BinaryToAst(JSContext* cx, const uint8_t* bytes, uint32_t length, LifoAlloc& lifo, AstModule** module); +BinaryToAst(JSContext* cx, const uint8_t* bytes, uint32_t length, LifoAlloc& lifo, + AstModule** module); } // end wasm namespace } // end js namespace diff --git a/js/src/asmjs/WasmBinaryToExperimentalText.cpp b/js/src/asmjs/WasmBinaryToExperimentalText.cpp index a78aa51dbcf2..07083ee6153e 100644 --- a/js/src/asmjs/WasmBinaryToExperimentalText.cpp +++ b/js/src/asmjs/WasmBinaryToExperimentalText.cpp @@ -129,7 +129,8 @@ struct WasmPrintContext uint32_t currentFuncIndex; PrintOperatorPrecedence currentPrecedence; - WasmPrintContext(JSContext* cx, AstModule* module, WasmPrintBuffer& buffer, const ExperimentalTextFormatting& f, GeneratedSourceMap* wasmSourceMap_) + WasmPrintContext(JSContext* cx, AstModule* module, WasmPrintBuffer& buffer, + const ExperimentalTextFormatting& f, GeneratedSourceMap* wasmSourceMap_) : cx(cx), module(module), buffer(buffer), diff --git a/js/src/jit-test/tests/wasm/to-text-experimental.js b/js/src/jit-test/tests/wasm/to-text-experimental.js index 06967bfc819c..6b90435659d8 100644 --- a/js/src/jit-test/tests/wasm/to-text-experimental.js +++ b/js/src/jit-test/tests/wasm/to-text-experimental.js @@ -1,6 +1,8 @@ // |jit-test| test-also-wasm-baseline load(libdir + "wasm.js"); +assertErrorMessage(() => wasmBinaryToText(wasmTextToBinary(`(module (func (result i32) (f32.const 13.37)))`), 'experimental'), WebAssembly.CompileError, /type mismatch/); + function runTest(code, expected) { var binary = wasmTextToBinary(code); var s = wasmBinaryToText(binary, "experimental"); diff --git a/js/src/jit-test/tests/wasm/to-text.js b/js/src/jit-test/tests/wasm/to-text.js index 0caa61ca44e1..706ed1900383 100644 --- a/js/src/jit-test/tests/wasm/to-text.js +++ b/js/src/jit-test/tests/wasm/to-text.js @@ -9,6 +9,8 @@ try { } assertEq(caught, true); +assertErrorMessage(() => wasmBinaryToText(wasmTextToBinary(`(module (func (result i32) (f32.const 13.37)))`)), WebAssembly.CompileError, /type mismatch/); + function runTest(code) { var expected = wasmTextToBinary(code); var s = wasmBinaryToText(expected);