mirror of
https://github.com/denoland/deno
synced 2024-08-27 20:09:17 +00:00
check EventTarget
params (#2018)
This commit is contained in:
parent
51c6f33f64
commit
ad3cbc50fb
|
@ -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.
|
||||
|
@ -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] = [];
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue