mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
event isTrusted
is enumerable (#2543)
This commit is contained in:
parent
425df50484
commit
6a5177dc11
3 changed files with 25 additions and 23 deletions
31
js/event.ts
31
js/event.ts
|
@ -6,6 +6,10 @@ import { getPrivateValue, requiredArguments } from "./util";
|
|||
// https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/Guides/Contributor_s_Guide/Private_Properties#Using_WeakMaps
|
||||
export const eventAttributes = new WeakMap();
|
||||
|
||||
function isTrusted(this: Event): boolean {
|
||||
return getPrivateValue(this, eventAttributes, "isTrusted");
|
||||
}
|
||||
|
||||
export class EventInit implements domTypes.EventInit {
|
||||
bubbles = false;
|
||||
cancelable = false;
|
||||
|
@ -19,6 +23,9 @@ export class EventInit implements domTypes.EventInit {
|
|||
}
|
||||
|
||||
export class Event implements domTypes.Event {
|
||||
// The default value is `false`.
|
||||
// Use `defineProperty` to define on each instance, NOT on the prototype.
|
||||
isTrusted!: boolean;
|
||||
// Each event has the following associated flags
|
||||
private _canceledFlag = false;
|
||||
private _dispatchedFlag = false;
|
||||
|
@ -46,6 +53,10 @@ export class Event implements domTypes.Event {
|
|||
target: null,
|
||||
timeStamp: Date.now()
|
||||
});
|
||||
Reflect.defineProperty(this, "isTrusted", {
|
||||
enumerable: true,
|
||||
get: isTrusted
|
||||
});
|
||||
}
|
||||
|
||||
get bubbles(): boolean {
|
||||
|
@ -134,25 +145,6 @@ export class Event implements domTypes.Event {
|
|||
this._inPassiveListenerFlag = value;
|
||||
}
|
||||
|
||||
get isTrusted(): boolean {
|
||||
return getPrivateValue(this, eventAttributes, "isTrusted");
|
||||
}
|
||||
|
||||
set isTrusted(value: boolean) {
|
||||
eventAttributes.set(this, {
|
||||
type: this.type,
|
||||
bubbles: this.bubbles,
|
||||
cancelable: this.cancelable,
|
||||
composed: this.composed,
|
||||
currentTarget: this.currentTarget,
|
||||
eventPhase: this.eventPhase,
|
||||
isTrusted: value,
|
||||
relatedTarget: this.relatedTarget,
|
||||
target: this.target,
|
||||
timeStamp: this.timeStamp
|
||||
});
|
||||
}
|
||||
|
||||
get path(): domTypes.EventPath[] {
|
||||
return this._path;
|
||||
}
|
||||
|
@ -363,7 +355,6 @@ Reflect.defineProperty(Event.prototype, "defaultPrevented", {
|
|||
});
|
||||
Reflect.defineProperty(Event.prototype, "dispatched", { enumerable: true });
|
||||
Reflect.defineProperty(Event.prototype, "eventPhase", { enumerable: true });
|
||||
Reflect.defineProperty(Event.prototype, "isTrusted", { enumerable: true });
|
||||
Reflect.defineProperty(Event.prototype, "target", { enumerable: true });
|
||||
Reflect.defineProperty(Event.prototype, "timeStamp", { enumerable: true });
|
||||
Reflect.defineProperty(Event.prototype, "type", { enumerable: true });
|
||||
|
|
|
@ -201,8 +201,6 @@ export class EventTarget implements domTypes.EventTarget {
|
|||
);
|
||||
}
|
||||
|
||||
event.isTrusted = false;
|
||||
|
||||
return this._dispatch(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { test, assertEquals } from "./test_util.ts";
|
||||
import { test, assertEquals, assertNotEquals } from "./test_util.ts";
|
||||
|
||||
test(function eventInitializedWithType(): void {
|
||||
const type = "click";
|
||||
|
@ -80,3 +80,16 @@ test(function eventInitializedWithNonStringType(): void {
|
|||
assertEquals(event.bubbles, false);
|
||||
assertEquals(event.cancelable, false);
|
||||
});
|
||||
|
||||
// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
|
||||
test(function eventIsTrusted(): void {
|
||||
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
||||
assertNotEquals(desc1, undefined);
|
||||
assertEquals(typeof desc1.get, "function");
|
||||
|
||||
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
||||
assertNotEquals(desc2, undefined);
|
||||
assertEquals(typeof desc2.get, "function");
|
||||
|
||||
assertEquals(desc1.get, desc2.get);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue