1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Check Event constructor params (#1997)

This commit is contained in:
迷渡 2019-03-26 19:42:26 +08:00 committed by Ryan Dahl
parent d8714281b4
commit ed2977d3c0
2 changed files with 15 additions and 1 deletions

View file

@ -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,

View file

@ -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);
});