summaryrefslogtreecommitdiff
path: root/cli/js/custom_event.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-04 20:28:51 -0400
committerGitHub <noreply@github.com>2019-10-04 20:28:51 -0400
commitb81e5db17aa8b3088d6034ddf86b79c69410f012 (patch)
tree579e4c23d60d1b0d038156bc28a04f74ea87b2f0 /cli/js/custom_event.ts
parent9049213867d30f7df090a83b6baf3e0717a4d2d2 (diff)
Merge deno_cli_snapshots into deno_cli (#3064)
Diffstat (limited to 'cli/js/custom_event.ts')
-rw-r--r--cli/js/custom_event.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/cli/js/custom_event.ts b/cli/js/custom_event.ts
new file mode 100644
index 000000000..922abd4b1
--- /dev/null
+++ b/cli/js/custom_event.ts
@@ -0,0 +1,48 @@
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+import * as domTypes from "./dom_types.ts";
+import * as event from "./event.ts";
+import { getPrivateValue, requiredArguments } from "./util.ts";
+
+// WeakMaps are recommended for private attributes (see MDN link below)
+// https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/Guides/Contributor_s_Guide/Private_Properties#Using_WeakMaps
+export const customEventAttributes = new WeakMap();
+
+export class CustomEvent extends event.Event implements domTypes.CustomEvent {
+ constructor(
+ type: string,
+ customEventInitDict: domTypes.CustomEventInit = {}
+ ) {
+ requiredArguments("CustomEvent", arguments.length, 1);
+ super(type, customEventInitDict);
+ const { detail = null } = customEventInitDict;
+ customEventAttributes.set(this, { detail });
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ get detail(): any {
+ return getPrivateValue(this, customEventAttributes, "detail");
+ }
+
+ initCustomEvent(
+ type: string,
+ bubbles?: boolean,
+ cancelable?: boolean,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ detail?: any
+ ): void {
+ if (this.dispatched) {
+ return;
+ }
+
+ customEventAttributes.set(this, { detail });
+ }
+
+ get [Symbol.toStringTag](): string {
+ return "CustomEvent";
+ }
+}
+
+/** Built-in objects providing `get` methods for our
+ * interceptable JavaScript operations.
+ */
+Reflect.defineProperty(CustomEvent.prototype, "detail", { enumerable: true });