mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
check EventTarget
params (#2018)
This commit is contained in:
parent
51c6f33f64
commit
ad3cbc50fb
1 changed files with 4 additions and 0 deletions
|
@ -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