Commit 5cfe07e2570b6afb92a3fbd37c2400404b9d2c5e
bump deps
wanderer committed on 12/2/2017, 6:46:50 AMParent: 1482f27c212076f2b13ceff808d145911083c543
Files changed
index.js | changed |
package-lock.json | changed |
package.json | changed |
index.js | ||
---|---|---|
@@ -1,8 +1,11 @@ | ||
1 | 1 | const ReferanceMap = require('reference-map') |
2 | 2 | const AbstractContainer = require('primea-abstract-container') |
3 | 3 | const ContainerTable = require('primea-container-table') |
4 | +const RadixTree = require('dfinity-radix-tree') | |
4 | 5 | |
6 | +const CODEKEY = new RadixTree.ArrayConstructor([1]) | |
7 | + | |
5 | 8 | module.exports = class WasmContainer extends AbstractContainer { |
6 | 9 | /** |
7 | 10 | * The wasm container runs wasm code and provides a basic API for wasm |
8 | 11 | * interfaces for interacting with the actor |
@@ -12,12 +15,28 @@ | ||
12 | 15 | constructor (actor, interfaces) { |
13 | 16 | super(actor) |
14 | 17 | this.imports = interfaces |
15 | 18 | this.referanceMap = new ReferanceMap() |
19 | + | |
20 | + // Builds a import map with an array of given interfaces | |
21 | + this.importMap = {} | |
22 | + for (const name in this.imports) { | |
23 | + this.importMap[name] = {} | |
24 | + const Import = this.imports[name] | |
25 | + const newInterface = new Import(this) | |
26 | + const props = Object.getOwnPropertyNames(Import.prototype) | |
27 | + | |
28 | + // bind the methods to the correct 'this' | |
29 | + for (const prop of props) { | |
30 | + if (prop !== 'constructor') { | |
31 | + this.importMap[name][prop] = newInterface[prop].bind(newInterface) | |
32 | + } | |
33 | + } | |
34 | + } | |
16 | 35 | } |
17 | 36 | |
18 | 37 | async onCreation (message) { |
19 | - let code = this.actor.code | |
38 | + let code = message.data | |
20 | 39 | if (!WebAssembly.validate(code)) { |
21 | 40 | throw new Error('invalid wasm binary') |
22 | 41 | } else { |
23 | 42 | for (const name in this.imports) { |
@@ -25,9 +44,9 @@ | ||
25 | 44 | if (interf.initialize) { |
26 | 45 | code = await interf.initialize(code) |
27 | 46 | } |
28 | 47 | } |
29 | - this.actor.state.code = code | |
48 | + this.actor.state.set(CODEKEY, code) | |
30 | 49 | } |
31 | 50 | return this._run(message, 'onCreation') |
32 | 51 | } |
33 | 52 | |
@@ -40,25 +59,10 @@ | ||
40 | 59 | return this._run(message, 'onMessage') |
41 | 60 | } |
42 | 61 | |
43 | 62 | async _run (message, method) { |
44 | - // Builds a import map with an array of given interfaces | |
45 | - const importMap = {} | |
46 | - for (const name in this.imports) { | |
47 | - importMap[name] = {} | |
48 | - const Import = this.imports[name] | |
49 | - const newInterface = new Import(this) | |
50 | - const props = Object.getOwnPropertyNames(Import.prototype) | |
51 | - | |
52 | - // bind the methods to the correct 'this' | |
53 | - for (const prop of props) { | |
54 | - if (prop !== 'constructor') { | |
55 | - importMap[name][prop] = newInterface[prop].bind(newInterface) | |
56 | - } | |
57 | - } | |
58 | - } | |
59 | - | |
60 | - const result = await WebAssembly.instantiate(this.actor.code, importMap) | |
63 | + const code = await this.actor.state.get(CODEKEY) | |
64 | + const result = await WebAssembly.instantiate(code, this.importMap) | |
61 | 65 | this.instance = result.instance |
62 | 66 | |
63 | 67 | // add the message and ports to the refereance map |
64 | 68 | const messageRef = this.referanceMap.add(message) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 160731 bytes New file size: 158775 bytes |
package.json | ||
---|---|---|
@@ -22,12 +22,12 @@ | ||
22 | 22 | "primea" |
23 | 23 | ], |
24 | 24 | "devDependencies": { |
25 | 25 | "coveralls": "^3.0.0", |
26 | - "dfinity-radix-tree": "0.0.7", | |
26 | + "dfinity-radix-tree": "0.0.8", | |
27 | 27 | "level-browserify": "^1.1.1", |
28 | 28 | "nyc": "^11.3.0", |
29 | - "primea-hypervisor": "^0.4.1", | |
29 | + "primea-hypervisor": "^0.4.3", | |
30 | 30 | "primea-message": "^0.6.0", |
31 | 31 | "standard": "^10.0.0", |
32 | 32 | "tape": "^4.6.3", |
33 | 33 | "wast2wasm": "0.0.1" |
Built with git-ssb-web