mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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: https://github.com/nodejs/performance/issues/32 PR-URL: https://github.com/nodejs/node/pull/46974 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
cf83caeb57
commit
74b9cf2ee1
5 files changed
+17
-7
No files matched your search
@@ -119,8 +119,6 @@ class Event {
|
||||
isTrustedSet.add(this);
|
||||
}
|
||||
|
||||
// isTrusted is special (LegacyUnforgeable)
|
||||
ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor);
|
||||
this[kTarget] = null;
|
||||
this[kIsBeingDispatched] = false;
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user