lib: avoid mutating Error.stackTraceLimit when it is not writable#38215
lib: avoid mutating Error.stackTraceLimit when it is not writable#38215aduh95 merged 1 commit intonodejs:masterfrom
Error.stackTraceLimit when it is not writable#38215Conversation
bmeck
left a comment
There was a problem hiding this comment.
Realized this should be checking configurable, not frozen status to handle if someone does an Object.seal(Error), etc.
|
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/998/ Results look OK-ish: |
Error.stackTraceLimit when Error is frozenError.stackTraceLimit when it is not writable
lib/internal/errors.js
Outdated
| return ObjectIsExtensible(Error); | ||
| } | ||
|
|
||
| return desc.writable ?? typeof desc.set === 'function'; |
There was a problem hiding this comment.
We could try to cache the value when the property is not configurable:
| return desc.writable ?? typeof desc.set === 'function'; | |
| const returnValue = desc.writable ?? typeof desc.set === 'function'; | |
| if (desc.configurable === false) | |
| module.exports.isErrorStackTraceLimitWritable = () => returnValue; | |
| return returnValue; |
I think it makes the harder to read, and I think we should try to optimize for the most common case (which is when the property has configurable and writable set to true).
|
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/999/ EDIT: the results are not as good… I'd say the tradeoff is worth it, I'm open to suggestions to improve those figures. |
|
I've added more tests. I think this is ready to land but I'd love to get a final approval to make sure I haven't forgotten anything :) |
PR-URL: nodejs#38215 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
|
Landed in 09c9e5d |
PR-URL: #38215 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This PR aims to avoid getting
Cannot assign to read only property 'stackTraceLimit' of function 'function Error() { [native code] }'errors thrown from core when Node.js is executed with the--frozen-intrinsicsflag.