Skip to content

Commit

Permalink
check EventTarget params (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Mar 30, 2019
1 parent 51c6f33 commit ad3cbc5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/event_target.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types";
import { requiredArguments } from "./util";

/* TODO: This is an incomplete implementation to provide functionality
* for Event. A proper spec is still required for a proper Web API.
Expand All @@ -14,6 +15,7 @@ export class EventTarget implements domTypes.EventTarget {
listener: domTypes.EventListenerOrEventListenerObject | null,
_options?: boolean | domTypes.AddEventListenerOptions
): void {
requiredArguments("EventTarget.addEventListener", arguments.length, 2);
if (!this.listeners.hasOwnProperty(type)) {
this.listeners[type] = [];
}
Expand All @@ -27,6 +29,7 @@ export class EventTarget implements domTypes.EventTarget {
callback: domTypes.EventListenerOrEventListenerObject | null,
_options?: domTypes.EventListenerOptions | boolean
): void {
requiredArguments("EventTarget.removeEventListener", arguments.length, 2);
if (this.listeners.hasOwnProperty(type) && callback !== null) {
this.listeners[type] = this.listeners[type].filter(
listener => listener !== callback
Expand All @@ -35,6 +38,7 @@ export class EventTarget implements domTypes.EventTarget {
}

public dispatchEvent(event: domTypes.Event): boolean {
requiredArguments("EventTarget.dispatchEvent", arguments.length, 1);
if (!this.listeners.hasOwnProperty(event.type)) {
return true;
}
Expand Down

0 comments on commit ad3cbc5

Please sign in to comment.