Commit 9babf4f2b9100d276b3b4aa9195653cf32fc388d
added globals_getter/setter
wanderer committed on 2/20/2018, 11:41:52 PMParent: a338912f819bd6fa4333e0c982768e58f6f2219f
Files changed
customTypes.js | changed |
wasmContainer.js | changed |
customTypes.js | ||
---|---|---|
@@ -104,9 +104,8 @@ | ||
104 | 104 | binEntries.write(entry.params.map(type => LANGUAGE_TYPES[type])) // the paramter types |
105 | 105 | } |
106 | 106 | |
107 | 107 | binEntries.write([entry.return_type ? 1 : 0]) // number of return types |
108 | - | |
109 | 108 | if (entry.return_type) { |
110 | 109 | binEntries.write([LANGUAGE_TYPES[entry.return_type]]) |
111 | 110 | } |
112 | 111 | } |
@@ -158,12 +157,13 @@ | ||
158 | 157 | function mergeTypeSections (json) { |
159 | 158 | const result = { |
160 | 159 | types: [], |
161 | 160 | indexes: {}, |
162 | - exports: {} | |
161 | + exports: {}, | |
162 | + globals: [] | |
163 | 163 | } |
164 | 164 | |
165 | - const wantedSections = ['types', 'typeMap', 'type', 'import', 'function', 'export'] | |
165 | + const wantedSections = ['types', 'typeMap', 'globals', 'type', 'import', 'function', 'export'] | |
166 | 166 | const iterator = findSections(json, wantedSections) |
167 | 167 | const mappedFuncs = new Map() |
168 | 168 | const mappedTypes = new Map() |
169 | 169 | const {value: customType} = iterator.next() |
@@ -175,8 +175,13 @@ | ||
175 | 175 | if (typeMap) { |
176 | 176 | decodeTypeMap(typeMap.payload).forEach(map => mappedFuncs.set(map.func, map.type)) |
177 | 177 | } |
178 | 178 | |
179 | + let {value: globals} = iterator.next() | |
180 | + if (globals) { | |
181 | + result.globals = decodeGlobals(globals.payload) | |
182 | + } | |
183 | + | |
179 | 184 | const {value: type} = iterator.next() |
180 | 185 | const {value: imports = {entries: []}} = iterator.next() |
181 | 186 | const {value: functions} = iterator.next() |
182 | 187 | functions.entries.forEach((typeIndex, funcIndex) => { |
wasmContainer.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 | const ReferanceMap = require('reference-map') |
4 | 4 | const leb128 = require('leb128') |
5 | 5 | const Message = require('./message.js') |
6 | 6 | const customTypes = require('./customTypes.js') |
7 | +const injectGlobals = require('./injectGlobals.js') | |
7 | 8 | const typeCheckWrapper = require('./typeCheckWrapper.js') |
8 | 9 | |
9 | 10 | const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64']) |
10 | 11 | const LANGUAGE_TYPES = { |
@@ -155,8 +156,11 @@ | ||
155 | 156 | const json = customTypes.mergeTypeSections(moduleJSON) |
156 | 157 | moduleJSON = wasmMetering.meterJSON(moduleJSON, { |
157 | 158 | meterType: 'i32' |
158 | 159 | }) |
160 | + if (json.globals.length) { | |
161 | + moduleJSON = injectGlobals(moduleJSON, json.globals) | |
162 | + } | |
159 | 163 | wasm = json2wasm(moduleJSON) |
160 | 164 | await Promise.all([ |
161 | 165 | new Promise((resolve, reject) => { |
162 | 166 | cachedb.put(id.toString() + 'meta', JSON.stringify(json), resolve) |
Built with git-ssb-web