tor-browser

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

Construct.html (2247B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      5 <link rel="help" href="https://github.com/whatwg/html/issues/10854">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10 <script>
     11 
     12 test(() => {
     13    class ABElement extends HTMLElement { };
     14    const scopedRegistry = new CustomElementRegistry;
     15    scopedRegistry.define('a-b', ABElement);
     16    assert_throws_js(TypeError, () => new ABElement);
     17 }, 'A constructor with only a scoped custom element registry definition should fail upon construction');
     18 
     19 test(() => {
     20    class CElement extends HTMLElement { };
     21    const scopedRegistry = new CustomElementRegistry;
     22    scopedRegistry.define('scoped-c', CElement);
     23    customElements.define('global-c', CElement);
     24    const cElement = new CElement;
     25    assert_equals(cElement.localName, 'global-c');
     26 }, 'A constructor uses the global registry to create an element');
     27 
     28 test(() => {
     29    let fgElement;
     30    let hiElement;
     31    class DEElement extends HTMLElement {
     32        constructor() {
     33            fgElement = document.createElement('f-g', {customElementRegistry: scopedRegistry2});
     34            super();
     35            hiElement = document.createElement('h-i', {customElementRegistry: scopedRegistry2});
     36        }
     37    };
     38    class FGElement extends HTMLElement { }
     39    class HIElement extends HTMLElement { }
     40    const scopedRegistry1 = new CustomElementRegistry;
     41    scopedRegistry1.define('d-e', DEElement);
     42    const scopedRegistry2 = new CustomElementRegistry;
     43    scopedRegistry2.define('f-g', FGElement);
     44    scopedRegistry2.define('h-i', HIElement);
     45 
     46    const deElement = document.createElement('d-e', {customElementRegistry: scopedRegistry1});
     47    assert_true(deElement instanceof DEElement);
     48    assert_equals(deElement.customElementRegistry, scopedRegistry1);
     49    assert_true(fgElement instanceof FGElement);
     50    assert_equals(fgElement.customElementRegistry, scopedRegistry2);
     51    assert_true(hiElement instanceof HIElement);
     52    assert_equals(hiElement.customElementRegistry, scopedRegistry2);
     53 }, 'A constructor creating an element from another registry before or after super call should work');
     54 
     55 </script>
     56 </body>
     57 </html>