mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-01 00:22:17 +00:00
Fix wasm-interpreter with mixed types of imports
We counted all imports until the index of the descriptor function, now we only count imported functions
This commit is contained in:
parent
493cd24ace
commit
bf791efe2c
@ -92,14 +92,19 @@ impl Interpreter {
|
|||||||
// function.
|
// function.
|
||||||
if let Some(i) = module.import_section() {
|
if let Some(i) = module.import_section() {
|
||||||
ret.imports = i.functions();
|
ret.imports = i.functions();
|
||||||
for (i, entry) in i.entries().iter().enumerate() {
|
let mut idx = 0;
|
||||||
|
for entry in i.entries() {
|
||||||
|
match entry.external() {
|
||||||
|
External::Function(_) => idx += 1,
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
if entry.module() != "__wbindgen_placeholder__" {
|
if entry.module() != "__wbindgen_placeholder__" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if entry.field() != "__wbindgen_describe" {
|
if entry.field() != "__wbindgen_describe" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret.describe_idx = Some(i as u32);
|
ret.describe_idx = Some(idx - 1 as u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +189,13 @@ impl Interpreter {
|
|||||||
SetLocal(i) => locals[*i as usize] = self.stack.pop().unwrap(),
|
SetLocal(i) => locals[*i as usize] = self.stack.pop().unwrap(),
|
||||||
GetLocal(i) => self.stack.push(locals[*i as usize]),
|
GetLocal(i) => self.stack.push(locals[*i as usize]),
|
||||||
Call(idx) => {
|
Call(idx) => {
|
||||||
|
// If this function is calling the `__wbindgen_describe`
|
||||||
|
// function, which we've precomputed the index for, then
|
||||||
|
// it's telling us about the next `u32` element in the
|
||||||
|
// descriptor to return. We "call" the imported function
|
||||||
|
// here by directly inlining it.
|
||||||
|
//
|
||||||
|
// Otherwise this is a normal call so we recurse.
|
||||||
if Some(*idx) == self.describe_idx {
|
if Some(*idx) == self.describe_idx {
|
||||||
self.descriptor.push(self.stack.pop().unwrap() as u32);
|
self.descriptor.push(self.stack.pop().unwrap() as u32);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user