summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/cross-realm-callback-report-exception.html
blob: 3067a7af9d273c3a027ccf978b51b07cc8c82201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!doctype html>
<meta charset=utf-8>
<title>Exceptions raised in constructors / lifecycle callbacks are reported in their global objects</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
<script>
setup({ allow_uncaught_exception: true });

window.onerror = () => { onerrorCalls.push("top"); };
frames[0].onerror = () => { onerrorCalls.push("frame0"); };
frames[1].onerror = () => { onerrorCalls.push("frame1"); };
frames[2].onerror = () => { onerrorCalls.push("frame2"); };

const sourceThrowError = `throw new parent.frames[2].Error("PASS")`;

test(t => {
  window.onerrorCalls = [];

  const XFoo = new frames[1].Function(sourceThrowError);
  frames[0].customElements.define("x-foo-constructor", XFoo);

  frames[0].document.createElement("x-foo-constructor");
  assert_array_equals(onerrorCalls, ["frame1"]);
}, "constructor");

test(t => {
  window.onerrorCalls = [];

  const XFooConnected = class extends frames[0].HTMLElement {};
  XFooConnected.prototype.connectedCallback = new frames[1].Function(sourceThrowError);
  frames[0].customElements.define("x-foo-connected", XFooConnected);

  const el = frames[0].document.createElement("x-foo-connected");
  frames[0].document.body.append(el);

  assert_array_equals(onerrorCalls, ["frame1"]);
}, "connectedCallback");

test(t => {
  window.onerrorCalls = [];

  const XFooDisconnected = class extends frames[0].HTMLElement {};
  XFooDisconnected.prototype.disconnectedCallback = new frames[1].Function(sourceThrowError);
  frames[0].customElements.define("x-foo-disconnected", XFooDisconnected);

  const el = frames[0].document.createElement("x-foo-disconnected");
  frames[0].document.body.append(el);
  el.remove();

  assert_array_equals(onerrorCalls, ["frame1"]);
}, "disconnectedCallback");

test(t => {
  window.onerrorCalls = [];

  const XFooAttributeChanged = class extends frames[0].HTMLElement {};
  XFooAttributeChanged.observedAttributes = ["foo"];
  XFooAttributeChanged.prototype.attributeChangedCallback = new frames[1].Function(sourceThrowError);
  frames[0].customElements.define("x-foo-attribute-changed", XFooAttributeChanged);

  const el = frames[0].document.createElement("x-foo-attribute-changed");
  frames[0].document.body.append(el);
  el.setAttribute("foo", "bar");

  assert_array_equals(onerrorCalls, ["frame1"]);
}, "attributeChangedCallback");

test(t => {
  window.onerrorCalls = [];

  const XFooAdopted = class extends frames[0].HTMLElement {};
  XFooAdopted.prototype.adoptedCallback = new frames[1].Function(sourceThrowError);
  frames[0].customElements.define("x-foo-adopted", XFooAdopted);

  const el = frames[0].document.createElement("x-foo-adopted");
  document.body.append(el);

  assert_array_equals(onerrorCalls, ["frame1"]);
}, "adoptedCallback");
</script>