wasmContainer.jsView |
---|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | 91 | static async onCreation (unverifiedWasm, id, tree) { |
92 | | - const cachedb = tree.dag._dag |
93 | | - let {json, wasm, modRef} = this.createModule(unverifiedWasm, id) |
94 | | - await Promise.all([ |
95 | | - new Promise((resolve, reject) => { |
96 | | - cachedb.put(id.id.toString() + 'meta', JSON.stringify(json), resolve) |
97 | | - }), |
98 | | - new Promise((resolve, reject) => { |
99 | | - cachedb.put(id.id.toString() + 'code', wasm.toString('hex'), resolve) |
100 | | - }) |
101 | | - ]) |
| 92 | + let {modRef} = this.createModule(unverifiedWasm, id) |
102 | 93 | return modRef |
103 | 94 | } |
104 | 95 | |
105 | 96 | getInterface (funcRef) { |
296 | 287 | return this._opsQueue |
297 | 288 | } |
298 | 289 | |
299 | 290 | async onStartup () { |
300 | | - let [json, wasm] = await Promise.all([ |
301 | | - new Promise((resolve, reject) => { |
302 | | - this.actor.cachedb.get(this.actor.id.id.toString() + 'meta', (err, json) => { |
303 | | - if (err) { |
304 | | - reject(err) |
305 | | - } else { |
306 | | - resolve(json) |
307 | | - } |
308 | | - }) |
309 | | - }), |
310 | | - new Promise((resolve, reject) => { |
311 | | - this.actor.cachedb.get(this.actor.id.id.toString() + 'code', (err, wasm) => { |
312 | | - if (err) { |
313 | | - reject(err) |
314 | | - } else { |
315 | | - resolve(wasm) |
316 | | - } |
317 | | - }) |
318 | | - }) |
319 | | - ]) |
320 | | - wasm = Buffer.from(wasm, 'hex') |
321 | | - json = JSON.parse(json) |
| 291 | + const code = this.actor.code |
| 292 | + const {json, wasm, modRef} = WasmContainer.createModule(code, this.actor.id) |
322 | 293 | this.mod = WebAssembly.Module(wasm) |
323 | 294 | this.json = json |
324 | | - this.modSelf = ModuleRef.fromMetaJSON(json, this.actor.id) |
| 295 | + this.modSelf = modRef |
325 | 296 | } |
326 | 297 | |
327 | 298 | get8Memory (offset, length) { |
328 | 299 | return new Uint8Array(this.instance.exports.memory.buffer, offset, length) |