• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4require('../common');
5const assert = require('assert');
6
7const {
8  Event,
9  CustomEvent,
10  EventTarget,
11  NodeEventTarget,
12} = require('internal/event_target');
13
14[
15  'target',
16  'currentTarget',
17  'srcElement',
18  'type',
19  'cancelable',
20  'defaultPrevented',
21  'timeStamp',
22  'returnValue',
23  'bubbles',
24  'composed',
25  'eventPhase',
26].forEach((i) => {
27  assert.throws(() => Reflect.get(Event.prototype, i, {}), {
28    code: 'ERR_INVALID_THIS',
29  });
30});
31
32[
33  'stopImmediatePropagation',
34  'preventDefault',
35  'composedPath',
36  'cancelBubble',
37  'stopPropagation',
38].forEach((i) => {
39  assert.throws(() => Reflect.apply(Event.prototype[i], [], {}), {
40    code: 'ERR_INVALID_THIS',
41  });
42});
43
44[
45  'target',
46  'currentTarget',
47  'srcElement',
48  'type',
49  'cancelable',
50  'defaultPrevented',
51  'timeStamp',
52  'returnValue',
53  'bubbles',
54  'composed',
55  'eventPhase',
56  'detail',
57].forEach((i) => {
58  assert.throws(() => Reflect.get(CustomEvent.prototype, i, {}), {
59    code: 'ERR_INVALID_THIS',
60  });
61});
62
63[
64  'stopImmediatePropagation',
65  'preventDefault',
66  'composedPath',
67  'cancelBubble',
68  'stopPropagation',
69].forEach((i) => {
70  assert.throws(() => Reflect.apply(CustomEvent.prototype[i], [], {}), {
71    code: 'ERR_INVALID_THIS',
72  });
73});
74
75['addEventListener', 'removeEventListener', 'dispatchEvent'].forEach((i) => {
76  assert.throws(() => Reflect.apply(EventTarget.prototype[i], [], {}), {
77    code: 'ERR_INVALID_THIS',
78  });
79});
80
81[
82  'setMaxListeners',
83  'getMaxListeners',
84  'eventNames',
85  'listenerCount',
86  'off',
87  'removeListener',
88  'on',
89  'addListener',
90  'once',
91  'emit',
92  'removeAllListeners',
93].forEach((i) => {
94  assert.throws(() => Reflect.apply(NodeEventTarget.prototype[i], [], {}), {
95    code: 'ERR_INVALID_THIS',
96  });
97});
98