Permalink
Browse files

- added several convenience methods for Scope

  • Loading branch information...
1 parent e75665d commit ce33055702151f6338a73afaf8ae2018ffb1037b Nickolay Platonov committed Dec 1, 2010
Showing with 31 additions and 7 deletions.
  1. +31 −7 lib/KiokuJS/Scope.js
View
@@ -53,7 +53,7 @@ Class('KiokuJS.Scope', {
// XXX proxy will currently only work, when linking with the `shallowLevel` == 0
node.immutable = true
- if (!node.isFirstClass()) node.acquireID(ID)
+ node.acquireID(ID)
this.pinNode(node)
},
@@ -69,43 +69,67 @@ Class('KiokuJS.Scope', {
// },
- // node *must* be live
+ // node *must* be live & have an ID (be first-class)
pinNode : function (node) {
- var nodeID = node.ID
+ if (this.nodePinned(node)) return
// if (!this.hasID(nodeID) || this.hasOwnID(nodeID)) {
if (!node.isLive()) throw "Can pin only live nodes"
+ if (!node.isFirstClass()) throw "Can pin only first-class nodes"
- this.nodesByID[ nodeID ] = node
+ this.nodesByID[ node.ID ] = node
var object = node.getObject()
this.nodesByREFADR[ object.__REFADR__ ] = node
+
+ return node.ID
// } else
// // XXX no proto inheritance already
// this.parent.pinNode(node)
},
unpinNode : function (node) {
- var nodeID = node.ID
+ if (!this.nodePinned(node)) return
// if (this.hasOwnID( nodeID )) {
- if (!node.isLive()) throw "Can unpin only live node"
+ if (!node.isLive()) throw "Can unpin only live nodes"
+ if (!node.isFirstClass()) throw "Can unpin only first-class nodes"
- delete this.nodesByID[ nodeID ]
+ delete this.nodesByID[ node.ID ]
var REFADR = node.getObject().__REFADR__
delete this.nodesByREFADR[ REFADR ]
+
+ return node.ID
// } else
// // XXX no proto inheritance already
// this.parent.unpinNode(node)
},
+
+ pinObject : function (object, ID) {
+ if (this.objectPinned(object)) return
+
+ var node = this.backend.createNodeFromObject(object)
+
+ node.acquireID(ID)
+
+ this.pinNode(node)
+ },
+
+ unpinObject : function (object) {
+ if (!this.objectPinned(object)) return
+
+ this.unpinNode(this.objectToNode(object))
+ },
+
+
unpinID : function (id) {
var node = this.idToNode(id)

0 comments on commit ce33055

Please sign in to comment.