tor-browser

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

parser-fallsback-to-unknown-element.html (4080B)


      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 fallback to creating a HTMLUnknownElement when a custom element construction fails">
      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 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 </head>
     12 <body>
     13 <div id="log"></div>
     14 <script>
     15 
     16 setup({allow_uncaught_exception:true});
     17 
     18 class ReturnsTextNode extends HTMLElement {
     19    constructor() {
     20        super();
     21        return document.createTextNode('some text');
     22    }
     23 };
     24 customElements.define('returns-text', ReturnsTextNode);
     25 
     26 class ReturnsNonElementObject extends HTMLElement {
     27    constructor() {
     28        super();
     29        return {};
     30    }
     31 };
     32 customElements.define('returns-non-element-object', ReturnsNonElementObject);
     33 
     34 class LacksSuperCall extends HTMLElement {
     35    constructor() { }
     36 };
     37 customElements.define('lacks-super-call', LacksSuperCall);
     38 
     39 class ThrowsException extends HTMLElement {
     40    constructor() {
     41        throw 'Bad';
     42    }
     43 };
     44 customElements.define('throws-exception', ThrowsException);
     45 
     46 </script>
     47 <returns-text></returns-text>
     48 <returns-non-element-object></returns-non-element-object>
     49 <lacks-super-call></lacks-super-call>
     50 <throws-exception></throws-exception>
     51 <script>
     52 
     53 test(function () {
     54    var instance = document.querySelector('returns-text');
     55 
     56    assert_false(instance instanceof ReturnsTextNode, 'HTML parser must NOT instantiate a custom element when the constructor returns a Text node');
     57    assert_true(instance instanceof HTMLElement, 'The fallback element created by HTML parser must be an instance of HTMLElement');
     58    assert_true(instance instanceof HTMLUnknownElement, 'The fallback element created by HTML parser must be an instance of HTMLUnknownElement');
     59 
     60 }, 'HTML parser must create a fallback HTMLUnknownElement when a custom element constructor returns a Text node');
     61 
     62 test(function () {
     63    var instance = document.querySelector('returns-non-element-object');
     64 
     65    assert_false(instance instanceof ReturnsNonElementObject, 'HTML parser must NOT instantiate a custom element when the constructor returns a non-Element object');
     66    assert_true(instance instanceof HTMLElement, 'The fallback element created by HTML parser must be an instance of HTMLElement');
     67    assert_true(instance instanceof HTMLUnknownElement, 'The fallback element created by HTML parser must be an instance of HTMLUnknownElement');
     68 
     69 }, 'HTML parser must create a fallback HTMLUnknownElement when a custom element constructor returns non-Element object');
     70 
     71 test(function () {
     72    var instance = document.querySelector('lacks-super-call');
     73 
     74    assert_false(instance instanceof LacksSuperCall, 'HTML parser must NOT instantiate a custom element when the constructor does not call super()');
     75    assert_true(instance instanceof HTMLElement, 'The fallback element created by HTML parser must be an instance of HTMLElement');
     76    assert_true(instance instanceof HTMLUnknownElement, 'The fallback element created by HTML parser must be an instance of HTMLUnknownElement');
     77 
     78 }, 'HTML parser must create a fallback HTMLUnknownElement when a custom element constructor does not call super()');
     79 
     80 test(function () {
     81    var instance = document.querySelector('throws-exception');
     82 
     83    assert_false(instance instanceof ThrowsException, 'HTML parser must NOT instantiate a custom element when the constructor throws an exception');
     84    assert_true(instance instanceof HTMLElement, 'The fallback element created by HTML parser must be an instance of HTMLElement');
     85    assert_true(instance instanceof HTMLUnknownElement, 'The fallback element created by HTML parser must be an instance of HTMLUnknownElement');
     86 
     87 }, 'HTML parser must create a fallback HTMLUnknownElement when a custom element constructor throws an exception');
     88 
     89 </script>
     90 </body>
     91 </html>