Commit 5b11996a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix error output for duplicate exports

There are other things to export beside functions. Thus, also print the
export kind when printing an error for duplicate export names.

R=titzer@chromium.org

Change-Id: I7477040dda274a16cfd776d7ac8db6e50a197b97
Reviewed-on: https://chromium-review.googlesource.com/564940Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46503}
parent 8cfec158
......@@ -606,8 +606,9 @@ class ModuleDecoder : public Decoder {
DCHECK(!cmp_less(*it, *last)); // Vector must be sorted.
if (!cmp_less(*last, *it)) {
const byte* pc = start() + GetBufferRelativeOffset(it->name.offset());
errorf(pc, "Duplicate export name '%.*s' for functions %d and %d",
it->name.length(), pc, last->index, it->index);
errorf(pc, "Duplicate export name '%.*s' for %s %d and %s %d",
it->name.length(), pc, ExternalKindName(last->kind),
last->index, ExternalKindName(it->kind), it->index);
break;
}
}
......
......@@ -1127,3 +1127,17 @@ Handle<Code> LazyCompilationOrchestrator::CompileLazy(
DCHECK_EQ(Code::WASM_FUNCTION, ret->kind());
return handle(ret, isolate);
}
const char* wasm::ExternalKindName(WasmExternalKind kind) {
switch (kind) {
case kExternalFunction:
return "function";
case kExternalTable:
return "table";
case kExternalMemory:
return "memory";
case kExternalGlobal:
return "global";
}
return "unknown";
}
......@@ -512,6 +512,8 @@ class LazyCompilationOrchestrator {
int exported_func_index, bool patch_caller);
};
const char* ExternalKindName(WasmExternalKind);
namespace testing {
void ValidateInstancesChain(Isolate* isolate,
Handle<WasmModuleObject> module_obj,
......
......@@ -38,3 +38,21 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addGlobal(kWasmI64, false).exportAs('g');
assertThrows(() => builder.instantiate(), WebAssembly.LinkError);
})();
(function duplicateGlobalExportName() {
var builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI64, false).exportAs('g');
builder.addGlobal(kWasmI64, false).exportAs('g');
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
/Duplicate export name 'g' for global 0 and global 1/);
})();
(function exportNameClashWithFunction() {
var builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI64, false).exportAs('foo');
builder.addFunction('f', kSig_v_v).addBody([]).exportAs('foo');
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
/Duplicate export name 'foo' for global 0 and function 0/);
})();
......@@ -106,12 +106,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("two", kSig_v_v).addBody([kExprNop]).exportAs("other");
builder.addFunction("three", kSig_v_v).addBody([kExprNop]).exportAs("main");
try {
builder.instantiate();
assertUnreachable("should have thrown an exception");
} catch (e) {
assertContains("Duplicate export", e.toString());
}
assertThrows(() => builder.instantiate(), WebAssembly.CompileError,
/Duplicate export name 'main' for function 0 and function 2/);
})();
......
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