Commit 659347f9 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Slighly modify some error messages

This CL revises some of our error messages to be more precise or more
aesthetically appealing.

R=titzer@chromium.org, ahaas@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
Bug: chromium:926311
Change-Id: I38eaee09fd37f9b67fdb08bc7b0df64a6eaf96f9
Reviewed-on: https://chromium-review.googlesource.com/c/1445980Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59249}
parent 0194eb58
......@@ -367,7 +367,7 @@ class ModuleDecoderImpl : public Decoder {
// Check if the section is out-of-order.
if (section_code < next_ordered_section_ &&
section_code < kFirstUnorderedSection) {
errorf(pc(), "unexpected section: %s", SectionName(section_code));
errorf(pc(), "unexpected section <%s>", SectionName(section_code));
return;
}
......@@ -446,18 +446,18 @@ class ModuleDecoderImpl : public Decoder {
if (enabled_features_.bulk_memory) {
DecodeDataCountSection();
} else {
errorf(pc(), "unexpected section: %s", SectionName(section_code));
errorf(pc(), "unexpected section <%s>", SectionName(section_code));
}
break;
case kExceptionSectionCode:
if (enabled_features_.eh) {
DecodeExceptionSection();
} else {
errorf(pc(), "unexpected section: %s", SectionName(section_code));
errorf(pc(), "unexpected section <%s>", SectionName(section_code));
}
break;
default:
errorf(pc(), "unexpected section: %s", SectionName(section_code));
errorf(pc(), "unexpected section <%s>", SectionName(section_code));
return;
}
......@@ -680,7 +680,8 @@ class ModuleDecoderImpl : public Decoder {
switch (exp->kind) {
case kExternalFunction: {
WasmFunction* func = nullptr;
exp->index = consume_func_index(module_.get(), &func);
exp->index =
consume_func_index(module_.get(), &func, "export function index");
module_->num_exported_functions++;
if (func) func->exported = true;
break;
......@@ -757,7 +758,8 @@ class ModuleDecoderImpl : public Decoder {
void DecodeStartSection() {
WasmFunction* func;
const byte* pos = pc_;
module_->start_function_index = consume_func_index(module_.get(), &func);
module_->start_function_index =
consume_func_index(module_.get(), &func, "start function index");
if (func &&
(func->sig->parameter_count() > 0 || func->sig->return_count() > 0)) {
error(pos, "invalid start function: non-zero parameter or return count");
......@@ -804,7 +806,8 @@ class ModuleDecoderImpl : public Decoder {
WasmElemSegment* init = &module_->elem_segments.back();
for (uint32_t j = 0; j < num_elem; j++) {
WasmFunction* func = nullptr;
uint32_t index = consume_func_index(module_.get(), &func);
uint32_t index =
consume_func_index(module_.get(), &func, "element function index");
DCHECK_IMPLIES(ok(), func != nullptr);
if (!ok()) break;
DCHECK_EQ(index, func->func_index);
......@@ -1267,8 +1270,9 @@ class ModuleDecoderImpl : public Decoder {
return count;
}
uint32_t consume_func_index(WasmModule* module, WasmFunction** func) {
return consume_index("function index", module->functions, func);
uint32_t consume_func_index(WasmModule* module, WasmFunction** func,
const char* name) {
return consume_index(name, module->functions, func);
}
uint32_t consume_global_index(WasmModule* module, WasmGlobal** global) {
......
......@@ -486,7 +486,7 @@ StreamingDecoder::SectionBuffer* StreamingDecoder::CreateNewBuffer(
// Check the order of sections. Unknown sections can appear at any position.
if (section_id != kUnknownSectionCode) {
if (section_id < next_section_id_) {
Error("Unexpected section");
Error("unexpected section");
return nullptr;
}
next_section_id_ = section_id + 1;
......
......@@ -46,7 +46,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' +
'function index 1 out of bounds (1 entry) @+20');
'start function index 1 out of bounds (1 entry) @+20');
})();
......@@ -63,7 +63,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' +
'unexpected section: Start @+27');
'unexpected section <Start> @+27');
})();
......
......@@ -584,7 +584,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) {
WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section: Global");
EXPECT_NOT_OK(result, "unexpected section <Global>");
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
......@@ -596,7 +596,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section: Global");
EXPECT_NOT_OK(result, "unexpected section <Global>");
}
TEST_F(WasmModuleVerifyTest, ExceptionImport) {
......@@ -2291,7 +2291,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) {
SECTION(Element, ENTRY_COUNT(0))};
WASM_FEATURE_SCOPE(bulk_memory);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section: Element");
EXPECT_NOT_OK(result, "unexpected section <Element>");
}
TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
......@@ -2309,7 +2309,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
};
WASM_FEATURE_SCOPE(bulk_memory);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section: Element");
EXPECT_NOT_OK(result, "unexpected section <Element>");
}
TEST_F(WasmModuleVerifyTest, MultipleDataCountSections) {
......
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