Commit 2417016a904e9be97c5043e4fc9b1d5357aa1635
fix a bug with calling findSections on the same json
Norton Wang committed on 3/6/2018, 10:27:33 PMParent: 888b8752d6766cfe61cb86689a349d3d493661c6
Files changed
injectGlobals.js | changed |
injectGlobals.js | ||
---|---|---|
@@ -1,21 +1,21 @@ | ||
1 | 1 | const {findSections} = require('wasm-json-toolkit') |
2 | -const wantedSections = ['type', 'import', 'function', 'export', 'code'] | |
3 | 2 | |
4 | 3 | module.exports = function injectGlobals (json, globals) { |
4 | + const wantedSections = ['type', 'import', 'function', 'export', 'code'] | |
5 | 5 | const iter = findSections(json, wantedSections) |
6 | - const {value: type} = iter.next() | |
6 | + const {value: type = {entries: []}} = iter.next() | |
7 | 7 | const getterType = type.entries.push(typeEntry()) - 1 |
8 | 8 | const setterType = type.entries.push(typeEntry(Array(globals.length).fill('i32'))) - 1 |
9 | 9 | |
10 | 10 | const {value: imports = {entries: []}} = iter.next() |
11 | - const {value: func} = iter.next() | |
11 | + const {value: func = {entries: []}} = iter.next() | |
12 | 12 | const getterIndex = func.entries.push(getterType) - 1 + imports.entries.length |
13 | 13 | const setterIndex = func.entries.push(setterType) - 1 + imports.entries.length |
14 | - const {value: exports} = iter.next() | |
14 | + const {value: exports = {entries: []}} = iter.next() | |
15 | 15 | exports.entries.push(exportEntry('getter_globals', getterIndex)) |
16 | 16 | exports.entries.push(exportEntry('setter_globals', setterIndex)) |
17 | - const {value: code} = iter.next() | |
17 | + const {value: code = {entries: []}} = iter.next() | |
18 | 18 | const getterCode = [] |
19 | 19 | const setterCode = [] |
20 | 20 | globals.forEach((global, index) => { |
21 | 21 | const globalIndex = global.index |
Built with git-ssb-web