git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 3c71975dada7fb231be29756db22f3b9f71eab24

sync contain creation

wanderer committed on 3/21/2018, 6:32:30 PM
Parent: a9f71fab3ac71562f46196e5ac263789e5c3f5b5

Files changed

index.jschanged
tests/index.jschanged
wasmContainer.jschanged
index.jsView
@@ -60,26 +60,27 @@
6060 * @param {Integer} type - the type id for the container
6161 * @param {Object} message - an intial [message](https://github.com/primea/js-primea-message) to send newly created actor
6262 * @param {Object} id - the id for the actor
6363 */
64- async createActor (type, code, id = {nonce: this.nonce++, parent: null}) {
64+ createActor (type, code, id = {nonce: this.nonce++, parent: null}) {
6565 const Container = this._containerTypes[type]
6666 const encoded = encodedID(id)
6767 let idHash = this._hash(encoded)
6868 idHash = new ID(idHash)
69- const module = await Container.onCreation(code, idHash, this.tree)
69+ const module = Container.onCreation(code, idHash, this.tree)
7070 const metaData = [type, 0]
7171
7272 // save the container in the state
73- const node = await this.tree.set(idHash.id, metaData)
74- // save the code
75- node[1] = {
76- '/': code
77- }
78- // save the storage
79- node[2] = {
80- '/': []
81- }
73+ this.tree.set(idHash.id, metaData).then(node => {
74+ // save the code
75+ node[1] = {
76+ '/': code
77+ }
78+ // save the storage
79+ node[2] = {
80+ '/': []
81+ }
82+ })
8283
8384 return {
8485 id: idHash,
8586 module
tests/index.jsView
@@ -47,9 +47,9 @@
4747
4848 const hypervisor = new Hypervisor(tree)
4949 hypervisor.registerContainer(testVMContainer)
5050
51- const {module} = await hypervisor.createActor(testVMContainer.typeId)
51+ const {module} = hypervisor.createActor(testVMContainer.typeId)
5252
5353 const message = new Message({
5454 funcRef: module.main,
5555 funcArguments: [1]
@@ -93,10 +93,10 @@
9393 const hypervisor = new Hypervisor(tree)
9494 hypervisor.registerContainer(testVMContainerA)
9595 hypervisor.registerContainer(testVMContainerB)
9696
97- const {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
98- const {module: moduleA} = await hypervisor.createActor(testVMContainerA.typeId)
97+ const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
98+ const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId)
9999
100100 const message = new Message({
101101 funcRef: moduleA.main,
102102 funcArguments: [moduleB.main]
@@ -141,11 +141,11 @@
141141 const hypervisor = new Hypervisor(tree)
142142 hypervisor.registerContainer(testVMContainerA)
143143 hypervisor.registerContainer(testVMContainerB)
144144
145- let {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
146- let {module: moduleA0} = await hypervisor.createActor(testVMContainerA.typeId)
147- let {module: moduleA1} = await hypervisor.createActor(testVMContainerA.typeId)
145+ let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
146+ let {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId)
147+ let {module: moduleA1} = hypervisor.createActor(testVMContainerA.typeId)
148148
149149 const message0 = new Message({
150150 funcRef: moduleA0.main,
151151 funcArguments: [moduleB.main]
@@ -197,11 +197,11 @@
197197 const hypervisor = new Hypervisor(tree)
198198 hypervisor.registerContainer(testVMContainerA)
199199 hypervisor.registerContainer(testVMContainerB)
200200
201- let actorB = await hypervisor.createActor(testVMContainerB.typeId)
202- let actorA0 = await hypervisor.createActor(testVMContainerA.typeId)
203- let actorA1 = await hypervisor.createActor(testVMContainerA.typeId)
201+ let actorB = hypervisor.createActor(testVMContainerB.typeId)
202+ let actorA0 = hypervisor.createActor(testVMContainerA.typeId)
203+ let actorA1 = hypervisor.createActor(testVMContainerA.typeId)
204204
205205 const message0 = new Message({
206206 funcRef: actorA0.module.main,
207207 funcArguments: [actorB.module.main]
@@ -254,10 +254,10 @@
254254 const hypervisor = new Hypervisor(tree)
255255 hypervisor.registerContainer(testVMContainerA)
256256 hypervisor.registerContainer(testVMContainerB)
257257
258- let {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
259- let {module: moduleA} = await hypervisor.createActor(testVMContainerA.typeId)
258+ let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
259+ let {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId)
260260 const message = new Message({
261261 funcRef: moduleA.main,
262262 funcArguments: [moduleB.main]
263263 })
@@ -277,9 +277,9 @@
277277 })
278278
279279 class testVMContainerA extends BaseContainer {
280280 async start (funcRef) {
281- const {module} = await this.actor.createActor(testVMContainerB.typeId)
281+ const {module} = this.actor.createActor(testVMContainerB.typeId)
282282 const message = new Message({
283283 funcRef: module.main,
284284 funcArguments: [{
285285 name: 'main',
@@ -306,9 +306,9 @@
306306 const hypervisor = new Hypervisor(tree)
307307 hypervisor.registerContainer(testVMContainerA)
308308 hypervisor.registerContainer(testVMContainerB)
309309
310- const {module} = await hypervisor.createActor(testVMContainerA.typeId)
310+ const {module} = hypervisor.createActor(testVMContainerA.typeId)
311311 await hypervisor.send(new Message({funcRef: module.start}))
312312
313313 const stateRoot = await hypervisor.createStateRoot()
314314 t.deepEquals(stateRoot, expectedState, 'expected root!')
@@ -370,10 +370,10 @@
370370 const hypervisor = new Hypervisor(tree)
371371 hypervisor.registerContainer(testVMContainerA)
372372 hypervisor.registerContainer(testVMContainerB)
373373
374- const {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
375- const {module: moduleA} = await hypervisor.createActor(testVMContainerA.typeId)
374+ const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
375+ const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId)
376376 const message = new Message({
377377 funcRef: moduleA.main,
378378 funcArguments: [moduleB.main]
379379 })
@@ -427,22 +427,22 @@
427427 const hypervisor = new Hypervisor(tree)
428428 hypervisor.registerContainer(testVMContainerA)
429429 hypervisor.registerContainer(testVMContainerB)
430430
431- let {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
431+ let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
432432 hypervisor.send(new Message({
433433 funcRef: moduleB.main,
434434 funcArguments: ['first']
435435 }))
436436
437- const {module: moduleA0} = await hypervisor.createActor(testVMContainerA.typeId)
437+ const {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId)
438438
439439 hypervisor.send(new Message({
440440 funcRef: moduleA0.main,
441441 funcArguments: [moduleB.main, 'second']
442442 }))
443443
444- const {module: moduleA1} = await hypervisor.createActor(testVMContainerA.typeId)
444+ const {module: moduleA1} = hypervisor.createActor(testVMContainerA.typeId)
445445 hypervisor.send(new Message({
446446 funcRef: moduleA1.main,
447447 funcArguments: [moduleB.main, 'third']
448448 }))
@@ -497,10 +497,10 @@
497497 const hypervisor = new Hypervisor(tree)
498498 hypervisor.registerContainer(testVMContainerA)
499499 hypervisor.registerContainer(testVMContainerB)
500500
501- const {module: moduleB} = await hypervisor.createActor(testVMContainerB.typeId)
502- const {module: moduleA} = await hypervisor.createActor(testVMContainerA.typeId)
501+ const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
502+ const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId)
503503
504504 const message = new Message({
505505 funcRef: moduleA.main,
506506 funcArguments: [moduleB.main]
@@ -547,9 +547,9 @@
547547
548548 const refernces = []
549549 let _numOfActors = numOfActors
550550 while (_numOfActors--) {
551- const {module} = await hypervisor.createActor(BenchmarkContainer.typeId)
551+ const {module} = hypervisor.createActor(BenchmarkContainer.typeId)
552552 refernces.push(module.main)
553553 }
554554 _numOfActors = numOfActors
555555 let msgs = []
wasmContainer.jsView
@@ -87,10 +87,10 @@
8787 modRef
8888 }
8989 }
9090
91- static async onCreation (unverifiedWasm, id, tree) {
92- let {modRef} = this.createModule(unverifiedWasm, id)
91+ static onCreation (unverifiedWasm, id, tree) {
92+ const {modRef} = this.createModule(unverifiedWasm, id)
9393 return modRef
9494 }
9595
9696 getInterface (funcRef) {
@@ -142,9 +142,10 @@
142142 }
143143 },
144144 module: {
145145 new: dataRef => {
146-
146+ const mod = this.actor.createActor(dataRef)
147+ return this.refs.add(mod, 'mod')
147148 },
148149 export: (modRef, bufRef) => {
149150 const mod = this.refs.get(modRef, 'mod')
150151 let name = this.refs.get(bufRef, 'buf')

Built with git-ssb-web