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

inspect: fix pop undefined when array prototype pop deleted #36742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yashLadha
Copy link
Contributor

@yashLadha yashLadha commented Jan 2, 2021

If one explicitly deletes the array prototype in the repl instance then
the method to check for pop seen in the context starts giving error.
Reason being primordials is not used and userland has modified the
prototype.

Fixed by using array pop method primordial.

image

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Jan 2, 2021
@aduh95 aduh95 added the needs-benchmark-ci PR that need a benchmark CI run. label Jan 2, 2021
@yashLadha
Copy link
Contributor Author

@aduh95
Copy link
Contributor

aduh95 commented Jan 3, 2021

There are a few perf regressions, but that might be an acceptable trade-off.

                                                                                                confidence improvement accuracy (*)   (**)   (***)
 util/format.js type='object-%s' n=100000                                                               **     -3.04 %       ±1.81% ±2.41%  ±3.14%
 util/format.js type='only-objects' n=100000                                                           ***     -6.02 %       ±2.08% ±2.77%  ±3.61%
 util/inspect.js option='colors' method='Object' n=20000                                                **     -4.03 %       ±2.72% ±3.62%  ±4.71%
 util/inspect.js option='colors' method='String_boxed' n=20000                                          **     -5.31 %       ±3.09% ±4.11%  ±5.35%
 util/inspect.js option='showHidden' method='Set' n=20000                                               **     -7.76 %       ±4.54% ±6.04%  ±7.87%
 util/inspect-proxy.js isProxy=0 showProxy=0 n=100000                                                   **     -2.86 %       ±1.99% ±2.64%  ±3.45%
 util/inspect-proxy.js isProxy=1 showProxy=0 n=100000                                                  ***     -4.76 %       ±1.41% ±1.87%  ±2.44%

@Trott
Copy link
Member

Trott commented Jan 12, 2021

Can we add a test for this? I think the perf hit might be worth it for the robustness in this case, although I wonder if @nodejs/util would agree or not.

@ExE-Boss
Copy link
Contributor

Note that this also uses %Array.prototype.includes% and %Array.prototype.push%:

if (ctx.seen.includes(value)) {
ctx.seen.push(value);

@yashLadha
Copy link
Contributor Author

@ExE-Boss Those changes are not in the scope of the fix but I can raise another PR to move them to primordials.

If one explicitly deletes the array prototype in the repl instance then
the method to check for `pop` seen in the context starts giving error.
Reason being primordials is not used and userland has modified the
prototype.

Fixed by using array pop method primordial.
@yashLadha yashLadha force-pushed the fix_pop_undefined_repl branch from b489173 to 23dff58 Compare January 19, 2021 01:50
@yashLadha
Copy link
Contributor Author

@ExE-Boss Updated PR to include other primordials as well.

@aduh95
Copy link
Contributor

aduh95 commented Jan 19, 2021

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/905/ (queued, will 404 until it starts)

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

Any reason not to rebase and land this?

@DerekNonGeneric
Copy link
Contributor

Any reason not to rebase and land this?

I believe @Trott had requested a test for this in #36742 (comment), so that might be the only thing lacking.

@yashLadha
Copy link
Contributor Author

Sure will add UTs

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.

util.inspect is quite performance sensitive. It is a sync API that many people use in their production, no matter if it's mainly meant for debugging. As such taking a performance hit does not seem right to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-benchmark-ci PR that need a benchmark 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.

9 participants