The Wayback Machine - https://web.archive.org/web/20220602170201/https://github.com/nodejs/node/pull/43100
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: fix console.dir crash on a revoked proxy #43100

Merged

Conversation

daeyeon
Copy link
Contributor

@daeyeon daeyeon commented May 14, 2022

Fixes: #43095

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com

@nodejs-github-bot nodejs-github-bot added needs-ci util labels May 14, 2022
@daeyeon daeyeon force-pushed the master.console-220514.Sat.ba25 branch 9 times, most recently from cdb0ea5 to bb9c1e7 Compare May 14, 2022
daeyeon added 2 commits May 14, 2022
Fixes: nodejs#43095

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
This commit removes extra spaces looking unnecessary if the
`joinedOutput` of type `Array` is empty on `reduceToSingleString`.

e.g) Proxy [  ] -> Proxy []

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
@daeyeon daeyeon force-pushed the master.console-220514.Sat.ba25 branch from bb9c1e7 to 5723aaf Compare May 14, 2022
Copy link
Member

@BridgeAR BridgeAR left a comment

Thanks for the PR! I am going to ignore the implementation details for now to clarify the visualization first:

I am wondering how we want to visualize the revoked proxy with showProxy === false. It's not null but we do not know about the value either. We could just print Revoked Proxy [] or Proxy [ null, null ]. This would however expose the information that it's a proxy which is a hidden fact for not-revoked proxies.

The situation for showProxy === true is simpler: just either use Revoked Proxy [] or Proxy [ null, null ]. I personally like the Revoked Proxy [] a bit better. Any other opinions @nodejs/util?

@daeyeon
Copy link
Contributor Author

@daeyeon daeyeon commented May 15, 2022

Thanks for starting the clarification!

FAYI, this PR's current visualization is the following:

let r = Proxy.revocable({}, {});
console.log(1, inspect(r.proxy));
console.log(2, inspect(r.proxy, { showProxy: true }));

r.revoke();

console.log(3, inspect(r.proxy));
console.log(4, inspect(r.proxy, { showProxy: true }));
1 {}
2 Proxy [ {}, {} ]
3 Proxy []
4 Proxy [ null, null ]

(3) was the part I was most confused of.

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
@daeyeon daeyeon force-pushed the master.console-220514.Sat.ba25 branch from ddf91e4 to 161dbe5 Compare May 16, 2022
@BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented May 18, 2022

@daeyeon what do you think about:

1 {}
2 Proxy [ {}, {} ]
3 <Revoked Proxy>
4 <Revoked Proxy>

3 + 4 using special for formatting (ctx.stylize('<Revoked Proxy>', 'special')).

Copy link
Member

@BridgeAR BridgeAR left a comment

It is possible to simplify the code by using this diff (line numbers must be ignored as they are not identical), if we do not care to distinguish visualization with the showProxy option:

@@ -759,6 +758,9 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
   // any proxy handlers.
   const proxy = getProxyDetails(value, !!ctx.showProxy);
   if (proxy !== undefined) {
+    if (proxy === null) {
+      return ctx.stylize('<Revoked Proxy>', 'special');
+    }
     if (ctx.showProxy) {
       return formatProxy(ctx, proxy, recurseTimes);
     }
@@ -1967,6 +1960,9 @@ function hasBuiltInToString(value) {
   const getFullProxy = false;
   const proxyTarget = getProxyDetails(value, getFullProxy);
   if (proxyTarget !== undefined) {
+    if (proxyTarget === null) {
+      return true;
+    }
     value = proxyTarget;
   }

The last change moves the extra check to only be executed for proxies and no other entries (value?.toString has to run the check for all entries).

@daeyeon daeyeon force-pushed the master.console-220514.Sat.ba25 branch 2 times, most recently from 87a63f5 to a19e077 Compare May 19, 2022
@daeyeon
Copy link
Contributor Author

@daeyeon daeyeon commented May 19, 2022

@BridgeAR Thanks for the review.

I also think that <Revoked Proxy> looks good and provides enough information for a revoked proxy. It can make the code simpler indeed. I applied your suggestion. PTAL.

The last change moves the extra check to only be executed for proxies and no other entries (value?.toString has to run the check for all entries).

Also fixed.

@BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented May 19, 2022

LGTM!

targos
targos approved these changes May 19, 2022
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
@daeyeon daeyeon force-pushed the master.console-220514.Sat.ba25 branch from a19e077 to 13964d0 Compare May 19, 2022
aduh95
aduh95 approved these changes May 21, 2022
@aduh95 aduh95 added the author ready label May 21, 2022
@aduh95 aduh95 added request-ci commit-queue-squash labels May 21, 2022
@github-actions github-actions bot removed the request-ci label May 21, 2022
@aduh95 aduh95 added the commit-queue label May 22, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue label May 22, 2022
@nodejs-github-bot nodejs-github-bot merged commit f7cd3f6 into nodejs:master May 22, 2022
54 checks passed
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented May 22, 2022

Landed in f7cd3f6

@daeyeon daeyeon deleted the master.console-220514.Sat.ba25 branch May 23, 2022
bengl pushed a commit that referenced this issue May 30, 2022
Fixes: #43095

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com

PR-URL: #43100
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@bengl bengl mentioned this pull request May 31, 2022
juanarbol pushed a commit that referenced this issue May 31, 2022
Fixes: #43095

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com

PR-URL: #43100
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready commit-queue-squash needs-ci util
5 participants