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
|
<!DOCTYPE html>
<meta charset="utf-8">
<title>Window extends EventTarget</title>
<link rel="help" href="https://github.com/jsdom/jsdom/issues/2830">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
"use strict";
test(() => {
assert_equals(window.addEventListener, EventTarget.prototype.addEventListener);
assert_equals(window.removeEventListener, EventTarget.prototype.removeEventListener);
assert_equals(window.dispatchEvent, EventTarget.prototype.dispatchEvent);
}, "EventTarget methods on Window instances are inherited from the EventTarget prototype");
test(() => {
const kCustom = "custom-event";
const customEvent = new CustomEvent(kCustom, {
bubbles: true
});
let target;
window.addEventListener.call(document.body, kCustom, function () {
target = this;
});
document.body.dispatchEvent(customEvent);
assert_equals(target, document.body);
}, "window.addEventListener respects custom `this`");
test(() => {
const kCustom = "custom-event";
const customEvent = new CustomEvent(kCustom, {
bubbles: true
});
let target;
window.addEventListener.call(null, kCustom, function () {
target = this;
});
document.body.dispatchEvent(customEvent);
assert_equals(target, window);
}, "window.addEventListener treats nullish `this` as `window`");
</script>
|