mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
fix(console): don't throw RangeError when an invalid date is passed (#4929)
This commit is contained in:
parent
62976a1c94
commit
d440495b6b
3 changed files with 16 additions and 3 deletions
|
@ -1067,6 +1067,15 @@ unitTest(function consoleLogShouldNotThrowError(): void {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log(Invalid Date) test
|
||||||
|
unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed(): void {
|
||||||
|
mockConsole((console, out) => {
|
||||||
|
const invalidDate = new Date("test");
|
||||||
|
console.log(invalidDate);
|
||||||
|
assertEquals(out.toString(), "Invalid Date\n");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// console.dir test
|
// console.dir test
|
||||||
unitTest(function consoleDir(): void {
|
unitTest(function consoleDir(): void {
|
||||||
mockConsole((console, out): void => {
|
mockConsole((console, out): void => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { isTypedArray, TypedArray } from "./util.ts";
|
import { isInvalidDate, isTypedArray, TypedArray } from "./util.ts";
|
||||||
import { cliTable } from "./console_table.ts";
|
import { cliTable } from "./console_table.ts";
|
||||||
import { exposeForTest } from "../internals.ts";
|
import { exposeForTest } from "../internals.ts";
|
||||||
import { PromiseState } from "./promise.ts";
|
import { PromiseState } from "./promise.ts";
|
||||||
|
@ -409,8 +409,7 @@ function createWeakMapString(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDateString(value: Date): string {
|
function createDateString(value: Date): string {
|
||||||
// without quotes, ISO format
|
return isInvalidDate(value) ? "Invalid Date" : value.toISOString(); // without quotes, ISO format
|
||||||
return value.toISOString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRegExpString(value: RegExp): string {
|
function createRegExpString(value: RegExp): string {
|
||||||
|
|
|
@ -18,6 +18,11 @@ export function isTypedArray(x: unknown): x is TypedArray {
|
||||||
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @internal
|
||||||
|
export function isInvalidDate(x: Date): boolean {
|
||||||
|
return isNaN(x.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export function requiredArguments(
|
export function requiredArguments(
|
||||||
name: string,
|
name: string,
|
||||||
|
|
Loading…
Reference in a new issue