diff options
author | Colin Ihrig <cjihrig@gmail.com> | 2022-06-17 11:05:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-17 11:05:02 -0400 |
commit | 367e006e06b0275ac1ac06669ce19f6192735c34 (patch) | |
tree | 4edd702b991d654d4ecf6c1d639b4086f47aafb3 /cli | |
parent | 870d2007163f687b1014db4e5cb43f95aff6d77f (diff) |
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().
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/unit/event_target_test.ts | 37 |
1 files changed, 36 insertions, 1 deletions
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, + ); +}); |