File: perform-microtask-checkpoint-before-construction-xml-parser.xhtml

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (81 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (17)
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
76
77
78
79
80
81
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Custom Elements: create an element for a token must perform a microtask checkpoint</title>
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org" />
<meta name="assert" content="When the HTML parser creates an element for a token, it must perform a microtask checkpoint before invoking the constructor" />
<meta name="help" content="https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token" />
<meta name="help" content="https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/custom-elements-helpers.js"></script>
</head>
<body>
<div id="log"></div>
<script>
<![CDATA[

async function construct_custom_element_in_parser(test, markup)
{
    const window = await create_window_in_test_async(test, 'application/xml', `<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body><script>
class SomeElement extends HTMLElement {
    constructor() {
        super();
        window.recordsListInConstructor = recordsList.map((records) => records.slice(0));
    }
}
customElements.define('some-element', SomeElement);

const recordsList = [];
const observer = new MutationObserver((records) => {
    recordsList.push(records);
});
observer.observe(document.body, {childList: true, subtree: true});

window.onload = () => {
    window.recordsListInDOMContentLoaded = recordsList.map((records) => records.slice(0));
}

</scr` + `ipt>${markup}</body></html>`);
    return window;
}

promise_test(async function () {
    const contentWindow = await construct_custom_element_in_parser(this, '<b><some-element></some-element></b>');
    const contentDocument = contentWindow.document;

    let recordsList = contentWindow.recordsListInConstructor;
    assert_true(Array.isArray(recordsList));
    assert_equals(recordsList.length, 1);
    assert_true(Array.isArray(recordsList[0]));
    assert_equals(recordsList[0].length, 1);
    let record = recordsList[0][0];
    assert_equals(record.type, 'childList');
    assert_equals(record.target, contentDocument.body);
    assert_equals(record.previousSibling, contentDocument.querySelector('script'));
    assert_equals(record.nextSibling, null);
    assert_equals(record.removedNodes.length, 0);
    assert_equals(record.addedNodes.length, 1);
    assert_equals(record.addedNodes[0], contentDocument.querySelector('b'));

    recordsList = contentWindow.recordsListInDOMContentLoaded;
    assert_true(Array.isArray(recordsList));
    assert_equals(recordsList.length, 2);
    assert_true(Array.isArray(recordsList[1]));
    assert_equals(recordsList[1].length, 1);
    record = recordsList[1][0];
    assert_equals(record.type, 'childList');
    assert_equals(record.target, contentDocument.querySelector('b'));
    assert_equals(record.previousSibling, null);
    assert_equals(record.nextSibling, null);
    assert_equals(record.removedNodes.length, 0);
    assert_equals(record.addedNodes.length, 1);
    assert_equals(record.addedNodes[0], contentDocument.querySelector('some-element'));
}, 'XML parser must perform a microtask checkpoint before constructing a custom element');

]]>
</script>
</body>
</html>