diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 97c84b690a..d1c570e1b2 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -1609,6 +1609,24 @@ Deno.test(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { }); }); +// console.log(new Proxy(new Set(), {})) +Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedSet() { + mockConsole((console, out) => { + const proxiedSet = new Proxy(new Set(), {}); + console.log(proxiedSet); + assertEquals(stripColor(out.toString()), "Set {}\n"); + }); +}); + +// console.log(new Proxy(new Map(), {})) +Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedMap() { + mockConsole((console, out) => { + const proxiedMap = new Proxy(new Map(), {}); + console.log(proxiedMap); + assertEquals(stripColor(out.toString()), "Map {}\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 4663ded735..a160951790 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -661,7 +661,8 @@ if (ctxHas(value)) { return handleCircular(value, cyan); } - return inspectObject(value, level, inspectOptions); + + return inspectObject(value, level, inspectOptions, proxyDetails); default: // Not implemented is red return red("[Not Implemented]"); @@ -1200,6 +1201,7 @@ value, level, inspectOptions, + proxyDetails, ) { if (customInspect in value && typeof value[customInspect] === "function") { return String(value[customInspect](inspect)); @@ -1240,9 +1242,17 @@ } else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) { return inspectDate(value, inspectOptions); } else if (ObjectPrototypeIsPrototypeOf(SetPrototype, value)) { - return inspectSet(value, level, inspectOptions); + return inspectSet( + proxyDetails ? proxyDetails[0] : value, + level, + inspectOptions, + ); } else if (ObjectPrototypeIsPrototypeOf(MapPrototype, value)) { - return inspectMap(value, level, inspectOptions); + return inspectMap( + proxyDetails ? proxyDetails[0] : value, + level, + inspectOptions, + ); } else if (ObjectPrototypeIsPrototypeOf(WeakSetPrototype, value)) { return inspectWeakSet(inspectOptions); } else if (ObjectPrototypeIsPrototypeOf(WeakMapPrototype, value)) {