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 { ...@@ -367,7 +367,7 @@ class ModuleDecoderImpl : public Decoder {
// Check if the section is out-of-order. // Check if the section is out-of-order.
if (section_code < next_ordered_section_ && if (section_code < next_ordered_section_ &&
section_code < kFirstUnorderedSection) { section_code < kFirstUnorderedSection) {
errorf(pc(), "unexpected section: %s", SectionName(section_code)); errorf(pc(), "unexpected section <%s>", SectionName(section_code));
return; return;
} }
...@@ -446,18 +446,18 @@ class ModuleDecoderImpl : public Decoder { ...@@ -446,18 +446,18 @@ class ModuleDecoderImpl : public Decoder {
if (enabled_features_.bulk_memory) { if (enabled_features_.bulk_memory) {
DecodeDataCountSection(); DecodeDataCountSection();
} else { } else {
errorf(pc(), "unexpected section: %s", SectionName(section_code)); errorf(pc(), "unexpected section <%s>", SectionName(section_code));
} }
break; break;
case kExceptionSectionCode: case kExceptionSectionCode:
if (enabled_features_.eh) { if (enabled_features_.eh) {
DecodeExceptionSection(); DecodeExceptionSection();
} else { } else {
errorf(pc(), "unexpected section: %s", SectionName(section_code)); errorf(pc(), "unexpected section <%s>", SectionName(section_code));
} }
break; break;
default: default:
errorf(pc(), "unexpected section: %s", SectionName(section_code)); errorf(pc(), "unexpected section <%s>", SectionName(section_code));
return; return;
} }
...@@ -680,7 +680,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -680,7 +680,8 @@ class ModuleDecoderImpl : public Decoder {
switch (exp->kind) { switch (exp->kind) {
case kExternalFunction: { case kExternalFunction: {
WasmFunction* func = nullptr; 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++; module_->num_exported_functions++;
if (func) func->exported = true; if (func) func->exported = true;
break; break;
...@@ -757,7 +758,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -757,7 +758,8 @@ class ModuleDecoderImpl : public Decoder {
void DecodeStartSection() { void DecodeStartSection() {
WasmFunction* func; WasmFunction* func;
const byte* pos = pc_; 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 && if (func &&
(func->sig->parameter_count() > 0 || func->sig->return_count() > 0)) { (func->sig->parameter_count() > 0 || func->sig->return_count() > 0)) {
error(pos, "invalid start function: non-zero parameter or return count"); error(pos, "invalid start function: non-zero parameter or return count");
...@@ -804,7 +806,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -804,7 +806,8 @@ class ModuleDecoderImpl : public Decoder {
WasmElemSegment* init = &module_->elem_segments.back(); WasmElemSegment* init = &module_->elem_segments.back();
for (uint32_t j = 0; j < num_elem; j++) { for (uint32_t j = 0; j < num_elem; j++) {
WasmFunction* func = nullptr; 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); DCHECK_IMPLIES(ok(), func != nullptr);
if (!ok()) break; if (!ok()) break;
DCHECK_EQ(index, func->func_index); DCHECK_EQ(index, func->func_index);
...@@ -1267,8 +1270,9 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1267,8 +1270,9 @@ class ModuleDecoderImpl : public Decoder {
return count; return count;
} }
uint32_t consume_func_index(WasmModule* module, WasmFunction** func) { uint32_t consume_func_index(WasmModule* module, WasmFunction** func,
return consume_index("function index", module->functions, func); const char* name) {
return consume_index(name, module->functions, func);
} }
uint32_t consume_global_index(WasmModule* module, WasmGlobal** global) { uint32_t consume_global_index(WasmModule* module, WasmGlobal** global) {
......
...@@ -486,7 +486,7 @@ StreamingDecoder::SectionBuffer* StreamingDecoder::CreateNewBuffer( ...@@ -486,7 +486,7 @@ StreamingDecoder::SectionBuffer* StreamingDecoder::CreateNewBuffer(
// Check the order of sections. Unknown sections can appear at any position. // Check the order of sections. Unknown sections can appear at any position.
if (section_id != kUnknownSectionCode) { if (section_id != kUnknownSectionCode) {
if (section_id < next_section_id_) { if (section_id < next_section_id_) {
Error("Unexpected section"); Error("unexpected section");
return nullptr; return nullptr;
} }
next_section_id_ = section_id + 1; next_section_id_ = section_id + 1;
......
...@@ -46,7 +46,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);}); ...@@ -46,7 +46,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
assertThrows( assertThrows(
() => builder.instantiate(), WebAssembly.CompileError, () => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' + '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]);}); ...@@ -63,7 +63,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
assertThrows( assertThrows(
() => builder.instantiate(), WebAssembly.CompileError, () => builder.instantiate(), WebAssembly.CompileError,
'WebAssembly.Module(): Wasm decoding failed: ' + 'WebAssembly.Module(): Wasm decoding failed: ' +
'unexpected section: Start @+27'); 'unexpected section <Start> @+27');
})(); })();
......
...@@ -584,7 +584,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) { ...@@ -584,7 +584,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) {
WASM_FEATURE_SCOPE(eh); WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data)); 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) { TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
...@@ -596,7 +596,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) { ...@@ -596,7 +596,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
WASM_FEATURE_SCOPE(eh); WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data)); 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) { TEST_F(WasmModuleVerifyTest, ExceptionImport) {
...@@ -2291,7 +2291,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) { ...@@ -2291,7 +2291,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) {
SECTION(Element, ENTRY_COUNT(0))}; SECTION(Element, ENTRY_COUNT(0))};
WASM_FEATURE_SCOPE(bulk_memory); WASM_FEATURE_SCOPE(bulk_memory);
ModuleResult result = DecodeModule(data, data + sizeof(data)); 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) { TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
...@@ -2309,7 +2309,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) { ...@@ -2309,7 +2309,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
}; };
WASM_FEATURE_SCOPE(bulk_memory); WASM_FEATURE_SCOPE(bulk_memory);
ModuleResult result = DecodeModule(data, data + sizeof(data)); 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) { 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