From 984b8bf0c864310bb373a57aad1fea0b002b74fe Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 15 Jun 2021 15:33:13 -0400 Subject: [PATCH] fix(inspector): Deno.inspect should inspect the object the proxy represents rather than the target of the proxy (#10977) --- cli/tests/unit/console_test.ts | 28 ++++++++++++++++++++++++++-- extensions/console/02_console.js | 6 ++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index a43bfdba35..8013da1529 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -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 {} }), diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js index a8098423d8..8fc6e93b2b 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);