From a2262c11d750c922e6cdea1cac5ff80f603d67e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=91=9E=E4=B8=B0?= Date: Mon, 26 Sep 2022 22:55:58 +0800 Subject: fix(ext/console): fix error when logging a proxied Date (#16018) --- cli/tests/unit/console_test.ts | 9 +++++++++ ext/console/02_console.js | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 0ddbe278c..0ab2829fc 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -1678,6 +1678,15 @@ Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedMap() { }); }); +// console.log(new Proxy(new Date(), {})) +Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedDate() { + mockConsole((console, out) => { + const proxiedDate = new Proxy(new Date("2022-09-24T15:59:39.529Z"), {}); + console.log(proxiedDate); + assertEquals(stripColor(out.toString()), "2022-09-24T15:59:39.529Z\n"); + }); +}); + // console.dir test Deno.test(function consoleDir() { mockConsole((console, out) => { diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 5b65774d9..efb7aeb50 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -701,7 +701,11 @@ return handleCircular(value, cyan); } - return inspectObject(value, inspectOptions, proxyDetails); + return inspectObject( + value, + inspectOptions, + proxyDetails, + ); default: // Not implemented is red return red("[Not Implemented]"); @@ -1283,11 +1287,7 @@ return [baseString, refIndex]; } - function inspectObject( - value, - inspectOptions, - proxyDetails, - ) { + function inspectObject(value, inspectOptions, proxyDetails) { if ( ReflectHas(value, customInspect) && typeof value[customInspect] === "function" @@ -1330,7 +1330,10 @@ } else if (ObjectPrototypeIsPrototypeOf(RegExpPrototype, value)) { return inspectRegExp(value, inspectOptions); } else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) { - return inspectDate(value, inspectOptions); + return inspectDate( + proxyDetails ? proxyDetails[0] : value, + inspectOptions, + ); } else if (ObjectPrototypeIsPrototypeOf(SetPrototype, value)) { return inspectSet( proxyDetails ? proxyDetails[0] : value, -- cgit v1.2.3