mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -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.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import * as domTypes from "./dom_types";
|
import * as domTypes from "./dom_types";
|
||||||
|
import { requiredArguments } from "./util";
|
||||||
|
|
||||||
/* TODO: This is an incomplete implementation to provide functionality
|
/* TODO: This is an incomplete implementation to provide functionality
|
||||||
* for Event. A proper spec is still required for a proper Web API.
|
* 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,
|
listener: domTypes.EventListenerOrEventListenerObject | null,
|
||||||
_options?: boolean | domTypes.AddEventListenerOptions
|
_options?: boolean | domTypes.AddEventListenerOptions
|
||||||
): void {
|
): void {
|
||||||
|
requiredArguments("EventTarget.addEventListener", arguments.length, 2);
|
||||||
if (!this.listeners.hasOwnProperty(type)) {
|
if (!this.listeners.hasOwnProperty(type)) {
|
||||||
this.listeners[type] = [];
|
this.listeners[type] = [];
|
||||||
}
|
}
|
||||||
|
@ -27,6 +29,7 @@ export class EventTarget implements domTypes.EventTarget {
|
||||||
callback: domTypes.EventListenerOrEventListenerObject | null,
|
callback: domTypes.EventListenerOrEventListenerObject | null,
|
||||||
_options?: domTypes.EventListenerOptions | boolean
|
_options?: domTypes.EventListenerOptions | boolean
|
||||||
): void {
|
): void {
|
||||||
|
requiredArguments("EventTarget.removeEventListener", arguments.length, 2);
|
||||||
if (this.listeners.hasOwnProperty(type) && callback !== null) {
|
if (this.listeners.hasOwnProperty(type) && callback !== null) {
|
||||||
this.listeners[type] = this.listeners[type].filter(
|
this.listeners[type] = this.listeners[type].filter(
|
||||||
listener => listener !== callback
|
listener => listener !== callback
|
||||||
|
@ -35,6 +38,7 @@ export class EventTarget implements domTypes.EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispatchEvent(event: domTypes.Event): boolean {
|
public dispatchEvent(event: domTypes.Event): boolean {
|
||||||
|
requiredArguments("EventTarget.dispatchEvent", arguments.length, 1);
|
||||||
if (!this.listeners.hasOwnProperty(event.type)) {
|
if (!this.listeners.hasOwnProperty(event.type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue