Skip to content

Commit

Permalink
Merge pull request #494 from sethkinast/revert-prototype-lookup-preve…
Browse files Browse the repository at this point in the history
…ntion

Revert "Merge pull request #472 from jimmyhchan/OPP"  This will allow dust references to look up the object's prototype chain again.
  • Loading branch information
prashn64 committed Sep 2, 2014
2 parents b96223c + 397ff7c commit d601153
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
32 changes: 10 additions & 22 deletions lib/dust.js
Expand Up @@ -10,27 +10,10 @@
EMPTY_FUNC = function() {},
logger = {},
originalLog,
loggerContext,
hasOwnProperty = Object.prototype.hasOwnProperty,
getResult;
loggerContext;

dust.debugLevel = NONE;

/**
* Given an object and a key, return the value. Use this instead of obj[key] in order to:
* prevent looking up the prototype chain
* fail nicely when the object is falsy
* @param {Object} obj the object to inspect
* @param {String} key the name of the property to resolve
* @return {*} the resolved value
*/
getResult = function(obj, key) {
if (obj && hasOwnProperty.call(obj, key)) {
return obj[key];
}
};


// Try to find the console in global scope
if (root && root.console && root.console.log) {
loggerContext = root.console;
Expand Down Expand Up @@ -325,7 +308,7 @@
while (ctx) {
if (ctx.isObject) {
ctxThis = ctx.head;
value = getResult(ctx.head, first);
value = ctx.head[first];
if (value !== undefined) {
break;
}
Expand All @@ -336,16 +319,21 @@
if (value !== undefined) {
ctx = value;
} else {
ctx = getResult(this.global, first);
ctx = this.global ? this.global[first] : undefined;
}
} else if (ctx) {
// if scope is limited by a leading dot, don't search up the tree
ctx = getResult(ctx.head, first);
if(ctx.head) {
ctx = ctx.head[first];
} else {
//context's head is empty, value we are searching for is not defined
ctx = undefined;
}
}

while (ctx && i < len) {
ctxThis = ctx;
ctx = getResult(ctx, down[i]);
ctx = ctx[down[i]];
i++;
}
}
Expand Down
7 changes: 0 additions & 7 deletions test/jasmine-test/spec/coreTests.js
Expand Up @@ -698,13 +698,6 @@ var coreTests = [
context: { foo: {bar: "Hello!"} },
expected: "Hello!",
message: "should test an object path"
},
{
name: "path should not look in the prototype",
source: "{arr.sort}",
context: { arr: [5, 3, 2, 1, 4]},
expected: '',
message: "should not be looking in the prototype"
}
]
},
Expand Down

0 comments on commit d601153

Please sign in to comment.