Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,16 @@ struct LegalizeJSInterface : public Pass {
// 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;
Expand Down Expand Up @@ -254,11 +261,7 @@ struct LegalizeJSInterface : public Pass {
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
Expand Down