FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: avoid mutating `Error.stackTraceLimit` when it is not writable by aduh95 · Pull Request #38215 · nodejs/node · GitHub

/ node Public

lib: avoid mutating Error.stackTraceLimit when it is not writable - #38215

Merged
aduh95 merged 1 commit into
nodejs:masterfrom
aduh95:frozen-error
Apr 14, 2021
Merged

lib: avoid mutating Error.stackTraceLimit when it is not writable#38215
aduh95 merged 1 commit into
nodejs:masterfrom
aduh95:frozen-error

Conversation

aduh95 commented Apr 12, 2021

Copy link
Copy Markdown
Contributor

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.

nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 12, 2021
aduh95 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Apr 12, 2021

Copy link
Copy Markdown
Collaborator

Comment thread lib/assert.js Outdated

bmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Realized this should be checking configurable, not frozen status to handle if someone does an Object.seal(Error), etc.

aduh95 removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Apr 12, 2021

aduh95 commented Apr 13, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

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

Results look OK-ish:

                                                               confidence improvement accuracy (*)    (**)   (***)
misc/hidestackframes.js n=100000 type='direct-call-noerr'                      0.02 %       ±5.94%  ±7.91% ±10.30%
misc/hidestackframes.js n=100000 type='direct-call-throw'               *     -2.86 %       ±2.36%  ±3.14%  ±4.09%
misc/hidestackframes.js n=100000 type='hide-stackframes-noerr'                 0.34 %      ±15.71% ±20.91% ±27.25%
misc/hidestackframes.js n=100000 type='hide-stackframes-throw'                -2.86 %       ±3.23%  ±4.30%  ±5.60%

aduh95 changed the title lib: avoid mutating Error.stackTraceLimit when Error is frozen lib: avoid mutating Error.stackTraceLimit when it is not writable Apr 13, 2021
aduh95 requested a review from bmeck April 13, 2021 10:44
Comment thread lib/internal/errors.js Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm fine not cacheing for now

Comment thread lib/internal/errors.js Outdated
aduh95 requested a review from bmeck April 13, 2021 14:27

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

aduh95 commented Apr 13, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

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.

                                                               confidence improvement accuracy (*)    (**)   (***)
misc/hidestackframes.js n=100000 type='direct-call-noerr'                      2.68 %       ±4.40%  ±5.86%  ±7.62%
misc/hidestackframes.js n=100000 type='direct-call-throw'              **     -4.20 %       ±3.04%  ±4.05%  ±5.29%
misc/hidestackframes.js n=100000 type='hide-stackframes-noerr'                13.07 %      ±14.03% ±18.86% ±24.95%
misc/hidestackframes.js n=100000 type='hide-stackframes-throw'        ***     -4.70 %       ±2.42%  ±3.22%  ±4.19%

Comment thread lib/internal/errors.js Outdated

Copy link
Copy Markdown
Collaborator

aduh95 commented Apr 14, 2021

Copy link
Copy Markdown
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 :)

bmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

aduh95 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Apr 14, 2021

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

PR-URL: nodejs#38215
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

aduh95 commented Apr 14, 2021

Copy link
Copy Markdown
Contributor Author

Landed in 09c9e5d

aduh95 merged commit 09c9e5d into nodejs:master Apr 14, 2021
aduh95 deleted the frozen-error branch April 14, 2021 22:18
BethGriggs pushed a commit that referenced this pull request Apr 15, 2021
PR-URL: #38215
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
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

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL