Skip to content

Commit

Permalink
JS: More implied receiver steps
Browse files Browse the repository at this point in the history
  • Loading branch information
asgerf committed Mar 26, 2024
1 parent f2939bd commit 22b56a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ module CallGraph {
StepSummary::step(getAnAllocationSiteRef(node), result, objectWithMethodsStep())
}

/**
* Holds if `function` flows to a property of `host` via non-local data flow.
*/
pragma[nomagic]
private predicate complexMethodInstallation(
DataFlow::SourceNode host, DataFlow::FunctionNode function
) {
not function = getAMethodOnObject(_) and
exists(DataFlow::TypeTracker t |
getAFunctionReference(function, 0, t) = host.getAPropertySource() and
t.start() // require call bit to be false
)
}

/**
* Holds if `pred` is assumed to flow to `succ` because a method is stored on an object that is assumed
* to be the receiver of calls to that method.
Expand All @@ -291,9 +305,18 @@ module CallGraph {
*/
cached
predicate impliedReceiverStep(DataFlow::SourceNode pred, DataFlow::SourceNode succ) {
// To avoid double-recursion, we handle either complex flow for the host object, or for the function, but not both.
exists(DataFlow::SourceNode host |
// Complex flow for the host object
pred = getAnAllocationSiteRef(host) and
succ = getAMethodOnObject(host).getReceiver()
or
// Complex flow for the function
exists(DataFlow::FunctionNode function |
complexMethodInstallation(host, function) and
pred = host and
succ = function.getReceiver()
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ spuriousCallee
missingCallee
| constructor-field.ts:40:5:40:14 | f3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
| constructor-field.ts:71:1:71:11 | bf3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
| implied-receiver.js:7:13:7:25 | this.member() | implied-receiver.js:17:22:19:1 | functio ... n 42;\\n} | -1 | calls |
badAnnotation
accessorCall
| accessors.js:12:1:12:5 | obj.f | accessors.js:5:8:5:12 | () {} |
Expand Down

0 comments on commit 22b56a4

Please sign in to comment.