From db4a0552774f844ded8e01dc0ab04c2092716fa1 Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Mon, 13 Jan 2014 16:24:30 -0800 Subject: [PATCH] protect against undefined context in Member.valueFn R=arv BUG=https://github.com/Polymer/polymer-expressions/issues/19 Review URL: https://codereview.appspot.com/51750043 --- src/polymer-expressions.js | 4 ++-- tests/tests.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/polymer-expressions.js b/src/polymer-expressions.js index 21ac3f6..d1772a1 100644 --- a/src/polymer-expressions.js +++ b/src/polymer-expressions.js @@ -146,13 +146,13 @@ if (path) { if (observer) observer.addPath(context, path); - return context[property.name]; + return path.getValueFrom(context); } var propName = property(model, observer); if (observer) observer.addPath(context, propName); - return context[propName]; + return context ? context[propName] : undefined; }; } return this.valueFn_; diff --git a/tests/tests.js b/tests/tests.js index dcdf170..5aa5859 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1602,6 +1602,24 @@ suite('PolymerExpressions', function() { }); }); + // https://github.com/Polymer/polymer-expressions/issues/19 + test('issue-19', function(done) { + var div = createTestHtml( + ''); + + var model = {}; + + recursivelySetTemplateModel(div, model); + + then(function() { + var target = div.childNodes[1]; + + done(); + }); + }); + test('Non-model path expressions', function() { assert.isFalse(getExpression_('a + b').nonModelPath); assert.isFalse(getExpression_('a + b > 3 + hello["kitty"]').nonModelPath);