lib: avoid mutating Error.stackTraceLimit when it is not writable#38215
Merged
aduh95 merged 1 commit intonodejs:masterfrom Apr 14, 2021
Merged
lib: avoid mutating Error.stackTraceLimit when it is not writable#38215aduh95 merged 1 commit intonodejs:masterfrom
Error.stackTraceLimit when it is not writable#38215aduh95 merged 1 commit intonodejs:masterfrom
Conversation
bmeck
approved these changes
Apr 12, 2021
mscdex
reviewed
Apr 12, 2021
bmeck
suggested changes
Apr 12, 2021
Member
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.
Contributor
Author
|
Results look OK-ish: |
Error.stackTraceLimit when Error is frozenError.stackTraceLimit when it is not writable
aduh95
commented
Apr 13, 2021
lib/internal/errors.js
Outdated
| return ObjectIsExtensible(Error); | ||
| } | ||
|
|
||
| return desc.writable ?? typeof desc.set === 'function'; |
Contributor
Author
There was a problem hiding this comment.
We could try to cache the value when the property is not configurable:
Suggested change
| 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).
bmeck
reviewed
Apr 13, 2021
benjamingr
approved these changes
Apr 13, 2021
bmeck
approved these changes
Apr 13, 2021
Contributor
Author
|
EDIT: the results are not as good… I'd say the tradeoff is worth it, I'm open to suggestions to improve those figures. |
ExE-Boss
reviewed
Apr 13, 2021
Contributor
Author
|
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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Contributor
Author
|
Landed in 09c9e5d |
BethGriggs
pushed a commit
that referenced
this pull request
Apr 15, 2021
PR-URL: #38215 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.