-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Handle calls to bound functions #2855
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
JS: Handle calls to bound functions #2855
Conversation
This seems fine, but before I check the details, I would like to confirm that the following is intentional: We do not use type tracking for callees in the callgraph, we only use ordinary dataflow and then type tracking for an eventual class/instance. But this change will permit type tracking for the bound function callees - right? |
Indeed. I've been meaning to track functions as well, but this will require a separate evaluation. |
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.
Still LGTM, but I found a few nits.
Do we want a generic change note for "improved callgraph"?
Implementation LGTM then.
|
5b27c49
to
1ee112a
Compare
Rebased to fix a conflict and added change note. I'd like to run a another short evaluation since the other PR involving partial invocations has landed. |
Evaluation still looks good. @esbena I rephrased the change note a bit, could you take a quick look? |
Co-Authored-By: Esben Sparre Andreasen <esbena@github.com>
Extends our call graph to deal with calls to bound functions, that is, functions created by a partial invocation such as
fn.bind(x, y)
. For example:It is not enough to simply add these to
getACallee
andFlowSteps::calls()
since that wouldn't take into account that the argument-to-parameter mapping is not 1:1.So "bound calls" are handled as a first-class concept in the data flow libraries. We could generalize ordinary calls to be seen as "bound calls with zero bound arguments and unbound receiver", but since the overwhelming majority of calls are plain calls, it seemed wasteful.
We already type-track the result of partial invocations, for use in library models that require aggressive tracking into callbacks (
getABoundCallbackParameter
). We now use the same type-tracking to create the call graph for bound calls.To avoid spurious flow, we distinguish cases where a bound function was tracked into a call from those that weren't. If it wasn't tracked into a call, we add a call edge that's assumed to hold in any context. If it was tracked into a call, we use our existing handling of callbacks to track the flow.
Evaluation looks fine.