Commit 650dd174 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[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/897526Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51059}
parent 3c3e76a3
...@@ -723,11 +723,10 @@ class ErrorUtils : public AllStatic { ...@@ -723,11 +723,10 @@ class ErrorUtils : public AllStatic {
T(WasmTrapDivByZero, "divide by zero") \ T(WasmTrapDivByZero, "divide by zero") \
T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \ T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \
T(WasmTrapRemByZero, "remainder by zero") \ T(WasmTrapRemByZero, "remainder by zero") \
T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \ T(WasmTrapFloatUnrepresentable, "float unrepresentable in integer range") \
T(WasmTrapFuncInvalid, "invalid function") \ T(WasmTrapFuncInvalid, "invalid index into function table") \
T(WasmTrapFuncSigMismatch, "function signature mismatch") \ T(WasmTrapFuncSigMismatch, "function signature mismatch") \
T(WasmTrapInvalidIndex, "invalid index into function table") \ T(WasmTrapTypeError, "wasm function signature contains illegal type") \
T(WasmTrapTypeError, "invalid type") \
T(WasmExceptionError, "wasm exception") \ T(WasmExceptionError, "wasm exception") \
/* Asm.js validation related */ \ /* Asm.js validation related */ \
T(AsmJsInvalid, "Invalid asm.js: %") \ T(AsmJsInvalid, "Invalid asm.js: %") \
......
...@@ -160,15 +160,22 @@ function assertConversionError(bytes, imports, msg) { ...@@ -160,15 +160,22 @@ function assertConversionError(bytes, imports, msg) {
(function TestConversionError() { (function TestConversionError() {
let b = builder(); let b = builder();
b.addImport("foo", "bar", kSig_v_l); b.addImport('foo', 'bar', kSig_v_l);
assertConversionError(b.addFunction("run", kSig_v_v).addBody([ let buffer = b.addFunction('run', kSig_v_v)
kExprI64Const, 0, kExprCallFunction, 0 .addBody([kExprI64Const, 0, kExprCallFunction, 0])
]).exportFunc().end().toBuffer(), {foo:{bar: (l)=>{}}}, "invalid type"); .exportFunc()
.end()
b = builder() .toBuffer();
assertConversionError(builder().addFunction("run", kSig_l_v).addBody([ assertConversionError(
kExprI64Const, 0 buffer, {foo: {bar: (l) => {}}}, kTrapMsgs[kTrapTypeError]);
]).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) { ...@@ -178,7 +185,7 @@ function assertConversionError(bytes, imports, msg) {
builder.addImport("mod", "func", sig); builder.addImport("mod", "func", sig);
builder.addFunction("main", sig) builder.addFunction("main", sig)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0]) .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
.exportAs("main") .exportAs("main");
var main = builder.instantiate({ var main = builder.instantiate({
mod: { mod: {
func: ()=>{%DebugTrace();} func: ()=>{%DebugTrace();}
......
...@@ -296,7 +296,7 @@ function checkStack(stack, expected_lines) { ...@@ -296,7 +296,7 @@ function checkStack(stack, expected_lines) {
} catch (e) { } catch (e) {
if (!(e instanceof TypeError)) throw e; if (!(e instanceof TypeError)) throw e;
checkStack(stripPath(e.stack), [ checkStack(stripPath(e.stack), [
'TypeError: invalid type', // - 'TypeError: ' + kTrapMsgs[kTrapTypeError], // -
' at direct (wasm-function[1]:1)', // - ' at direct (wasm-function[1]:1)', // -
' at main (wasm-function[3]:3)', // - ' at main (wasm-function[3]:3)', // -
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // - /^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
...@@ -309,7 +309,7 @@ function checkStack(stack, expected_lines) { ...@@ -309,7 +309,7 @@ function checkStack(stack, expected_lines) {
} catch (e) { } catch (e) {
if (!(e instanceof TypeError)) throw e; if (!(e instanceof TypeError)) throw e;
checkStack(stripPath(e.stack), [ checkStack(stripPath(e.stack), [
'TypeError: invalid type', // - 'TypeError: ' + kTrapMsgs[kTrapTypeError], // -
' at indirect (wasm-function[2]:1)', // - ' at indirect (wasm-function[2]:1)', // -
' at main (wasm-function[3]:3)', // - ' at main (wasm-function[3]:3)', // -
/^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // - /^ at testIllegalImports \(interpreter.js:\d+:22\)$/, // -
......
...@@ -286,7 +286,7 @@ let id = (() => { // identity exported function ...@@ -286,7 +286,7 @@ let id = (() => { // identity exported function
assertInvalidFunction = function(s) { assertInvalidFunction = function(s) {
assertThrows( assertThrows(
() => instances[i].exports.main(s), WebAssembly.RuntimeError, () => instances[i].exports.main(s), WebAssembly.RuntimeError,
/invalid function/); kTrapMsgs[kTrapFuncInvalid]);
} }
assertInvalidFunction(size); assertInvalidFunction(size);
assertInvalidFunction(size + 1); assertInvalidFunction(size + 1);
......
...@@ -374,7 +374,7 @@ let kTrapRemByZero = 4; ...@@ -374,7 +374,7 @@ let kTrapRemByZero = 4;
let kTrapFloatUnrepresentable = 5; let kTrapFloatUnrepresentable = 5;
let kTrapFuncInvalid = 6; let kTrapFuncInvalid = 6;
let kTrapFuncSigMismatch = 7; let kTrapFuncSigMismatch = 7;
let kTrapInvalidIndex = 8; let kTrapTypeError = 8;
let kTrapMsgs = [ let kTrapMsgs = [
"unreachable", "unreachable",
...@@ -382,10 +382,10 @@ let kTrapMsgs = [ ...@@ -382,10 +382,10 @@ let kTrapMsgs = [
"divide by zero", "divide by zero",
"divide result unrepresentable", "divide result unrepresentable",
"remainder by zero", "remainder by zero",
"integer result unrepresentable", "float unrepresentable in integer range",
"invalid function", "invalid index into function table",
"function signature mismatch", "function signature mismatch",
"invalid index into function table" "wasm function signature contains illegal type"
]; ];
function assertTraps(trap, code) { function assertTraps(trap, code) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment