Skip to content

Commit

Permalink
Check Event constructor params (denoland#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Mar 26, 2019
1 parent d871428 commit ed2977d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/event.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions js/event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit ed2977d

Please sign in to comment.