Bug 1305097: Enhance error reporting from the ToAST transformation; r=luke

This commit is contained in:
Benjamin Bouvier 2016-09-26 10:33:06 +02:00
Родитель 8bd74b039e
Коммит 31ba17fbcb
7 изменённых файлов: 27 добавлений и 14 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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),

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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),

Просмотреть файл

@ -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");

Просмотреть файл

@ -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);