GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: fix inspecting of proxy objects by jasnell · Pull Request #6465 · nodejs/node

Conversation

@jasnell

@jasnell jasnell commented Apr 29, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Affected core subsystem(s)

util

Description of change

In certain conditions (see #6464), inspecting a Proxy object can lead to a max call stack error. Avoid that by detecting the Proxy object and outputting information about the Proxy object itself.

Also adds util.isProxy()

Fixes: #6464

/cc @bnoordhuis

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell jasnell added the util Issues and PRs related to the built-in util module. label Apr 29, 2016
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 29, 2016
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

CI: https://ci.nodejs.org/job/node-test-pull-request/2428/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins

MylesBorins commented Apr 29, 2016

Copy link
Copy Markdown
Contributor

CI is green LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented Apr 29, 2016

Copy link
Copy Markdown
Contributor

-1, the whole point of proxies is being transparent

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex mscdex removed the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 29, 2016
@addaleax

addaleax commented Apr 29, 2016

Copy link
Copy Markdown
Member

the whole point of proxies is being transparent

That’s true for the programmatic use of proxies, but util.inspect comes with the intention of showing humans what is going on.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@addaleax +1 . Note that getters/setters are also generally intended to be transparent for most cases but util.inspect will produce output like {a: [Getter]} which avoids similar stack-depth side effects... e.g.

var m = {};
Object.defineProperty(m, 'a', {
  enumerable: true,
  get: function() {
    console.log(this);
    return 5;
  }
});
util.inspect(m);
  // Returns `{a: [Getter]}`
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

(@thealphanerd ... what are you doing up at 2am reviewing code I wrote at 1am? Sleep my friend! Sleep!)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Apr 29, 2016
View reviewed changes
Comment thread lib/util.js Outdated

@cjihrig cjihrig Apr 29, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If you export this, it becomes public API, and should be documented.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasnell jasnell Apr 29, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

+1 ... Forgot to add the doc for it. Will add soon!
On Apr 29, 2016 6:29 AM, "Colin Ihrig" [email protected] wrote:

In lib/util.js
#6465 (comment):

@@ -785,6 +792,10 @@ exports.isPrimitive = isPrimitive;

exports.isBuffer = Buffer.isBuffer;

+function isProxy(p) {

  • return binding.isProxy(p);
    +}
    +exports.isProxy = isProxy;

If you export this, it becomes public API, and should be documented.

—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/6465/files/3d4ff4311a3cf1ff756413756ffc859a663aba99#r61577439

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@cjihrig ... updated! PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

New CI after update: https://ci.nodejs.org/job/node-test-pull-request/2432/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin vkurchatkin added the semver-major PRs that contain breaking changes and should be released in the next major version. label Apr 29, 2016
cjihrig
cjihrig reviewed Apr 29, 2016
View reviewed changes
Comment thread doc/api/util.md Outdated

@cjihrig cjihrig Apr 29, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Unnecessary blank line.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@cjihrig ... done! :-)

@vkurchatkin ... +1 on it being semver-major (unfortunately).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@vkurchatkin ... would this be a bit more palatable if there were an option on util.inspect to turn off this special treatment of Proxy objects? e.g. util.inspect(proxyObj, {unwrapProxy: false});

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig reviewed Apr 29, 2016
View reviewed changes
Comment thread test/parallel/test-util-inspect-proxy.js Outdated

@cjihrig cjihrig Apr 29, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This should probably be camelCase.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cjihrig

cjihrig commented Apr 29, 2016

Copy link
Copy Markdown
Contributor

LGTM pending CI, but it should sit for a couple days.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented Apr 29, 2016

Copy link
Copy Markdown
Contributor

would this be a bit more palatable if there were an option on util.inspect to turn off

@jasnell after some thinking, I agree with your reasoning. Having an option is nice, but in practice no one uses them

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@cjihrig +1 for letting it sit a couple days. There's definitely no rush on it.
@vkurchatkin ... awesome.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
util: fix inspecting of proxy objects
86daa71
In certain conditions, inspecting a Proxy object can lead to a
max call stack error. Avoid that by detecting the Proxy object
and outputting information about the Proxy object itself.

Also adds util.isProxy()

Fixes: nodejs#6464
@jasnell
jasnell force-pushed the inspect-proxy branch from ad9be3a to 86daa71 Compare April 29, 2016 17:59
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

Squashed, new CI: https://ci.nodejs.org/job/node-test-pull-request/2435/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

