From 6c1baf1971adaf9f8a393943d4ba31d280e04e77 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 31 May 2016 14:46:58 -0700 Subject: handle duplicate exports in asm2wasm --- src/asm2wasm.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 2c78df2c0..4231fcc9a 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -660,6 +660,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // exports Ref object = curr[1]; Ref contents = object[1]; + std::map exported; for (unsigned k = 0; k < contents->size(); k++) { Ref pair = contents[k]; IString key = pair[0]->getIString(); @@ -675,10 +676,16 @@ void Asm2WasmBuilder::processAsm(Ref ast) { getTempRet0 = value; } assert(wasm.checkFunction(value)); - auto export_ = new Export; - export_->name = key; - export_->value = value; - wasm.addExport(export_); + if (exported.count(key) > 0) { + // asm.js allows duplicate exports, but not wasm. use the last, like asm.js + exported[key]->value = value; + } else { + auto* export_ = new Export; + export_->name = key; + export_->value = value; + wasm.addExport(export_); + exported[key] = export_; + } } } } -- cgit v1.2.3