[wasm] Improve trap messages
Especially "invalid function" and "invalid type" could contain much more information. Drive-by: Remove unused WasmTrapInvalidIndex. R=ahaas@chromium.org Change-Id: I7fd72c095eaad94e3e2d9bfe6ab4a9ce0bb4798b Reviewed-on: https://chromium-review.googlesource.com/897526 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#51059}
This commit is contained in:
parent
3c3e76a304
commit
650dd1746b
@ -723,11 +723,10 @@ class ErrorUtils : public AllStatic {
|
||||
T(WasmTrapDivByZero, "divide by zero") \
|
||||
T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \
|
||||
T(WasmTrapRemByZero, "remainder by zero") \
|
||||
T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \
|
||||
T(WasmTrapFuncInvalid, "invalid function") \
|
||||
T(WasmTrapFloatUnrepresentable, "float unrepresentable in integer range") \
|
||||
T(WasmTrapFuncInvalid, "invalid index into function table") \
|
||||
T(WasmTrapFuncSigMismatch, "function signature mismatch") \
|
||||
T(WasmTrapInvalidIndex, "invalid index into function table") \
|
||||
T(WasmTrapTypeError, "invalid type") \
|
||||
T(WasmTrapTypeError, "wasm function signature contains illegal type") \
|
||||
T(WasmExceptionError, "wasm exception") \
|
||||
/* Asm.js validation related */ \
|
||||
T(AsmJsInvalid, "Invalid asm.js: %") \
|
||||
|
@ -160,15 +160,22 @@ function assertConversionError(bytes, imports, msg) {
|
||||
|
||||
(function TestConversionError() {
|
||||
let b = builder();
|
||||
b.addImport("foo", "bar", kSig_v_l);
|
||||
assertConversionError(b.addFunction("run", kSig_v_v).addBody([
|
||||
kExprI64Const, 0, kExprCallFunction, 0
|
||||
]).exportFunc().end().toBuffer(), {foo:{bar: (l)=>{}}}, "invalid type");
|
||||
b.addImport('foo', 'bar', kSig_v_l);
|
||||
let buffer = b.addFunction('run', kSig_v_v)
|
||||
.addBody([kExprI64Const, 0, kExprCallFunction, 0])
|
||||
.exportFunc()
|
||||
.end()
|
||||
.toBuffer();
|
||||
assertConversionError(
|
||||
buffer, {foo: {bar: (l) => {}}}, kTrapMsgs[kTrapTypeError]);
|
||||
|
||||
b = builder()
|
||||
assertConversionError(builder().addFunction("run", kSig_l_v).addBody([
|
||||
kExprI64Const, 0
|
||||
]).exportFunc().end().toBuffer(), {}, "invalid type");
|
||||
buffer = builder()
|
||||
.addFunction('run', kSig_l_v)
|
||||
.addBody([kExprI64Const, 0])
|
||||
.exportFunc()
|
||||
.end()
|
||||
.toBuffer();
|
||||
assertConversionError(buffer, {}, kTrapMsgs[kTrapTypeError]);
|
||||
})();
|
||||
|
||||
|
||||
@ -178,7 +185,7 @@ function assertConversionError(bytes, imports, msg) {
|
||||
builder.addImport("mod", "func", sig);
|
||||
builder.addFunction("main", sig)
|
||||
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
|
||||
.exportAs("main")
|
||||
.exportAs("main");
|
||||
var main = builder.instantiate({
|
||||
mod: {
|
||||
func: ()=>{%DebugTrace();}
|
||||
|
@ -296,7 +296,7 @@ function checkStack(stack, expected_lines) {
|
||||
} catch (e) {
|
||||
if (!(e instanceof TypeError)) throw e;
|
||||
checkStack(stripPath(e.stack), [
|
||||
'TypeError: invalid type', // -
|
||||
'TypeError: ' + kTrapMsgs[kTrapTypeError], // -
|
||||
' at direct (wasm-function[1]:1)', // -
|
||||
' at main (wasm-function[3]:3)', // -
|
||||
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
|
||||
@ -309,7 +309,7 @@ function checkStack(stack, expected_lines) {
|
||||
} catch (e) {
|
||||
if (!(e instanceof TypeError)) throw e;
|
||||
checkStack(stripPath(e.stack), [
|
||||
'TypeError: invalid type', // -
|
||||
'TypeError: ' + kTrapMsgs[kTrapTypeError], // -
|
||||
' at indirect (wasm-function[2]:1)', // -
|
||||
' at main (wasm-function[3]:3)', // -
|
||||
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
|
||||
|
@ -286,7 +286,7 @@ let id = (() => { // identity exported function
|
||||
assertInvalidFunction = function(s) {
|
||||
assertThrows(
|
||||
() => instances[i].exports.main(s), WebAssembly.RuntimeError,
|
||||
/invalid function/);
|
||||
kTrapMsgs[kTrapFuncInvalid]);
|
||||
}
|
||||
assertInvalidFunction(size);
|
||||
assertInvalidFunction(size + 1);
|
||||
|
@ -374,7 +374,7 @@ let kTrapRemByZero = 4;
|
||||
let kTrapFloatUnrepresentable = 5;
|
||||
let kTrapFuncInvalid = 6;
|
||||
let kTrapFuncSigMismatch = 7;
|
||||
let kTrapInvalidIndex = 8;
|
||||
let kTrapTypeError = 8;
|
||||
|
||||
let kTrapMsgs = [
|
||||
"unreachable",
|
||||
@ -382,10 +382,10 @@ let kTrapMsgs = [
|
||||
"divide by zero",
|
||||
"divide result unrepresentable",
|
||||
"remainder by zero",
|
||||
"integer result unrepresentable",
|
||||
"invalid function",
|
||||
"float unrepresentable in integer range",
|
||||
"invalid index into function table",
|
||||
"function signature mismatch",
|
||||
"invalid index into function table"
|
||||
"wasm function signature contains illegal type"
|
||||
];
|
||||
|
||||
function assertTraps(trap, code) {
|
||||
|
Loading…
Reference in New Issue
Block a user