File: parser-uses-constructed-element.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (75 lines) | stat: -rw-r--r-- 3,554 bytes parent folder | download | duplicates (32)
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>