wasmContainer.jsView |
---|
73 | 73 | |
74 | 74 | let numOfGlobals = json.globals.length |
75 | 75 | if (numOfGlobals) { |
76 | 76 | moduleJSON = injectGlobals(moduleJSON, json.globals) |
77 | | - const storage = [] |
78 | | - while (numOfGlobals--) { |
79 | | - const type = json.globals[numOfGlobals].type |
80 | | - storage.push(DEFAULTS[type]) |
81 | | - } |
82 | | - tree.set(Buffer.concat([id.id, Buffer.from([1])]), storage) |
83 | 77 | } |
84 | 78 | |
85 | 79 | wasm = json2wasm(moduleJSON) |
86 | 80 | await Promise.all([ |
221 | 215 | let numOfGlobals = this.json.globals.length |
222 | 216 | if (numOfGlobals) { |
223 | 217 | const refs = [] |
224 | 218 | while (numOfGlobals--) { |
225 | | - const obj = this.storage[numOfGlobals] |
| 219 | + const obj = this.actor.storage[numOfGlobals] || DEFAULTS[this.json.globals[numOfGlobals].type] |
226 | 220 | refs.push(this.refs.add(obj, this.json.globals[numOfGlobals].type)) |
227 | 221 | } |
228 | 222 | this.instance.exports.setter_globals(...refs) |
229 | 223 | } |
237 | 231 | await this.onDone() |
238 | 232 | |
239 | 233 | numOfGlobals = this.json.globals.length |
240 | 234 | if (numOfGlobals) { |
241 | | - this.storage = [] |
| 235 | + this.actor.storage = [] |
242 | 236 | this.instance.exports.getter_globals() |
243 | 237 | const mem = new Uint32Array(this.instance.exports.memory.buffer, 0, numOfGlobals) |
244 | 238 | while (numOfGlobals--) { |
245 | 239 | const ref = mem[numOfGlobals] |
246 | | - this.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type)) |
| 240 | + this.actor.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type)) |
247 | 241 | } |
248 | | - this.actor.state.set(Buffer.from([1]), this.storage) |
249 | 242 | } |
250 | 243 | |
251 | 244 | this.refs.clear() |
252 | 245 | } |
273 | 266 | return this._opsQueue |
274 | 267 | } |
275 | 268 | |
276 | 269 | async onStartup () { |
277 | | - let [json, wasm, storage] = await Promise.all([ |
| 270 | + let [json, wasm] = await Promise.all([ |
278 | 271 | new Promise((resolve, reject) => { |
279 | 272 | this.actor.cachedb.get(this.actor.id.id.toString() + 'meta', (err, json) => { |
280 | 273 | if (err) { |
281 | 274 | reject(err) |
291 | 284 | } else { |
292 | 285 | resolve(wasm) |
293 | 286 | } |
294 | 287 | }) |
295 | | - }), |
296 | | - this.actor.state.get(Buffer.from([1])) |
| 288 | + }) |
297 | 289 | ]) |
298 | | - this.storage = storage.value |
299 | 290 | wasm = Buffer.from(wasm, 'hex') |
300 | 291 | json = JSON.parse(json) |
301 | 292 | this.mod = WebAssembly.Module(wasm) |
302 | 293 | this.json = json |