node
node copied to clipboard
inspect: fix pop undefined when array prototype pop deleted
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.
Checklist
- [ ]
make -j4 test
(UNIX), orvcbuild test
(Windows) passes - [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [x] commit message follows commit guidelines
Benchmark run: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/863/
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%
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.
Note that this also uses %Array.prototype.includes%
and %Array.prototype.push%
: https://github.com/nodejs/node/blob/b489173ff99dafe694a1547b1a8ffd2fd4fc0694/lib/internal/util/inspect.js#L771https://github.com/nodejs/node/blob/b489173ff99dafe694a1547b1a8ffd2fd4fc0694/lib/internal/util/inspect.js#L991
@ExE-Boss Those changes are not in the scope of the fix but I can raise another PR to move them to primordials.
@ExE-Boss Updated PR to include other primordials as well.
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/905/ (queued, will 404 until it starts)
Any reason not to rebase and land this?
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.
Sure will add UTs