tor-browser

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

custom-element-exception.html (1034B)


      1 <!DOCTYPE html>
      2 <title>Handling of exceptions in custom element constructors</title>
      3 
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7    setup({allow_uncaught_exception: true});
      8 
      9    window.log = [];
     10    window.addEventListener("error", ev => log.push(ev.error));
     11 
     12    const test_load = async_test(
     13        "Test that exceptions from the constructor of a custom element " +
     14        "inside a module are propagated as expected.\n");
     15    window.addEventListener("load", test_load.step_func_done(ev => {
     16      assert_equals(1, log.length);
     17      const exception = log[0];
     18      assert_true(exception instanceof Error);
     19      assert_equals(exception.message, "custom element error");
     20    }));
     21 </script>
     22 <script type="module">
     23    class XThrower extends HTMLElement {
     24      constructor() {
     25        super();
     26        throw new Error("custom element error");
     27      }
     28    }
     29    customElements.define("x-thrower", XThrower);
     30    document.createElement("x-thrower");
     31 </script>