Skip to content

Commit 0b9efd6

Browse files
committed
fix(WebAssemblyGenerator): correct getNextFuncIndex
1 parent c2eef97 commit 0b9efd6

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

‎lib/WebAssemblyGenerator.js‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ function compose(...fns) {
1818

1919
// Utility functions
2020
const isGlobalImport = moduleImport => moduleImport.descr.type === "GlobalType";
21-
const isFuncImport = moduleImport =>
22-
moduleImport.descr.type === "FuncImportDescr";
2321
const initFuncId = t.identifier("__init__");
2422

2523
/**
@@ -77,28 +75,20 @@ function getImportedGlobals(ast) {
7775
/**
7876
* Get next func index
7977
*
80-
* We need to respect the instantation order, first count the number of imported
81-
* func and func declared in the module.
78+
* Funcs are referenced by their index in the type section, we just return the
79+
* next index.
8280
*
8381
* @param {Object} ast - Module's AST
8482
* @returns {t.indexLiteral} - index
8583
*/
8684
function getNextFuncIndex(ast) {
87-
let count = 0;
85+
const typeSectionMetadata = t.getSectionMetadata(ast, "type");
8886

89-
t.traverse(ast, {
90-
ModuleImport({ node }) {
91-
if (isFuncImport(node) === true) {
92-
count++;
93-
}
94-
},
95-
96-
Func({ node }) {
97-
count++;
98-
}
99-
});
87+
if (typeof typeSectionMetadata === "undefined") {
88+
return t.indexLiteral(0);
89+
}
10090

101-
return t.indexLiteral(count);
91+
return t.indexLiteral(typeSectionMetadata.vectorOfSize);
10292
}
10393

10494
/**

0 commit comments

Comments
 (0)