CI is green. Will land on monday if there are no objections. /cc @nodejs/ctc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented Apr 29, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Looks like this conflates two things:

  1. fixing inspect (which shouldn't be major)
  2. adding util.isProxy() (which we should not do given we don't even know what the hell do do with the existing functions: util: deprecate most of util.is*() #6235)

Please do not land in this state.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 30, 2016

Copy link
Copy Markdown
Member Author

New CI: https://ci.nodejs.org/job/node-test-pull-request/2444/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed May 1, 2016
View reviewed changes
Comment thread lib/util.js Outdated
function formatValue(ctx, value, recurseTimes) {

if (ctx.showProxy &&
(typeof value === 'object' || typeof value === 'function')) {

@bnoordhuis bnoordhuis May 1, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You should check that typeof value === 'object' && value !== null, I think?

Style nit: can you drop the blank line?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasnell jasnell May 1, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ack

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell
Address nits
842a8e4
@jasnell

jasnell commented May 1, 2016

Copy link
Copy Markdown
Member Author

@bnoordhuis ... updated

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed May 2, 2016
View reviewed changes
Comment thread lib/util.js
// for it to get proper formatting, and because
// the target and handle objects also might be
// proxies... it's unfortunate but necessary.
proxyCache.set(proxy, undefined);

@bnoordhuis bnoordhuis May 2, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I understand the logic but I don't think the 'necessary' is accurate; if you skipped adding proxy to the cache here, the algorithm would still work, only less efficiently. The next iteration would check the cache, miss, call .getProxyDetails() for the details array, and add the undefined return value to the cache a few lines below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasnell jasnell May 2, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Necessary in the sense of avoiding an extraneous call to getProxyDetails... Which I would consider to be a bug since the point is to only check when we don't know for sure. ;)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented May 2, 2016

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 2, 2016

Copy link
Copy Markdown
Contributor

CI after nits.. seems fine to me if others are happy with the details: https://ci.nodejs.org/job/node-test-pull-request/2459/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

@thealphanerd and @cjihrig ... still LGTY?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins

MylesBorins commented May 3, 2016

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented May 3, 2016

Copy link
Copy Markdown
Contributor

Yes, LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell added a commit that referenced this pull request May 3, 2016
@jasnell
util: fix inspecting of proxy objects
ba6196f
In certain conditions, inspecting a Proxy object can lead to a
max call stack error. Avoid that by detecting the Proxy object
and outputting information about the Proxy object itself.

Fixes: #6464
PR-URL: #6465
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@jasnell jasnell removed the wip Issues and PRs that are still a work in progress. label May 3, 2016
@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

Landed in ba6196f.
Thank you all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell closed this May 3, 2016
Fishrock123 pushed a commit that referenced this pull request May 4, 2016
@jasnell @Fishrock123
util: fix inspecting of proxy objects
0bca959
In certain conditions, inspecting a Proxy object can lead to a
max call stack error. Avoid that by detecting the Proxy object
and outputting information about the Proxy object itself.

Fixes: #6464
PR-URL: #6465
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
This was referenced May 4, 2016
Propose v6.1.0 wrong base please ignore #6556
Closed
Propose v6.1.0 (Openssl update) #6557
Merged
joelostrowski pushed a commit to joelostrowski/node that referenced this pull request May 4, 2016
@jasnell @joelostrowski
util: fix inspecting of proxy objects
155c358
In certain conditions, inspecting a Proxy object can lead to a
max call stack error. Avoid that by detecting the Proxy object
and outputting information about the Proxy object itself.

Fixes: nodejs#6464
PR-URL: nodejs#6465
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
cd7b76e
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
  - Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
  - Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
    - This is set to `100` by default.
  - Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
    - Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
7f82130
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
  - Please see our blog post for more info on the security contents of this release:
  - https://nodejs.org/en/blog/vulnerability/openssl-may-2016/
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
  - Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
  - Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
    - This is set to `100` by default.
  - Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
    - Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
b9ceb42
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
- Please see our blog post for more info on the security contents of
this release:
- https://nodejs.org/en/blog/vulnerability/openssl-may-2016/
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
- Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
- Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
- This is set to `100` by default.
- Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
- Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
@yous yous mentioned this pull request May 23, 2016
Translate "Node v6.1.0 (Current)" nodejs/nodejs-ko#348
Merged
@zbjornson zbjornson mentioned this pull request Jan 11, 2017
console.log(proxy) invokes get trap with built-in Symbols #10731
Closed
@kriscendobot kriscendobot mentioned this pull request Jul 12, 2026
design(inspect): @endo/inspect package + shim for portable, safe inspection endojs/endo-but-for-bots#715
Draft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@jasnell @MylesBorins @vkurchatkin @addaleax @cjihrig @Fishrock123 @mscdex @bnoordhuis @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.