File: event-handler-idl-attribute-realm.window.js

package info (click to toggle)
thunderbird 1%3A144.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,725,312 kB
  • sloc: cpp: 7,869,225; javascript: 5,974,276; ansic: 3,946,747; python: 1,421,062; xml: 654,642; asm: 474,045; java: 183,117; sh: 110,973; makefile: 20,398; perl: 14,362; objc: 13,086; yacc: 4,583; pascal: 3,448; lex: 1,720; ruby: 999; exp: 762; sql: 731; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (59 lines) | stat: -rw-r--r-- 2,498 bytes parent folder | download | duplicates (3)
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
setup({ allow_uncaught_exception: true });

test(t => {
  document.body.append(document.createElement("iframe"), document.createElement("iframe"));
  t.add_cleanup(() => document.querySelectorAll("iframe").forEach(iframe => iframe.remove()));

  const frame0Document = frames[0].document.documentElement;
  const frame1Body = frames[1].document.body;

  frame1Body.setAttribute("onclick", "void(0)");
  frame0Document.appendChild(frame1Body);
  const get = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onclick").get;
  const f = get.call(frame1Body);

  assert_equals(f.constructor, frames[0].Function, "The function must be created in the element's document's global");
}, "Event handler IDL attributes must return a function from the element's document's realm");

test(t => {
  document.body.append(document.createElement("iframe"), document.createElement("iframe"));
  t.add_cleanup(() => document.querySelectorAll("iframe").forEach(iframe => iframe.remove()));

  const log = [];
  window.addEventListener("error", t.step_func(e => {
    log.push("error event in top / error object realm = " + getErrorRealm(e));
  }, { signal: t.get_signal() }));
  frames[0].addEventListener("error", t.step_func(e => {
    log.push("error event in frames[0] / error object realm = " + getErrorRealm(e));
  }, { signal: t.get_signal() }));
  frames[1].addEventListener("error", t.step_func(e => {
    log.push("error event in frames[1] / error object realm = " + getErrorRealm(e));
  }, { signal: t.get_signal() }));

  const frame0Document = frames[0].document.documentElement;
  const frame1Body = frames[1].document.body;

  frame1Body.setAttribute("onmousedown", "1 *-* 'syntax error'");
  frame0Document.appendChild(frame1Body);

  assert_array_equals(log, [], "No error events must be fired before calling the getter");

  const get = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmousedown").get;
  const f = get.call(frame1Body);

  assert_array_equals(log, ["error event in frames[0] / error object realm = frames[0]"]);
  assert_equals(f, null, "The returned value must be null");
}, "Event handler IDL attribute compilation errors must be fired on the element's document's global");

function getErrorRealm(event) {
  const { error } = event;

  if (error instanceof SyntaxError) {
    return "top";
  } if (error instanceof frames[0].SyntaxError) {
    return "frames[0]";
  } if (error instanceof frames[1].SyntaxError) {
    return "frames[1]";
  }
  return "unknown";
}