From 367e006e06b0275ac1ac06669ce19f6192735c34 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Fri, 17 Jun 2022 11:05:02 -0400 Subject: fix(ext/web): add EventTarget brand checking (#14637) This commit adds brand checking to EventTarget. It also fixes a bug where deno would crash if an abort signal was aborted on the global addEventListener(). --- cli/tests/unit/event_target_test.ts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/tests/unit/event_target_test.ts b/cli/tests/unit/event_target_test.ts index dfc28605b..f732003ec 100644 --- a/cli/tests/unit/event_target_test.ts +++ b/cli/tests/unit/event_target_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file no-window-prefix -import { assertEquals } from "./test_util.ts"; +import { assertEquals, assertThrows } from "./test_util.ts"; Deno.test(function addEventListenerTest() { const document = new EventTarget(); @@ -244,3 +244,38 @@ Deno.test(function eventTargetDispatchShouldSetTargetInListener() { target.dispatchEvent(event); assertEquals(called, true); }); + +Deno.test(function eventTargetAddEventListenerGlobalAbort() { + return new Promise((resolve) => { + const c = new AbortController(); + + c.signal.addEventListener("abort", () => resolve()); + addEventListener("test", () => {}, { signal: c.signal }); + c.abort(); + }); +}); + +Deno.test(function eventTargetBrandChecking() { + const self = {}; + + assertThrows( + () => { + EventTarget.prototype.addEventListener.call(self, "test", null); + }, + TypeError, + ); + + assertThrows( + () => { + EventTarget.prototype.removeEventListener.call(self, "test", null); + }, + TypeError, + ); + + assertThrows( + () => { + EventTarget.prototype.dispatchEvent.call(self, new Event("test")); + }, + TypeError, + ); +}); -- cgit v1.2.3