From 397ff7cbfb8c1f9f781f991ee8846be8494aa5e5 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Thu, 28 Aug 2014 13:32:40 -0700 Subject: [PATCH] Revert "Merge pull request #472 from jimmyhchan/OPP" This reverts commit dcc3d350214ab270bffe3a957f3b438b429651b4, reversing changes made to ad2d39fd4f2e29223d27b94a19512f2bab45d05e. --- lib/dust.js | 32 +++++++++-------------------- test/jasmine-test/spec/coreTests.js | 7 ------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/dust.js b/lib/dust.js index 62accd7e..86a02e48 100644 --- a/lib/dust.js +++ b/lib/dust.js @@ -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; @@ -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; } @@ -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++; } } diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index dfd220f9..ec4b2479 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -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" } ] },