Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:Flotype/now

  • Loading branch information...
commit 8f2eba060885b408cfa0593f84b2c905ea58c3a7 2 parents c4afb1e + 0dda0f5
@ericz ericz authored
Showing with 20 additions and 6 deletions.
  1. +20 −6 lib/wrap.js
View
26 lib/wrap.js
@@ -5,17 +5,23 @@ exports.wrap = function (store, sessions) {
var taintedFqns = {};
var set = store ? (store.set || store.save).bind(store) : null;
- return Proxy.create({
+ var theProxy = Proxy.create({
get : function (recv, name) {
if (name === 'toJSON' && !sessions.hasOwnProperty(name)) {
return function () { return sessions }
}
- else return wrapRoot(name, sessions[name], "[\""+name+"\"]")
+ else {
+ var returnObj = wrapRoot(name, sessions[name], '["'+name+'"]', theProxy);
+ if(typeof returnObj === 'function' && sessions.hasOwnProperty(name)){
+ returnObj = returnObj.bind({now: theProxy})
+ }
+ return returnObj;
+ }
},
set : function (recv, name, value) {
sessions[name] = value;
update(name, "[\""+name+"\"]");
- return wrapRoot(name, value, name);
+ return wrapRoot(name, value, name, theProxy);
},
enumerate : function () {
return Object.keys(sessions)
@@ -55,7 +61,7 @@ exports.wrap = function (store, sessions) {
taintedFqns[key][fqn] = (val !== null && val !== undefined && val.hasOwnProperty('toFqn'))? val.toFqn() : val;
}
- function wrapRoot (rootKey, obj, path) {
+ function wrapRoot (rootKey, obj, path, nowObject) {
if (typeof obj !== 'object' || obj === null) return obj;
var setTaint = update.bind({}, rootKey);
var wrap = wrapRoot.bind({}, rootKey);
@@ -66,7 +72,13 @@ exports.wrap = function (store, sessions) {
return function () { return obj };
} else if(name === 'toFqn' && !obj.hasOwnProperty(name)) {
return function () { return {$ref: '$'+path} };
- } else return wrap(obj[name], path+"[\""+ name+"\"]");
+ } else {
+ var returnObj = obj[name];
+ if(typeof returnObj === 'function'){
+ returnObj = returnObj.bind({now: nowObject});
+ }
+ return wrap(returnObj, path+"[\""+ name+"\"]");
+ }
},
set : function (recv, name, value) {
obj[name] = value;
@@ -90,6 +102,8 @@ exports.wrap = function (store, sessions) {
},
}, Object.getPrototypeOf(obj))
}
+
+ return theProxy;
};
function convertToDotNotation(lameFqn){
@@ -110,4 +124,4 @@ function getVarAtFqn(fqn, scope){
}
return currVar;
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.