mirror of
https://github.com/denoland/deno
synced 2024-08-27 20:09:17 +00:00
Check Event
constructor params (#1997)
This commit is contained in:
parent
d8714281b4
commit
ed2977d3c0
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue