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) --- cli/tests/unit/performance_test.ts | 17 +++++++++++++++++ cli/tests/unit/permissions_test.ts | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index 3c98e4e40..7b2fa5cef 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -3,6 +3,7 @@ import { unitTest, assert, assertEquals, + assertThrows, createResolvable, } from "./test_util.ts"; @@ -64,3 +65,19 @@ unitTest(function performanceMeasure() { }, 100); }); }); + +unitTest(function performanceIllegalConstructor() { + assertThrows(() => new Performance(), TypeError, "Illegal constructor."); +}); + +unitTest(function performanceEntryIllegalConstructor() { + assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor."); +}); + +unitTest(function performanceMeasureIllegalConstructor() { + assertThrows( + () => new PerformanceMeasure(), + TypeError, + "Illegal constructor.", + ); +}); diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 005727721..21fa1d27b 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { unitTest, assertThrowsAsync } from "./test_util.ts"; +import { unitTest, assertThrows, assertThrowsAsync } from "./test_util.ts"; unitTest(async function permissionInvalidName(): Promise { await assertThrowsAsync(async () => { @@ -13,3 +13,15 @@ unitTest(async function permissionNetInvalidUrl(): Promise { await Deno.permissions.query({ name: "net", url: ":" }); }, URIError); }); + +unitTest(function permissionsIllegalConstructor() { + assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor."); +}); + +unitTest(function permissionStatusIllegalConstructor() { + assertThrows( + () => new Deno.PermissionStatus(), + TypeError, + "Illegal constructor.", + ); +}); -- cgit v1.2.3