tor-browser

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

custom-element.window.js (1168B)


      1 // The document open steps have:
      2 //
      3 // 2. If document's throw-on-dynamic-markup-insertion counter is greater than
      4 //    0, then throw an "InvalidStateError" DOMException.
      5 //
      6 // The throw-on-dynamic-markup-insertion counter is only incremented when the
      7 // parser creates a custom element, not when createElement is called. Test for
      8 // this.
      9 //
     10 // See: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document-open-steps
     11 
     12 const noError = Symbol("no error");
     13 let err = noError;
     14 
     15 class CustomElement extends HTMLElement {
     16  constructor() {
     17    super();
     18    try {
     19      assert_equals(document.open(), document);
     20    } catch (e) {
     21      err = e;
     22    }
     23  }
     24 }
     25 customElements.define("custom-element", CustomElement);
     26 
     27 test(t => {
     28  err = noError;
     29  document.createElement("custom-element");
     30  assert_equals(err, noError);
     31 }, "document.open() works in custom element constructor for createElement()");
     32 
     33 test(t => {
     34  err = noError;
     35  document.write("<custom-element></custom-element>");
     36  assert_throws_dom("InvalidStateError", () => {
     37    throw err;
     38  });
     39 }, "document.open() is forbidden in custom element constructor when creating element from parser");