From fbf827d9c7706c64ff09adcba1c67f61f33f7222 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 9 Nov 2018 18:18:24 -0800 Subject: [PATCH] Behavior property copying fixes * ensure element has `is` on prototype early as this is sometimes checked in user code. * ensure properties copied onto elements from info/behaviors are forced to configurable so they can be re-configured by later behaviors. * add `_noAccessors` optimization for faster property copying --- lib/legacy/class.html | 19 +++++++++++++------ test/unit/behaviors.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/legacy/class.html b/lib/legacy/class.html index bed2211d53..ad6817a7fb 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -34,7 +34,8 @@ beforeRegister: true, registered: true, attributeChanged: true, - behaviors: true + behaviors: true, + _noAccessors: true }; const excludeOnBehaviors = Object.assign({ @@ -45,13 +46,19 @@ }, excludeOnInfo); function copyProperties(source, target, excludeProps) { + const noAccessors = source._noAccessors; for (let p in source) { - // NOTE: cannot copy `excludeProps` methods onto prototype at least because - // `super.ready` must be called and is not included in the user fn. if (!(p in excludeProps)) { - let pd = Object.getOwnPropertyDescriptor(source, p); - if (pd) { - Object.defineProperty(target, p, pd); + if (noAccessors) { + target[p] = source[p]; + } else { + let pd = Object.getOwnPropertyDescriptor(source, p); + if (pd) { + // ensure property is configurable so that a later behavior can + // re-configure it. + pd.configurable = true; + Object.defineProperty(target, p, pd); + } } } } diff --git a/test/unit/behaviors.html b/test/unit/behaviors.html index 4cafee3c28..b08dfd5dee 100644 --- a/test/unit/behaviors.html +++ b/test/unit/behaviors.html @@ -378,6 +378,20 @@ behaviors: [window.BehaviorA] }); + Polymer({ + is: 'no-accessors-behavior', + behaviors: [{ + _noAccessors: true, + properties: { + nug: String + }, + foo: function() {}, + bar: true + }], + _noAccessors: true, + zot: 'zot' + }); + }); @@ -447,6 +461,12 @@ + + + +