Skip to content

Commit

Permalink
fix(inspector): Deno.inspect should inspect the object the proxy repr…
Browse files Browse the repository at this point in the history
…esents rather than the target of the proxy (denoland#10977)
  • Loading branch information
dsherret committed Jun 15, 2021
1 parent 0c0058f commit 984b8bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
28 changes: 26 additions & 2 deletions cli/tests/unit/console_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,16 +1737,40 @@ unitTest(function inspectIterableLimit(): void {
unitTest(function inspectProxy(): void {
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], { get(): void {} }),
new Proxy([1, 2, 3], {}),
)),
"[ 1, 2, 3 ]",
);
assertEquals(
stripColor(Deno.inspect(
new Proxy({ key: "value" }, { get(): void {} }),
new Proxy({ key: "value" }, {}),
)),
`{ key: "value" }`,
);
assertEquals(
stripColor(Deno.inspect(
new Proxy({}, {
get(_target, key) {
if (key === Symbol.toStringTag) {
return "MyProxy";
} else {
return 5;
}
},
getOwnPropertyDescriptor() {
return {
enumerable: true,
configurable: true,
value: 5,
};
},
ownKeys() {
return ["prop1", "prop2"];
},
}),
)),
`MyProxy { prop1: 5, prop2: 5 }`,
);
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], { get(): void {} }),
Expand Down
6 changes: 2 additions & 4 deletions extensions/console/02_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,8 @@
inspectOptions,
) {
const proxyDetails = core.getProxyDetails(value);
if (proxyDetails != null) {
return inspectOptions.showProxy
? inspectProxy(proxyDetails, level, inspectOptions)
: inspectValue(proxyDetails[0], level, inspectOptions);
if (proxyDetails != null && inspectOptions.showProxy) {
return inspectProxy(proxyDetails, level, inspectOptions);
}

const green = maybeColor(colors.green, inspectOptions);
Expand Down

0 comments on commit 984b8bf

Please sign in to comment.