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
Member

@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 PRs that need a full CI run. util Issues and PRs related to the built-in util module. 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 19:22
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 19:26
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Member Author

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 17:26
@BridgeAR
Copy link
Member

@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 08:59
@daeyeon
Copy link
Member Author

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

LGTM!

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 13:08
@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 21, 2022
@aduh95 aduh95 added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 21, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 21, 2022
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label May 22, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 22, 2022
@nodejs-github-bot nodejs-github-bot merged commit f7cd3f6 into nodejs:master May 22, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in f7cd3f6

@daeyeon daeyeon deleted the master.console-220514.Sat.ba25 branch May 23, 2022 15:02
bengl pushed a commit that referenced this pull request 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 pull request 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>
danielleadams pushed a commit that referenced this pull request Jun 27, 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>
targos pushed a commit that referenced this pull request Jul 12, 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>
targos pushed a commit that referenced this pull request Jul 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>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
Fixes: nodejs/node#43095

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

PR-URL: nodejs/node#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 PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when calling console.dir on a revoked Proxy
5 participants