git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit db8690a1d23bec923250cdf8757fc222ee7236b3

added checks for bound names

wanderer committed on 6/3/2017, 7:05:48 PM
Parent: 6496226a003a3eb1845cd6d43c4cdde5fca7b665

Files changed

portManager.jschanged
tests/index.jschanged
portManager.jsView
@@ -51,22 +51,22 @@
5151 */
5252 async start () {
5353 // skip the root, since it doesn't have a parent
5454 if (this.parentPort !== undefined) {
55- this._bindRef(this.parentPort, ENTRY)
55 + this._bindHandle(this.parentPort, ENTRY)
5656 }
5757
5858 // map ports to thier id's
5959 this.ports = await this.hypervisor.graph.get(this.state, 'ports')
6060 Object.keys(this.ports).map(name => {
6161 const port = this.ports[name]
62- this._bindRef(port, name)
62 + this._bindHandle(port, name)
6363 })
6464 }
6565
66- _bindRef (portRef, name) {
66 + _bindHandle (portHandle, name) {
6767 const port = new Port(name)
68- this._portMap.set(portRef, port)
68 + this._portMap.set(portHandle, port)
6969 }
7070
7171 /**
7272 * binds a port to a name
@@ -75,12 +75,14 @@
7575 */
7676 bind (port, name) {
7777 if (this.isBound(port)) {
7878 throw new Error('cannot bind a port that is already bound')
79 + } else if (this.ports[name]) {
80 + throw new Error('cannot bind port to a name that is alread bound')
7981 }
8082 // save the port instance
8183 this.ports[name] = port
82- this._bindRef(port, name)
84 + this._bindHandle(port, name)
8385 }
8486
8587 /**
8688 * unbinds a port given its name
@@ -165,16 +167,8 @@
165167 })
166168 }
167169
168170 /**
169- * creates a copy of a port given a port referance
170- * @param {Object} port - the port to copy
171- */
172- copy (port, type = port.type) {
173- return this._createPortObject(port.type, port.link)
174- }
175-
176- /**
177171 * waits till all ports have reached a threshold tick count
178172 * @param {Integer} threshold - the number of ticks to wait
179173 * @param {Object} fromPort - the port requesting the wait
180174 * @param {Array} ports - the ports to wait on
tests/index.jsView
@@ -668,22 +668,10 @@
668668 const foundThird = await hypervisor.getInstanceByPath(root, 'first/second/third')
669669 t.equals(third, foundThird, 'should find by path')
670670 })
671671
672- tape('copy ports', async t => {
673- t.plan(1)
674- const hypervisor = new Hypervisor(node.dag)
675- hypervisor.registerContainer('base', BaseContainer)
676-
677- const root = await hypervisor.createInstance('base')
678- let port = root.ports.create('base')
679- let port2 = root.ports.copy(port)
680-
681- t.equals(port2.type, port.type, 'should copy port type')
682- })
683-
684672 tape('checking ports', async t => {
685- t.plan(4)
673 + t.plan(5)
686674 const hypervisor = new Hypervisor(node.dag)
687675 hypervisor.registerContainer('base', BaseContainer)
688676
689677 const root = await hypervisor.createInstance('base')
@@ -705,8 +693,15 @@
705693 } catch (e) {
706694 t.pass('should thow if binding an already bound port')
707695 }
708696
697 + try {
698 + let port2 = root.ports.create('base')
699 + root.ports.bind(port2, 'test')
700 + } catch (e) {
701 + t.pass('should thow if binding an already bound name')
702 + }
703 +
709704 root.ports.unbind('test')
710705 const message = root.createMessage({ports: [port]})
711706 t.equals(message.ports[0], port, 'should create a message if the port is unbound')
712707 })

Built with git-ssb-web