Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: define Event.isTrusted in the prototype #46974

Merged
merged 1 commit into from Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/internal/event_target.js
Expand Up @@ -119,8 +119,6 @@ class Event {
isTrustedSet.add(this);
}

// isTrusted is special (LegacyUnforgeable)
ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor);
this[kTarget] = null;
this[kIsBeingDispatched] = false;
}
Expand Down Expand Up @@ -343,6 +341,11 @@ ObjectDefineProperties(
eventPhase: kEnumerableProperty,
cancelBubble: kEnumerableProperty,
stopPropagation: kEnumerableProperty,
// 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.
isTrusted: isTrustedDescriptor,
});

function isCustomEvent(value) {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-abortcontroller.js
Expand Up @@ -57,9 +57,9 @@ const { setTimeout: sleep } = require('timers/promises');
}));
first.abort();
second.abort();
const firstTrusted = Reflect.getOwnPropertyDescriptor(ev1, 'isTrusted').get;
const secondTrusted = Reflect.getOwnPropertyDescriptor(ev2, 'isTrusted').get;
const untrusted = Reflect.getOwnPropertyDescriptor(ev3, 'isTrusted').get;
const firstTrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev1), 'isTrusted').get;
const secondTrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev2), 'isTrusted').get;
const untrusted = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(ev3), 'isTrusted').get;
strictEqual(firstTrusted, secondTrusted);
strictEqual(untrusted, firstTrusted);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-events-customevent.js
Expand Up @@ -187,7 +187,7 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
}
{
const ev = new CustomEvent('foo');
deepStrictEqual(Object.keys(ev), ['isTrusted']);
strictEqual(ev.isTrusted, false);
}

// Works with EventTarget
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-eventtarget.js
Expand Up @@ -126,7 +126,7 @@ let asyncTest = Promise.resolve();
}
{
const ev = new Event('foo');
deepStrictEqual(Object.keys(ev), ['isTrusted']);
strictEqual(ev.isTrusted, false);
}
{
const eventTarget = new EventTarget();
Expand Down
7 changes: 7 additions & 0 deletions test/wpt/status/dom/events.json
Expand Up @@ -11,6 +11,13 @@
"Event-dispatch-listener-order.window.js": {
"skip": "document is not defined"
},
"Event-isTrusted.any.js": {
"fail": {
"expected": [
"Event-isTrusted"
]
}
},
"EventListener-addEventListener.sub.window.js": {
"skip": "document is not defined"
},
Expand Down