-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib: avoid mutating Error.stackTraceLimit
when it is not writable
#38215
Conversation
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
).
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'm fine not cacheing for now
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 :) |
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.
LGTM
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-intrinsics
flag.