mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
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
This commit is contained in:
+13
-6
@@ -34,7 +34,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
beforeRegister: true,
|
||||
registered: true,
|
||||
attributeChanged: true,
|
||||
behaviors: true
|
||||
behaviors: true,
|
||||
_noAccessors: true
|
||||
};
|
||||
|
||||
const excludeOnBehaviors = Object.assign({
|
||||
@@ -45,13 +46,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
}, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user