Skip to content

Commit

Permalink
Merge pull request #4541 from Polymer/4540-kschaaf-lazy-default
Browse files Browse the repository at this point in the history
Guard against overwriting bound values with hasOwnProperty. Fixes #4540
  • Loading branch information
Steve Orvell authored Apr 18, 2017
2 parents ad224e4 + 4c02374 commit c6c93c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,17 @@
}
for (let p in p$) {
let info = p$[p];
if (!this._isPropertyPending(p)) {
// Don't set default value if there is already an own property, which
// happens when a `properties` property with default but no effects had
// a property set (e.g. bound) by its host before upgrade
if (!this.hasOwnProperty(p)) {
let value = typeof info.value == 'function' ?
info.value.call(this) :
info.value;
// Set via `_setProperty` if there is an accessor, to enable
// initializing readOnly property defaults
if (this._hasAccessor(p)) {
this._setProperty(p, value)
this._setPendingProperty(p, value, true);
} else {
this[p] = value;
}
Expand Down
7 changes: 6 additions & 1 deletion test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@
defaultUsesNoEffectProp: {
type: Number
},
boundNoEffectProp: {
type: Number,
value: 5
},
prop: {
value: 'lazy',
observer: 'propChanged'
Expand All @@ -294,7 +298,7 @@

<dom-module id="x-config-lazy-host">
<template>
<x-config-lazy id="lazy" prop="{{foo}}" read-only-prop="{{foo}}" had-attr-prop="attrValue"></x-config-lazy>
<x-config-lazy id="lazy" prop="{{foo}}" read-only-prop="{{foo}}" had-attr-prop="attrValue" bound-no-effect-prop="{{foo}}"></x-config-lazy>
</template>
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -489,6 +493,7 @@
Polymer(window.XConfigLazy);
assert.equal(el.$.lazy.noEffectProp, 1);
assert.equal(el.$.lazy.defaultUsesNoEffectProp, 2);
assert.equal(el.$.lazy.boundNoEffectProp, 'foo');
assert.equal(el.$.lazy.prop, 'foo');
assert.isTrue(el.$.lazy.propChanged.calledOnce);
assert.equal(el.$.lazy.readOnlyProp, 'readOnly');
Expand Down

0 comments on commit c6c93c8

Please sign in to comment.