1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40: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 // console.dir test
Deno.test(function consoleDir() { Deno.test(function consoleDir() {
mockConsole((console, out) => { mockConsole((console, out) => {

View file

@ -661,7 +661,8 @@
if (ctxHas(value)) { if (ctxHas(value)) {
return handleCircular(value, cyan); return handleCircular(value, cyan);
} }
return inspectObject(value, level, inspectOptions);
return inspectObject(value, level, inspectOptions, proxyDetails);
default: default:
// Not implemented is red // Not implemented is red
return red("[Not Implemented]"); return red("[Not Implemented]");
@ -1200,6 +1201,7 @@
value, value,
level, level,
inspectOptions, inspectOptions,
proxyDetails,
) { ) {
if (customInspect in value && typeof value[customInspect] === "function") { if (customInspect in value && typeof value[customInspect] === "function") {
return String(value[customInspect](inspect)); return String(value[customInspect](inspect));
@ -1240,9 +1242,17 @@
} else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) { } else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) {
return inspectDate(value, inspectOptions); return inspectDate(value, inspectOptions);
} else if (ObjectPrototypeIsPrototypeOf(SetPrototype, value)) { } else if (ObjectPrototypeIsPrototypeOf(SetPrototype, value)) {
return inspectSet(value, level, inspectOptions); return inspectSet(
proxyDetails ? proxyDetails[0] : value,
level,
inspectOptions,
);
} else if (ObjectPrototypeIsPrototypeOf(MapPrototype, value)) { } else if (ObjectPrototypeIsPrototypeOf(MapPrototype, value)) {
return inspectMap(value, level, inspectOptions); return inspectMap(
proxyDetails ? proxyDetails[0] : value,
level,
inspectOptions,
);
} else if (ObjectPrototypeIsPrototypeOf(WeakSetPrototype, value)) { } else if (ObjectPrototypeIsPrototypeOf(WeakSetPrototype, value)) {
return inspectWeakSet(inspectOptions); return inspectWeakSet(inspectOptions);
} else if (ObjectPrototypeIsPrototypeOf(WeakMapPrototype, value)) { } else if (ObjectPrototypeIsPrototypeOf(WeakMapPrototype, value)) {