summaryrefslogtreecommitdiff
path: root/src/passes/LegalizeJSInterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/LegalizeJSInterface.cpp')
-rw-r--r--src/passes/LegalizeJSInterface.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp
index 7991d7eb3..2f3e484ad 100644
--- a/src/passes/LegalizeJSInterface.cpp
+++ b/src/passes/LegalizeJSInterface.cpp
@@ -214,9 +214,16 @@ private:
// JS calls the export, so it must call a legal stub that calls the actual
// wasm function
Name makeLegalStub(Function* func, Module* module) {
+ Name legalName(std::string("legalstub$") + func->name.str);
+
+ // a method may be exported multiple times
+ if (module->getFunctionOrNull(legalName)) {
+ return legalName;
+ }
+
Builder builder(*module);
auto* legal = new Function();
- legal->name = Name(std::string("legalstub$") + func->name.str);
+ legal->name = legalName;
auto* call = module->allocator.alloc<Call>();
call->target = func->name;
@@ -254,11 +261,7 @@ private:
legal->body = call;
}
- // a method may be exported multiple times
- if (!module->getFunctionOrNull(legal->name)) {
- module->addFunction(legal);
- }
- return legal->name;
+ return module->addFunction(legal)->name;
}
// wasm calls the import, so it must call a stub that calls the actual legal