summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-06-15 15:33:13 -0400
committerGitHub <noreply@github.com>2021-06-15 15:33:13 -0400
commit984b8bf0c864310bb373a57aad1fea0b002b74fe (patch)
tree9293d0860edb0e8f687e9802b0f52271520e7003
parent0c0058f1181d1fd6590f760a0375ead706043d32 (diff)
fix(inspector): Deno.inspect should inspect the object the proxy represents rather than the target of the proxy (#10977)
-rw-r--r--cli/tests/unit/console_test.ts28
-rw-r--r--extensions/console/02_console.js6
2 files changed, 28 insertions, 6 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index a43bfdba3..8013da152 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -1737,18 +1737,42 @@ 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 {} }),
{ showProxy: true },
)),
diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js
index a8098423d..8fc6e93b2 100644
--- a/extensions/console/02_console.js
+++ b/extensions/console/02_console.js
@@ -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);