From aaa5e6613a739f8e2ff7579b69c2504bcdc37d4f Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 19 Sep 2020 22:30:59 +0100 Subject: fix(cli/rt): make some web API constructors illegal at runtime (#7468) --- op_crates/web/abort_controller_test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'op_crates/web/abort_controller_test.js') diff --git a/op_crates/web/abort_controller_test.js b/op_crates/web/abort_controller_test.js index a2fb12c65..0243c6628 100644 --- a/op_crates/web/abort_controller_test.js +++ b/op_crates/web/abort_controller_test.js @@ -9,6 +9,19 @@ function assertEquals(left, right) { assert(left === right); } +function assertThrows(fn) { + let error = null; + try { + fn(); + } catch (error_) { + error = error_; + } + if (error == null) { + throw new Error("Didn't throw."); + } + return error; +} + function basicAbortController() { controller = new AbortController(); assert(controller); @@ -64,12 +77,19 @@ function controllerHasProperToString() { assertEquals(actual, "[object AbortController]"); } +function abortSignalIllegalConstructor() { + const error = assertThrows(() => new AbortSignal()); + assert(error instanceof TypeError); + assertEquals(error.message, "Illegal constructor."); +} + function main() { basicAbortController(); signalCallsOnabort(); signalEventListener(); onlyAbortsOnce(); controllerHasProperToString(); + abortSignalIllegalConstructor(); } main(); -- cgit v1.2.3