Merge branch 'fix-for-2348' of https://github.com/nazar-pc/polymer into nazar-pc-fix-for-2348

# Conflicts:
#	test/unit/configure.html

+ use hasOwnProperty check; benchmarking indicates perf is ok.
+ refine test.
This commit is contained in:
Steven Orvell 2016-02-12 16:58:19 -08:00
commit d99e6939d6
2 changed files with 34 additions and 2 deletions

View File

@ -114,8 +114,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_configureProperties: function(properties, config) {
for (var i in properties) {
var c = properties[i];
// don't accept undefined values
if (c.value !== undefined) {
// Allow properties set before upgrade on the instance
// 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 (this.hasOwnProperty(i)) {
config[i] = this[i];
delete this[i];
} else if (c.value !== undefined) {
var value = c.value;
if (typeof value == 'function') {
// pass existing config values (this._config) to value function

View File

@ -103,6 +103,32 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
});
test('pre-register property assignment does not break getters and setters', function() {
var x = document.createElement('x-late-register');
document.body.appendChild(x);
// set property
x.shouldChange = '1';
// now register element
Polymer({
is: 'x-late-register',
properties: {
shouldChange : {
observer: 'shouldChangeCallback',
type: String
}
},
shouldChangeCallback: function() {
this.textContent = this.shouldChange;
}
});
CustomElements.takeRecords();
assert.equal(x.shouldChange, '1');
assert.equal(x.shouldChange, x.textContent);
x.shouldChange = '2';
assert.equal(x.shouldChange, '2');
assert.equal(x.shouldChange, x.textContent);
document.body.removeChild(x);
});
});
</script>