tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

parser-constructs-custom-element-in-document-write.html (1454B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Custom Elements: Changes to the HTML parser</title>
      5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      6 <meta name="assert" content="HTML parser must construct custom elements inside document.write">
      7 <link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-token">
      8 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
      9 <link rel="help" href="https://html.spec.whatwg.org/#document.write()">
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 </head>
     13 <body>
     14 <div id="log"></div>
     15 <script>
     16 
     17 var numberOfChildNodesInConnectedCallback = 0;
     18 
     19 class MyCustomElement extends HTMLElement {
     20    connectedCallback() {
     21        numberOfChildNodesInConnectedCallback = this.childNodes.length;
     22    }
     23 }
     24 customElements.define('my-custom-element', MyCustomElement);
     25 
     26 document.write('<my-custom-element>hello <b>world</b></my-custom-element>');
     27 
     28 test(function () {
     29    var instance = document.querySelector('my-custom-element');
     30 
     31    assert_true(instance instanceof HTMLElement);
     32    assert_true(instance instanceof MyCustomElement);
     33 
     34 }, 'HTML parser must instantiate custom elements inside document.write');
     35 
     36 test(function () {
     37  assert_equals(numberOfChildNodesInConnectedCallback, 0);
     38 
     39 }, 'HTML parser should call connectedCallback before appending child nodes inside document.write');
     40 
     41 </script>
     42 </body>
     43 </html>