Skip to content

Commit

Permalink
Merge pull request #5469 from Polymer/2.x-copy-properties
Browse files Browse the repository at this point in the history
Polymer 2.x version of #5464
  • Loading branch information
dfreedm authored Jan 29, 2019
2 parents a0b98b9 + 625a166 commit d1f36d8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@

function copyProperties(source, target, excludeProps) {
const noAccessors = source._noAccessors;
for (let p in source) {
if (!(p in excludeProps)) {
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);
}
const propertyNames = Object.getOwnPropertyNames(source);
for (let i = 0; i < propertyNames.length; i++) {
let p = propertyNames[i];
if (p in excludeProps) {
continue;
}
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);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
'unit/disable-upgrade.html',
'unit/shady-unscoped-style.html',
'unit/html-tag.html',
'unit/legacy-data.html'
'unit/legacy-data.html',
// 'unit/multi-style.html'
'unit/class-properties.html'
];

function combinations(suites, flags) {
Expand Down
38 changes: 38 additions & 0 deletions test/unit/class-properties.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>
<script>
class Example {
ready() {}
foo() {}
}
Example.prototype.is = 'x-example';

suite('Polymer function w/Class', function() {
test('Polymer call works with a class', function() {
assert.doesNotThrow(() => Polymer(Example.prototype));
});
test('methods are copied from class input', function() {
const def = customElements.get('x-example');
assert(def.prototype.ready, 'ready should be defined');
assert(def.prototype.foo, 'foo should be defined');
});
});
</script>
</body>
</html>

0 comments on commit d1f36d8

Please sign in to comment.