git ssb

0+

wanderer🌟 / js-primea-wasm-container



Commit 1acaf62122a024e6a953fb715cf4bbda94b804ad

added message and ports to referance map

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 8/16/2017, 7:37:10 PM
Parent: 97b2a265bf3e33d6846db4e4dd44976f4d0e2c7f

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -59,10 +59,15 @@
5959 }
6060
6161 const result = await WebAssembly.instantiate(this.kernel.state.code, importMap)
6262 this.instance = result.instance
63+
64+ // add the message and ports to the refereance map
65+ const messageRef = this.referanceMap.add(message)
66+ message.ports.forEach(port => this.referanceMap.add())
67+
6368 // runs the wasm code
64- this.instance.exports[method]()
69+ this.instance.exports[method](messageRef)
6570 return this.onDone()
6671 }
6772
6873 /**
tests/index.jsView
@@ -22,8 +22,12 @@
2222 writeMem (offset, val) {
2323 return this.wasmContainer.setMemory(offset, [val])
2424 }
2525
26+ numOfReferances () {
27+ return this.wasmContainer.referanceMap.size
28+ }
29+
2630 async callback (cb) {
2731 const promise = new Promise((resolve, reject) => {
2832 resolve()
2933 })
@@ -45,8 +49,23 @@
4549 }))
4650 instance.message(instance.createMessage())
4751 })
4852
53+ tape('referances', async t => {
54+ t.plan(1)
55+ const hypervisor = new Hypervisor(node.dag)
56+ const main = fs.readFileSync(`${__dirname}/wasm/referances.wasm`)
57+ hypervisor.registerContainer(WasmContainer, {
58+ env: ContainerTestInterface,
59+ test: testInterface(t)
60+ })
61+ const ports = hypervisor.createChannel()
62+ await hypervisor.createInstance(WasmContainer.typeId, new Message({
63+ data: main,
64+ ports: ports
65+ }))
66+ })
67+
4968 tape('wasm container - mem', async t => {
5069 t.plan(1)
5170 try {
5271 const hypervisor = new Hypervisor(node.dag)

Built with git-ssb-web