tor-browser

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

cross-realm-callback-report-exception.html (2876B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Exceptions raised in constructors / lifecycle callbacks are reported in their global objects</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <iframe></iframe>
      7 <iframe></iframe>
      8 <iframe></iframe>
      9 <script>
     10 setup({ allow_uncaught_exception: true });
     11 
     12 window.onerror = () => { onerrorCalls.push("top"); };
     13 frames[0].onerror = () => { onerrorCalls.push("frame0"); };
     14 frames[1].onerror = () => { onerrorCalls.push("frame1"); };
     15 frames[2].onerror = () => { onerrorCalls.push("frame2"); };
     16 
     17 const sourceThrowError = `throw new parent.frames[2].Error("PASS")`;
     18 
     19 test(t => {
     20  window.onerrorCalls = [];
     21 
     22  const XFoo = new frames[1].Function(sourceThrowError);
     23  frames[0].customElements.define("x-foo-constructor", XFoo);
     24 
     25  frames[0].document.createElement("x-foo-constructor");
     26  assert_array_equals(onerrorCalls, ["frame1"]);
     27 }, "constructor");
     28 
     29 test(t => {
     30  window.onerrorCalls = [];
     31 
     32  const XFooConnected = class extends frames[0].HTMLElement {};
     33  XFooConnected.prototype.connectedCallback = new frames[1].Function(sourceThrowError);
     34  frames[0].customElements.define("x-foo-connected", XFooConnected);
     35 
     36  const el = frames[0].document.createElement("x-foo-connected");
     37  frames[0].document.body.append(el);
     38 
     39  assert_array_equals(onerrorCalls, ["frame1"]);
     40 }, "connectedCallback");
     41 
     42 test(t => {
     43  window.onerrorCalls = [];
     44 
     45  const XFooDisconnected = class extends frames[0].HTMLElement {};
     46  XFooDisconnected.prototype.disconnectedCallback = new frames[1].Function(sourceThrowError);
     47  frames[0].customElements.define("x-foo-disconnected", XFooDisconnected);
     48 
     49  const el = frames[0].document.createElement("x-foo-disconnected");
     50  frames[0].document.body.append(el);
     51  el.remove();
     52 
     53  assert_array_equals(onerrorCalls, ["frame1"]);
     54 }, "disconnectedCallback");
     55 
     56 test(t => {
     57  window.onerrorCalls = [];
     58 
     59  const XFooAttributeChanged = class extends frames[0].HTMLElement {};
     60  XFooAttributeChanged.observedAttributes = ["foo"];
     61  XFooAttributeChanged.prototype.attributeChangedCallback = new frames[1].Function(sourceThrowError);
     62  frames[0].customElements.define("x-foo-attribute-changed", XFooAttributeChanged);
     63 
     64  const el = frames[0].document.createElement("x-foo-attribute-changed");
     65  frames[0].document.body.append(el);
     66  el.setAttribute("foo", "bar");
     67 
     68  assert_array_equals(onerrorCalls, ["frame1"]);
     69 }, "attributeChangedCallback");
     70 
     71 test(t => {
     72  window.onerrorCalls = [];
     73 
     74  const XFooAdopted = class extends frames[0].HTMLElement {};
     75  XFooAdopted.prototype.adoptedCallback = new frames[1].Function(sourceThrowError);
     76  frames[0].customElements.define("x-foo-adopted", XFooAdopted);
     77 
     78  const el = frames[0].document.createElement("x-foo-adopted");
     79  document.body.append(el);
     80 
     81  assert_array_equals(onerrorCalls, ["frame1"]);
     82 }, "adoptedCallback");
     83 </script>