1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements: HTML parser must construct a custom element instead of upgrading</title>
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
<meta name="assert" content="HTML parser must construct a custom element instead of upgrading">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-token">
<link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
</head>
<body>
<div id="log"></div>
<script>
let anotherElementCreatedBeforeSuperCall = undefined;
let elementCreatedBySuperCall = undefined;
let shouldCreateElementBeforeSuperCall = true;
class InstantiatesItselfBeforeSuper extends HTMLElement {
constructor() {
if (shouldCreateElementBeforeSuperCall) {
shouldCreateElementBeforeSuperCall = false;
anotherElementCreatedBeforeSuperCall = new InstantiatesItselfBeforeSuper();
}
super();
elementCreatedBySuperCall = this;
}
};
customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
let shouldCreateAnotherInstance = true;
let anotherInstance = undefined;
let firstInstance = undefined;
class ReturnsAnotherInstance extends HTMLElement {
constructor() {
super();
if (shouldCreateAnotherInstance) {
shouldCreateAnotherInstance = false;
firstInstance = this;
anotherInstance = new ReturnsAnotherInstance;
return anotherInstance;
} else
return this;
}
};
customElements.define('returns-another-instance', ReturnsAnotherInstance);
</script>
<instantiates-itself-before-super></instantiates-itself-before-super>
<returns-another-instance></returns-another-instance>
<script>
test(function () {
var instance = document.querySelector('instantiates-itself-before-super');
assert_true(instance instanceof InstantiatesItselfBeforeSuper, 'HTML parser must insert the synchronously constructed custom element');
assert_equals(instance, elementCreatedBySuperCall, 'HTML parser must insert the element returned by the custom element constructor');
assert_not_equals(instance, anotherElementCreatedBeforeSuperCall, 'HTML parser must not insert another instance of the custom element created before super() call');
assert_equals(anotherElementCreatedBeforeSuperCall.parentNode, null, 'HTML parser must not insert another instance of the custom element created before super() call');
}, 'HTML parser must use the returned value of the custom element constructor instead of the one created before super() call');
test(function () {
var instance = document.querySelector('returns-another-instance');
assert_true(instance instanceof ReturnsAnotherInstance, 'HTML parser must insert the synchronously constructed custom element');
assert_equals(instance, anotherInstance, 'HTML parser must insert the element returned by the custom element constructor');
assert_not_equals(instance, firstInstance, 'HTML parser must not insert the element created by super() call if the constructor returned another element');
assert_equals(firstInstance.parentNode, null, 'HTML parser must not insert the element created by super() call if the constructor returned another element');
}, 'HTML parser must use the returned value of the custom element constructor instead using the one created in super() call');
</script>
</body>
</html>
|