1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/console): fix error with a Proxy of a Map (#14032)

This commit is contained in:
Jason 2022-03-20 19:21:42 +08:00 committed by Kitson Kelly
parent fd006debe5
commit 74307a6950
2 changed files with 31 additions and 3 deletions

View file

@ -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) => {

View file

@ -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)) {