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:
parent
3a0ebff641
commit
3d65e57d7c
8 changed files with 30 additions and 12 deletions
|
@ -70,11 +70,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
name,
|
name = null,
|
||||||
entryType,
|
entryType = null,
|
||||||
startTime,
|
startTime = null,
|
||||||
duration,
|
duration = null,
|
||||||
key,
|
key = null,
|
||||||
) {
|
) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
|
@ -185,7 +185,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class Performance {
|
class Performance {
|
||||||
constructor(key) {
|
constructor(key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class PermissionStatus {
|
class PermissionStatus {
|
||||||
constructor(state, key) {
|
constructor(state = null, key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ unitTest(function globalThisInstanceofWindow(): void {
|
||||||
assert(globalThis instanceof Window);
|
assert(globalThis instanceof Window);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest(function globalThisConstructorLength(): void {
|
||||||
|
assert(globalThis.constructor.length === 0);
|
||||||
|
});
|
||||||
|
|
||||||
unitTest(function globalThisInstanceofEventTarget(): void {
|
unitTest(function globalThisInstanceofEventTarget(): void {
|
||||||
assert(globalThis instanceof EventTarget);
|
assert(globalThis instanceof EventTarget);
|
||||||
});
|
});
|
||||||
|
|
|
@ -83,10 +83,12 @@ unitTest(function performanceMeasure() {
|
||||||
|
|
||||||
unitTest(function performanceIllegalConstructor() {
|
unitTest(function performanceIllegalConstructor() {
|
||||||
assertThrows(() => new Performance(), TypeError, "Illegal constructor.");
|
assertThrows(() => new Performance(), TypeError, "Illegal constructor.");
|
||||||
|
assertEquals(Performance.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
unitTest(function performanceEntryIllegalConstructor() {
|
unitTest(function performanceEntryIllegalConstructor() {
|
||||||
assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor.");
|
assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor.");
|
||||||
|
assertEquals(PerformanceEntry.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
unitTest(function performanceMeasureIllegalConstructor() {
|
unitTest(function performanceMeasureIllegalConstructor() {
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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> {
|
unitTest(async function permissionInvalidName(): Promise<void> {
|
||||||
await assertThrowsAsync(async () => {
|
await assertThrowsAsync(async () => {
|
||||||
|
@ -24,4 +29,5 @@ unitTest(function permissionStatusIllegalConstructor() {
|
||||||
TypeError,
|
TypeError,
|
||||||
"Illegal constructor.",
|
"Illegal constructor.",
|
||||||
);
|
);
|
||||||
|
assertEquals(Deno.PermissionStatus.length, 0);
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
this.#abortAlgorithms.delete(algorithm);
|
this.#abortAlgorithms.delete(algorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(key) {
|
constructor(key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
const illegalConstructorKey = Symbol("illegalConstuctorKey");
|
const illegalConstructorKey = Symbol("illegalConstuctorKey");
|
||||||
|
|
||||||
class Window extends EventTarget {
|
class Window extends EventTarget {
|
||||||
constructor(key) {
|
constructor(key = null) {
|
||||||
if (key !== illegalConstructorKey) {
|
if (key !== illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorkerGlobalScope extends EventTarget {
|
class WorkerGlobalScope extends EventTarget {
|
||||||
constructor(key) {
|
constructor(key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
|
class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
|
||||||
constructor(key) {
|
constructor(key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,11 @@ function abortSignalHandlerLocation() {
|
||||||
const abortHandler = Object.getOwnPropertyDescriptor(signal, "onabort");
|
const abortHandler = Object.getOwnPropertyDescriptor(signal, "onabort");
|
||||||
assertEquals(abortHandler, undefined);
|
assertEquals(abortHandler, undefined);
|
||||||
}
|
}
|
||||||
|
function abortSignalLength() {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const { signal } = controller;
|
||||||
|
assertEquals(signal.constructor.length, 0);
|
||||||
|
}
|
||||||
function main() {
|
function main() {
|
||||||
basicAbortController();
|
basicAbortController();
|
||||||
signalCallsOnabort();
|
signalCallsOnabort();
|
||||||
|
@ -128,6 +133,7 @@ function main() {
|
||||||
abortSignalEventOrder();
|
abortSignalEventOrder();
|
||||||
abortSignalEventOrderComplex();
|
abortSignalEventOrderComplex();
|
||||||
abortSignalHandlerLocation();
|
abortSignalHandlerLocation();
|
||||||
|
abortSignalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Reference in a new issue