node icon indicating copy to clipboard operation
node copied to clipboard

inspect: fix pop undefined when array prototype pop deleted

Open yashLadha opened this issue 4 years ago • 10 comments

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
  • [x] commit message follows commit guidelines

yashLadha avatar Jan 02 '21 16:01 yashLadha

Benchmark run: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/863/

yashLadha avatar Jan 03 '21 02:01 yashLadha

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%

aduh95 avatar Jan 03 '21 16:01 aduh95

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.

Trott avatar Jan 12 '21 23:01 Trott

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

yashLadha avatar Jan 18 '21 01:01 yashLadha

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

yashLadha avatar Jan 19 '21 01:01 yashLadha

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

aduh95 avatar Jan 19 '21 08:01 aduh95

Any reason not to rebase and land this?

ljharb avatar Dec 16 '21 17:12 ljharb

Any reason not to rebase and land this?

I believe @Trott had requested a test for this in https://github.com/nodejs/node/pull/36742#issuecomment-759108796, so that might be the only thing lacking.

DerekNonGeneric avatar Dec 17 '21 07:12 DerekNonGeneric

Sure will add UTs

yashLadha avatar Dec 17 '21 10:12 yashLadha