1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix: fix various global objects constructor length (#8373)

This commit changes various Web APIs constructors to 
match their signature in the browser.
This commit is contained in:
Benjamin Gruenbaum 2020-11-14 14:10:23 +02:00 committed by GitHub
parent 3a0ebff641
commit 3d65e57d7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 12 deletions

View file

@ -70,11 +70,11 @@
}
constructor(
name,
entryType,
startTime,
duration,
key,
name = null,
entryType = null,
startTime = null,
duration = null,
key = null,
) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
@ -185,7 +185,7 @@
}
class Performance {
constructor(key) {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}

View file

@ -17,7 +17,7 @@
}
class PermissionStatus {
constructor(state, key) {
constructor(state = null, key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}

View file

@ -40,6 +40,10 @@ unitTest(function globalThisInstanceofWindow(): void {
assert(globalThis instanceof Window);
});
unitTest(function globalThisConstructorLength(): void {
assert(globalThis.constructor.length === 0);
});
unitTest(function globalThisInstanceofEventTarget(): void {
assert(globalThis instanceof EventTarget);
});

View file

@ -83,10 +83,12 @@ unitTest(function performanceMeasure() {
unitTest(function performanceIllegalConstructor() {
assertThrows(() => new Performance(), TypeError, "Illegal constructor.");
assertEquals(Performance.length, 0);
});
unitTest(function performanceEntryIllegalConstructor() {
assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor.");
assertEquals(PerformanceEntry.length, 0);
});
unitTest(function performanceMeasureIllegalConstructor() {

View file

@ -1,5 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assertThrows, assertThrowsAsync, unitTest } from "./test_util.ts";
import {
assertEquals,
assertThrows,
assertThrowsAsync,
unitTest,
} from "./test_util.ts";
unitTest(async function permissionInvalidName(): Promise<void> {
await assertThrowsAsync(async () => {
@ -24,4 +29,5 @@ unitTest(function permissionStatusIllegalConstructor() {
TypeError,
"Illegal constructor.",
);
assertEquals(Deno.PermissionStatus.length, 0);
});

View file

@ -31,7 +31,7 @@
this.#abortAlgorithms.delete(algorithm);
}
constructor(key) {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}

View file

@ -4,7 +4,7 @@
const illegalConstructorKey = Symbol("illegalConstuctorKey");
class Window extends EventTarget {
constructor(key) {
constructor(key = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}
@ -17,7 +17,7 @@
}
class WorkerGlobalScope extends EventTarget {
constructor(key) {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}
@ -30,7 +30,7 @@
}
class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
constructor(key) {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}

View file

@ -118,6 +118,11 @@ function abortSignalHandlerLocation() {
const abortHandler = Object.getOwnPropertyDescriptor(signal, "onabort");
assertEquals(abortHandler, undefined);
}
function abortSignalLength() {
const controller = new AbortController();
const { signal } = controller;
assertEquals(signal.constructor.length, 0);
}
function main() {
basicAbortController();
signalCallsOnabort();
@ -128,6 +133,7 @@ function main() {
abortSignalEventOrder();
abortSignalEventOrderComplex();
abortSignalHandlerLocation();
abortSignalLength();
}
main();