git ssb

0+

wanderer🌟 / js-primea-wasm-container



Commit 5cfe07e2570b6afb92a3fbd37c2400404b9d2c5e

bump deps

wanderer committed on 12/2/2017, 6:46:50 AM
Parent: 1482f27c212076f2b13ceff808d145911083c543

Files changed

index.jschanged
package-lock.jsonchanged
package.jsonchanged
index.jsView
@@ -1,8 +1,11 @@
11 const ReferanceMap = require('reference-map')
22 const AbstractContainer = require('primea-abstract-container')
33 const ContainerTable = require('primea-container-table')
4+const RadixTree = require('dfinity-radix-tree')
45
6+const CODEKEY = new RadixTree.ArrayConstructor([1])
7+
58 module.exports = class WasmContainer extends AbstractContainer {
69 /**
710 * The wasm container runs wasm code and provides a basic API for wasm
811 * interfaces for interacting with the actor
@@ -12,12 +15,28 @@
1215 constructor (actor, interfaces) {
1316 super(actor)
1417 this.imports = interfaces
1518 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+ }
1635 }
1736
1837 async onCreation (message) {
19- let code = this.actor.code
38+ let code = message.data
2039 if (!WebAssembly.validate(code)) {
2140 throw new Error('invalid wasm binary')
2241 } else {
2342 for (const name in this.imports) {
@@ -25,9 +44,9 @@
2544 if (interf.initialize) {
2645 code = await interf.initialize(code)
2746 }
2847 }
29- this.actor.state.code = code
48+ this.actor.state.set(CODEKEY, code)
3049 }
3150 return this._run(message, 'onCreation')
3251 }
3352
@@ -40,25 +59,10 @@
4059 return this._run(message, 'onMessage')
4160 }
4261
4362 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)
6165 this.instance = result.instance
6266
6367 // add the message and ports to the refereance map
6468 const messageRef = this.referanceMap.add(message)
package-lock.jsonView
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.jsonView
@@ -22,12 +22,12 @@
2222 "primea"
2323 ],
2424 "devDependencies": {
2525 "coveralls": "^3.0.0",
26- "dfinity-radix-tree": "0.0.7",
26+ "dfinity-radix-tree": "0.0.8",
2727 "level-browserify": "^1.1.1",
2828 "nyc": "^11.3.0",
29- "primea-hypervisor": "^0.4.1",
29+ "primea-hypervisor": "^0.4.3",
3030 "primea-message": "^0.6.0",
3131 "standard": "^10.0.0",
3232 "tape": "^4.6.3",
3333 "wast2wasm": "0.0.1"

Built with git-ssb-web