mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
wasm_interp: If called function is not found in exports, look in name section too
This commit is contained in:
parent
473dd371b0
commit
3d5edf57fc
1 changed files with 22 additions and 4 deletions
|
@ -198,6 +198,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
let fn_index = {
|
let fn_index = {
|
||||||
let mut export_iter = module.export.exports.iter();
|
let mut export_iter = module.export.exports.iter();
|
||||||
export_iter
|
export_iter
|
||||||
|
// First look up the name in exports
|
||||||
.find_map(|ex| {
|
.find_map(|ex| {
|
||||||
if ex.ty == ExportType::Func && ex.name == fn_name {
|
if ex.ty == ExportType::Func && ex.name == fn_name {
|
||||||
Some(ex.index)
|
Some(ex.index)
|
||||||
|
@ -205,10 +206,27 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok_or(format!(
|
.or_else(|| {
|
||||||
"I couldn't find an exported function '{}' in this WebAssembly module",
|
// Then look it up in the debug info!
|
||||||
|
// This is non-spec behaviour that Wasm3 seems to implement,
|
||||||
|
// and that our wasm_linking tests accidentally rely on!
|
||||||
|
let mut names = module.names.function_names.iter();
|
||||||
|
names.find_map(
|
||||||
|
|(index, name)| {
|
||||||
|
if *name == fn_name {
|
||||||
|
Some(*index)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.ok_or_else(|| {
|
||||||
|
format!(
|
||||||
|
"I couldn't find a function '{}' in this WebAssembly module",
|
||||||
fn_name
|
fn_name
|
||||||
))?
|
)
|
||||||
|
})?
|
||||||
};
|
};
|
||||||
|
|
||||||
self.program_counter = {
|
self.program_counter = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue