Merge pull request #1064 from alexcrichton/wasm2es6js-imports

wasm2es6js: Fix handling of exported imports
This commit is contained in:
Sendil Kumar N 2018-11-30 01:01:45 +01:00 committed by GitHub
commit fbad34a4cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,7 +58,27 @@ pub fn typescript(module: &Module) -> String {
.unwrap_or(0);
for entry in i.entries() {
let idx = match *entry.internal() {
Internal::Function(i) => i - imported_functions,
Internal::Function(i) if i < imported_functions => {
*module.import_section()
.unwrap()
.entries()
.iter()
.filter_map(|f| {
match f.external() {
External::Function(i) => Some(i),
_ => None,
}
})
.nth(i as usize)
.unwrap()
}
Internal::Function(i) => {
let idx = i - imported_functions;
let functions = module
.function_section()
.expect("failed to find function section");
functions.entries()[idx as usize].type_ref()
}
Internal::Memory(_) => {
exports.push_str(&format!(
"export const {}: WebAssembly.Memory;\n",
@ -76,11 +96,6 @@ pub fn typescript(module: &Module) -> String {
Internal::Global(_) => continue,
};
let functions = module
.function_section()
.expect("failed to find function section");
let idx = functions.entries()[idx as usize].type_ref();
let types = module
.type_section()
.expect("failed to find type section");