Skip to content

Commit 061ed0e

Browse files
daeyeontargos
authored andcommitted
events: improve Event compatibility
This fixes `Event` constructor to improve `Event Web API` compatibility. The test added was written by referring to `wpt@dom/events/Event-constructors.any.js`. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #43461 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2e181f6 commit 061ed0e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/internal/event_target.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ class Event {
9595
* composed?: boolean,
9696
* }} [options]
9797
*/
98-
constructor(type, options = null) {
98+
constructor(type, options = kEmptyObject) {
9999
if (arguments.length === 0)
100100
throw new ERR_MISSING_ARGS('type');
101-
validateObject(options, 'options', {
102-
allowArray: true, allowFunction: true, nullable: true,
103-
});
104-
const { cancelable, bubbles, composed } = { ...options };
101+
validateObject(options, 'options');
102+
const { bubbles, cancelable, composed } = options;
105103
this.#cancelable = !!cancelable;
106104
this.#bubbles = !!bubbles;
107105
this.#composed = !!composed;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { test, assert_equals, assert_array_equals } =
5+
require('../common/wpt').harness;
6+
7+
// Source: https://github.com/web-platform-tests/wpt/blob/6cef1d2087d6a07d7cc6cee8cf207eec92e27c5f/dom/events/Event-constructors.any.js#L91-L112
8+
test(function() {
9+
const called = [];
10+
const ev = new Event('Xx', {
11+
get cancelable() {
12+
called.push('cancelable');
13+
return false;
14+
},
15+
get bubbles() {
16+
called.push('bubbles');
17+
return true;
18+
},
19+
get sweet() {
20+
called.push('sweet');
21+
return 'x';
22+
},
23+
});
24+
assert_array_equals(called, ['bubbles', 'cancelable']);
25+
assert_equals(ev.type, 'Xx');
26+
assert_equals(ev.bubbles, true);
27+
assert_equals(ev.cancelable, false);
28+
assert_equals(ev.sweet, undefined);
29+
});

0 commit comments

Comments
 (0)