Skip to content

Commit 625a166

Browse files
committed
Polymer 2.x version of #5464
1 parent a0b98b9 commit 625a166

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

lib/legacy/class.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@
4747

4848
function copyProperties(source, target, excludeProps) {
4949
const noAccessors = source._noAccessors;
50-
for (let p in source) {
51-
if (!(p in excludeProps)) {
52-
if (noAccessors) {
53-
target[p] = source[p];
54-
} else {
55-
let pd = Object.getOwnPropertyDescriptor(source, p);
56-
if (pd) {
57-
// ensure property is configurable so that a later behavior can
58-
// re-configure it.
59-
pd.configurable = true;
60-
Object.defineProperty(target, p, pd);
61-
}
50+
const propertyNames = Object.getOwnPropertyNames(source);
51+
for (let i = 0; i < propertyNames.length; i++) {
52+
let p = propertyNames[i];
53+
if (p in excludeProps) {
54+
continue;
55+
}
56+
if (noAccessors) {
57+
target[p] = source[p];
58+
} else {
59+
let pd = Object.getOwnPropertyDescriptor(source, p);
60+
if (pd) {
61+
// ensure property is configurable so that a later behavior can
62+
// re-configure it.
63+
pd.configurable = true;
64+
Object.defineProperty(target, p, pd);
6265
}
6366
}
6467
}

test/runner.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@
8282
'unit/disable-upgrade.html',
8383
'unit/shady-unscoped-style.html',
8484
'unit/html-tag.html',
85-
'unit/legacy-data.html'
85+
'unit/legacy-data.html',
8686
// 'unit/multi-style.html'
87+
'unit/class-properties.html'
8788
];
8889

8990
function combinations(suites, flags) {

test/unit/class-properties.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
5+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
Code distributed by Google as part of the polymer project is also
9+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
-->
11+
<html>
12+
<head>
13+
<meta charset="utf-8">
14+
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
15+
<script src="../../../web-component-tester/browser.js"></script>
16+
<link rel="import" href="../../polymer.html">
17+
</head>
18+
<body>
19+
<script>
20+
class Example {
21+
ready() {}
22+
foo() {}
23+
}
24+
Example.prototype.is = 'x-example';
25+
26+
suite('Polymer function w/Class', function() {
27+
test('Polymer call works with a class', function() {
28+
assert.doesNotThrow(() => Polymer(Example.prototype));
29+
});
30+
test('methods are copied from class input', function() {
31+
const def = customElements.get('x-example');
32+
assert(def.prototype.ready, 'ready should be defined');
33+
assert(def.prototype.foo, 'foo should be defined');
34+
});
35+
});
36+
</script>
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)