Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 33f32dc

Browse filesBrowse files
santigimenoMoLow
authored andcommitted
lib: define Event.isTrusted in the prototype
Don't conform to the spec with isTrusted. The spec defines it as `LegacyUnforgeable` but defining it in the constructor has a big performance impact and the property doesn't seem to be useful outside of browsers. Refs: nodejs/performance#32 PR-URL: #46974 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4850ba4 commit 33f32dc
Copy full SHA for 33f32dc

File tree

Expand file treeCollapse file tree

5 files changed

+17
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+17
-7
lines changed
Open diff view settings
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ class Event {
119119
isTrustedSet.add(this);
120120
}
121121

122-
// isTrusted is special (LegacyUnforgeable)
123-
ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor);
124122
this[kTarget] = null;
125123
this[kIsBeingDispatched] = false;
126124
}
@@ -325,6 +323,11 @@ ObjectDefineProperties(
325323
eventPhase: kEnumerableProperty,
326324
cancelBubble: kEnumerableProperty,
327325
stopPropagation: kEnumerableProperty,
326+
// Don't conform to the spec with isTrusted. The spec defines it as
327+
// LegacyUnforgeable but defining it in the constructor has a big
328+
// performance impact and the property doesn't seem to be useful outside of
329+
// browsers.
330+
isTrusted: isTrustedDescriptor,
328331
});
329332

330333
function isCustomEvent(value) {
Collapse file

‎test/parallel/test-abortcontroller.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-abortcontroller.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const { setTimeout: sleep } = require('timers/promises');
5757
}));
5858
first.abort();
5959
second.abort();
60-
const firstTrusted = Reflect.getOwnPropertyDescriptor(ev1, 'isTrusted').get;
61-
const secondTrusted = Reflect.getOwnPropertyDescriptor(ev2, 'isTrusted').get;
62-
const untrusted = Reflect.getOwnPropertyDescriptor(ev3, 'isTrusted').get;
60+
const firstTrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev1), 'isTrusted').get;
61+
const secondTrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev2), 'isTrusted').get;
62+
const untrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev3), 'isTrusted').get;
6363
strictEqual(firstTrusted, secondTrusted);
6464
strictEqual(untrusted, firstTrusted);
6565
}
Collapse file

‎test/parallel/test-events-customevent.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-events-customevent.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
187187
}
188188
{
189189
const ev = new CustomEvent('foo');
190-
deepStrictEqual(Object.keys(ev), ['isTrusted']);
190+
strictEqual(ev.isTrusted, false);
191191
}
192192

193193
// Works with EventTarget
Collapse file

‎test/parallel/test-eventtarget.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-eventtarget.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ let asyncTest = Promise.resolve();
126126
}
127127
{
128128
const ev = new Event('foo');
129-
deepStrictEqual(Object.keys(ev), ['isTrusted']);
129+
strictEqual(ev.isTrusted, false);
130130
}
131131
{
132132
const eventTarget = new EventTarget();
Collapse file

‎test/wpt/status/dom/events.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/dom/events.json
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
"Event-dispatch-listener-order.window.js": {
2828
"skip": "document is not defined"
2929
},
30+
"Event-isTrusted.any.js": {
31+
"fail": {
32+
"expected": [
33+
"Event-isTrusted"
34+
]
35+
}
36+
},
3037
"EventListener-addEventListener.sub.window.js": {
3138
"skip": "document is not defined"
3239
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.