diff --git a/js/event.ts b/js/event.ts index f397391909..61f21f2e7f 100644 --- a/js/event.ts +++ b/js/event.ts @@ -1,6 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import * as domTypes from "./dom_types"; -import { getPrivateValue } from "./util"; +import { getPrivateValue, requiredArguments } from "./util"; // 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 @@ -31,6 +31,8 @@ export class Event implements domTypes.Event { private _path: domTypes.EventPath[] = []; constructor(type: string, eventInitDict: domTypes.EventInit = {}) { + requiredArguments("Event", arguments.length, 1); + type = String(type); this._initializedFlag = true; eventAttributes.set(this, { type, diff --git a/js/event_test.ts b/js/event_test.ts index d0af40ea9f..eb5521406a 100644 --- a/js/event_test.ts +++ b/js/event_test.ts @@ -68,3 +68,15 @@ test(function eventPreventDefaultSuccess() { cancelableEvent.preventDefault(); assertEquals(cancelableEvent.defaultPrevented, true); }); + +test(function eventInitializedWithNonStringType() { + const type = undefined; + const event = new Event(type); + + assertEquals(event.isTrusted, false); + assertEquals(event.target, null); + assertEquals(event.currentTarget, null); + assertEquals(event.type, "undefined"); + assertEquals(event.bubbles, false); + assertEquals(event.cancelable, false); +});