From 4cfb245402cae818f5f0e44d8784fb889860544c Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 18 Feb 2016 16:42:57 -0800 Subject: [PATCH] Restrict early property set to properties that have accessors. This allows users to set properties in `created` which are listed in `properties` but which have no accessor. --- src/standard/configure.html | 3 ++- test/unit/configure.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/standard/configure.html b/src/standard/configure.html index b994b00367..378d25729d 100644 --- a/src/standard/configure.html +++ b/src/standard/configure.html @@ -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) { diff --git a/test/unit/configure.html b/test/unit/configure.html index dc125a89a0..9c438b4022 100644 --- a/test/unit/configure.html +++ b/test/unit/configure.html @@ -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); + }); });