-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add util.getCallSite() API #54380
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54380 +/- ##
==========================================
- Coverage 87.61% 87.60% -0.01%
==========================================
Files 650 650
Lines 182829 182878 +49
Branches 35382 35390 +8
==========================================
+ Hits 160179 160210 +31
Misses 15931 15931
- Partials 6719 6737 +18
|
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.
Should we add an option to ignore node:internal
?
Also, I think we should pretty print the callsite object, if we console.log it:
[
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {}
]
If we JSON.stringify:
[{},{},{},{},{},{},{},{}]
And maybe we should add some snapshot tests, I know they could break if we change/add the methods that call them but usually they are great to track regressions, I know we have a couple snapshot tests like that in our codebase.
In general, looks great to me to have a utility function like this.
I'd not include an option to ignore it in this initial version - maybe a follow up pr once it's landed? It's not supposed to be printed via console.log because it's a CallSite representation. I will modify the API so it retrieves the stack trace from C++, and this should address this issue with the new object |
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 landing it with this js version, just include a benchmark and then we can evaluate if the new c++ version will be faster.
Also, having some snapshot tests will be good to see what will change when we land the c++ version.
C++ version will be landed on this PR. I didn't have time yet. |
Is the new API going to work for events like |
7c0422f
to
8c114c9
Compare
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
Did you do a benchmark?
I did, but without having a fair comparison I don't know if it will mean much: From my local machine
I suspect the C++ implementation will be slower than the JS one for this particular scenario. We need to iterate over v8::StackTrace to create objects while the JS approach does not compute the values unless the function is called. e.g: But, remember that we've switched to C++ for a side-effect-less approach. I can optimize this code later. |
8d9f30a
to
72d56c9
Compare
Landed in 80a989f |
PR-URL: #54380 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Claudio Wunder <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: TODO
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) #54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) #54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) #54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) #54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) #54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) #54384 PR-URL: #54966
This comment was marked as off-topic.
This comment was marked as off-topic.
PR-URL: nodejs#54380 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Claudio Wunder <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) nodejs#54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) nodejs#54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) nodejs#54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) nodejs#54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) nodejs#54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) nodejs#54384 PR-URL: nodejs#54966
PR-URL: nodejs#54380 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Claudio Wunder <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable changes: lib: * (SEMVER-MINOR) add util.getCallSite() API (Rafael Gonzaga) nodejs#54380 repl: * doc-deprecate instantiating `node:repl` classes without `new` (Aviv Keller) nodejs#54842 src: * create handle scope in FastInternalModuleStat (Joyee Cheung) nodejs#54384 stream: * (SEMVER-MINOR) relocate the status checking code in the onwritecomplete (YoonSoo_Shin) nodejs#54032 tls: * (SEMVER-MINOR) add `allowPartialTrustChain` flag (Anna Henningsen) nodejs#54790 v8: * Revert "v8: enable maglev on supported architectures (Joyee Cheung) nodejs#54384 PR-URL: nodejs#54966
This pull request introduces a new API method,
util.getCallSite()
, which provides a way to capture and inspect the call stack within a Node.js application. The method returns an array of CallSite objects, so developers can retrieve information about each function call in the stack trace.Previously, they could reach the same behaviour by using
Error.prepareStackTrace
but, this API isn't that friendly IMO.