Skip to content

Commit

Permalink
Merge pull request #3417 from Polymer/nazar-pc-fix-for-2348
Browse files Browse the repository at this point in the history
Nazar-pc fix for #2348
  • Loading branch information
kevinpschaaf committed Feb 13, 2016
2 parents 596b690 + b569ea6 commit 9bdfaca
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/lib/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@
var useNativeCustomElements = (!window.CustomElements ||
window.CustomElements.useNative);

var usePolyfillProto = !useNativeCustomElements && !Object.__proto__;

return {
wantShadow: wantShadow,
hasShadow: hasShadow,
nativeShadow: nativeShadow,
useShadow: useShadow,
useNativeShadow: useShadow && nativeShadow,
useNativeImports: useNativeImports,
useNativeCustomElements: useNativeCustomElements
useNativeCustomElements: useNativeCustomElements,
usePolyfillProto: usePolyfillProto
};
})()
};
Expand Down
15 changes: 12 additions & 3 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->

<script>

(function() {
/*
Process inputs efficiently via a configure lifecycle callback.
Configure is called top-down, host before local dom. Users should
Expand Down Expand Up @@ -41,6 +41,8 @@
directly (on-foo-changed).
*/

var usePolyfillProto = Polymer.Settings.usePolyfillProto;

Polymer.Base._addFeature({

// storage for configuration
Expand Down Expand Up @@ -114,8 +116,14 @@
_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 (!usePolyfillProto && 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
Expand Down Expand Up @@ -217,4 +225,5 @@

});

})();
</script>
30 changes: 30 additions & 0 deletions test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
});

test('pre-register property assignment does not break getters and setters', 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-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>
Expand Down

0 comments on commit 9bdfaca

Please sign in to comment.