summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/event_test.ts15
-rw-r--r--ext/web/02_event.js78
-rw-r--r--tools/wpt/expectation.json4
3 files changed, 34 insertions, 63 deletions
diff --git a/cli/tests/unit/event_test.ts b/cli/tests/unit/event_test.ts
index d81023da1..88ff803af 100644
--- a/cli/tests/unit/event_test.ts
+++ b/cli/tests/unit/event_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assert, assertEquals, assertStringIncludes } from "./test_util.ts";
+import { assertEquals, assertStringIncludes } from "./test_util.ts";
Deno.test(function eventInitializedWithType() {
const type = "click";
@@ -80,19 +80,6 @@ Deno.test(function eventInitializedWithNonStringType() {
assertEquals(event.cancelable, false);
});
-// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
-Deno.test(function eventIsTrusted() {
- const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
- assert(desc1);
- assertEquals(typeof desc1.get, "function");
-
- const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
- assert(desc2);
- assertEquals(typeof desc2!.get, "function");
-
- assertEquals(desc1!.get, desc2!.get);
-});
-
Deno.test(function eventInspectOutput() {
// deno-lint-ignore no-explicit-any
const cases: Array<[any, (event: any) => string]> = [
diff --git a/ext/web/02_event.js b/ext/web/02_event.js
index 859da2121..d59a897a6 100644
--- a/ext/web/02_event.js
+++ b/ext/web/02_event.js
@@ -122,20 +122,6 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
},
}, "isTrusted").get;
-webidl.converters.EventInit = webidl.createDictionaryConverter("EventInit", [{
- key: "bubbles",
- defaultValue: false,
- converter: webidl.converters.boolean,
-}, {
- key: "cancelable",
- defaultValue: false,
- converter: webidl.converters.boolean,
-}, {
- key: "composed",
- defaultValue: false,
- converter: webidl.converters.boolean,
-}]);
-
const _attributes = Symbol("[[attributes]]");
const _canceledFlag = Symbol("[[canceledFlag]]");
const _stopPropagationFlag = Symbol("[[stopPropagationFlag]]");
@@ -161,36 +147,7 @@ class Event {
this[_isTrusted] = false;
this[_path] = [];
- if (!eventInitDict[_skipInternalInit]) {
- webidl.requiredArguments(
- arguments.length,
- 1,
- "Failed to construct 'Event'",
- );
- type = webidl.converters.DOMString(
- type,
- "Failed to construct 'Event'",
- "Argument 1",
- );
- const eventInit = webidl.converters.EventInit(
- eventInitDict,
- "Failed to construct 'Event'",
- "Argument 2",
- );
- this[_attributes] = {
- type,
- ...eventInit,
- currentTarget: null,
- eventPhase: Event.NONE,
- target: null,
- timeStamp: DateNow(),
- };
- // [LegacyUnforgeable]
- ReflectDefineProperty(this, "isTrusted", {
- enumerable: true,
- get: isTrusted,
- });
- } else {
+ if (eventInitDict?.[_skipInternalInit]) {
this[_attributes] = {
type,
data: eventInitDict.data ?? null,
@@ -202,10 +159,30 @@ class Event {
target: null,
timeStamp: 0,
};
- // TODO(@littledivy): Not spec compliant but performance is hurt badly
- // for users of `_skipInternalInit`.
- this.isTrusted = false;
+ return;
}
+
+ webidl.requiredArguments(
+ arguments.length,
+ 1,
+ "Failed to construct 'Event'",
+ );
+ type = webidl.converters.DOMString(
+ type,
+ "Failed to construct 'Event'",
+ "Argument 1",
+ );
+
+ this[_attributes] = {
+ type,
+ bubbles: !!eventInitDict.bubbles,
+ cancelable: !!eventInitDict.cancelable,
+ composed: !!eventInitDict.composed,
+ currentTarget: null,
+ eventPhase: Event.NONE,
+ target: null,
+ timeStamp: DateNow(),
+ };
}
[SymbolFor("Deno.privateCustomInspect")](inspect) {
@@ -435,6 +412,13 @@ class Event {
}
}
+// Not spec compliant. The spec defines it as [LegacyUnforgeable]
+// but doing so has a big performance hit
+ReflectDefineProperty(Event.prototype, "isTrusted", {
+ enumerable: true,
+ get: isTrusted,
+});
+
function defineEnumerableProps(
Ctor,
props,
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 326b7f55d..c3deef9bd 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -2229,8 +2229,8 @@
],
"AddEventListenerOptions-signal.any.html": true,
"AddEventListenerOptions-signal.any.worker.html": true,
- "Event-isTrusted.any.html": true,
- "Event-isTrusted.any.worker.html": true,
+ "Event-isTrusted.any.html": false,
+ "Event-isTrusted.any.worker.html": false,
"EventTarget-add-remove-listener.any.html": true,
"EventTarget-add-remove-listener.any.worker.html": true,
"EventTarget-addEventListener.any.html": true,