Commit b3ff3903 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix tests and improve error message

The test "assertThrows(builder.instantiate)" threw a TypeError before,
which made the test pass, but not because of the feature we wanted to
test.
This CL fixes the test to call builder.instantiate correctly, and also
tests for the correct error message.

Drive-by fix: Fix {expected} and {found} parameters in assertThrows.

R=ahaas@chromium.org

Change-Id: I11c0f63885cc14a36559e637aea60a9da6f1bb8f
Reviewed-on: https://chromium-review.googlesource.com/472886Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44584}
parent 2e275856
......@@ -931,8 +931,8 @@ class ModuleDecoder : public Decoder {
const byte* pos = pc_;
uint32_t index = consume_u32v(name);
if (index >= vector.size()) {
errorf(pos, "%s %u out of bounds (%d entries)", name, index,
static_cast<int>(vector.size()));
errorf(pos, "%s %u out of bounds (%d entr%s)", name, index,
static_cast<int>(vector.size()), vector.size() == 1 ? "y" : "ies");
*ptr = nullptr;
return 0;
}
......
......@@ -105,7 +105,8 @@ class V8_EXPORT_PRIVATE ErrorThrower {
template <typename T>
void CompileFailed(const char* error, Result<T>& result) {
DCHECK(result.failed());
CompileError("%s", result.error_msg.c_str());
CompileError("%s: %s @+%u", error, result.error_msg.c_str(),
result.error_offset);
}
i::Handle<i::Object> Reify() {
......
......@@ -422,7 +422,7 @@ var failWithMessage;
'invalid use of assertThrows, maybe you want assertThrowsEquals');
}
if (arguments.length >= 3) {
assertEquals(e.message, cause_opt);
assertEquals(cause_opt, e.message);
}
// Success.
return;
......
......@@ -44,7 +44,10 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
builder.addStart(func.index + 1);
assertThrows(builder.instantiate);
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' +
'function index 1 out of bounds (1 entry) @+20');
})();
......@@ -58,7 +61,10 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
builder.addExplicitSection([kStartSectionCode, 0]);
builder.addExplicitSection([kStartSectionCode, 0]);
assertThrows(builder.instantiate);
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' +
'unexpected section: Start @+27');
})();
......
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