Skip to content

Commit

Permalink
Restrict early property set to properties that have accessors. This a…
Browse files Browse the repository at this point in the history
…llows users to set properties in `created` which are listed in `properties` but which have no accessor.
  • Loading branch information
Steven Orvell committed Feb 19, 2016
1 parent 667a9b6 commit 4cfb245
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
// to override default values. This allows late upgrade + an early set
// to not b0rk accessors on the prototype.
// Perf testing has shown `hasOwnProperty` to be ok here.
if (!usePolyfillProto && this.hasOwnProperty(i)) {
if (!usePolyfillProto && this.hasOwnProperty(i) &&
this._propertyEffects && this._propertyEffects[i]) {
config[i] = this[i];
delete this[i];
} else if (c.value !== undefined) {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,35 @@
assert.equal(x.shouldChange, x.textContent);
document.body.removeChild(x);
});

test('setting properties in created works with configuration', function() {
// don't test if __proto__ is polyfilled (IE10); cannot be fixed in this case.
if (Polymer.Settings.usePolyfillProto) {
return;
}
var x = document.createElement('x-late-register2');
document.body.appendChild(x);
// now register element
Polymer({
is: 'x-late-register2',
properties: {
a: {
type: Number
},
b: {
value: function() {
return this.a * 2;
}
}
},
created: function() {
this.a = 1;
}
});
CustomElements.takeRecords();
assert.equal(x.b, 2);
document.body.removeChild(x);
});
});

</script>
Expand Down

0 comments on commit 4cfb245

Please sign in to comment.