Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cfd04d

Browse files
author
Max Schaefer
committed
JavaScript: Eliminate slow antijoin predicate.
1 parent 080f974 commit 0cfd04d

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

javascript/ql/src/semmle/javascript/dataflow/internal/InterProceduralTypeInference.qll

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,26 @@ private class IIFEWithAnalyzedReturnFlow extends CallWithAnalyzedReturnFlow {
160160

161161
}
162162

163+
/**
164+
* Gets the only access to `v`, which is the variable declared by `fn`.
165+
*
166+
* This predicate is not defined for global functions `fn`, or for
167+
* local variables `v` that do not have exactly one access.
168+
*/
169+
private VarAccess getOnlyAccess(FunctionDeclStmt fn, LocalVariable v) {
170+
v = fn.getVariable() and
171+
result = v.getAnAccess() and
172+
strictcount(v.getAnAccess()) = 1
173+
}
174+
163175
/** A function that only is used locally, making it amenable to type inference. */
164176
class LocalFunction extends Function {
165177

166178
DataFlow::Impl::ExplicitInvokeNode invk;
167179

168180
LocalFunction() {
169-
this instanceof FunctionDeclStmt and
170-
exists (LocalVariable v, Expr callee |
171-
callee = invk.getCalleeNode().asExpr() and
172-
v = getVariable() and
173-
v.getAnAccess() = callee and
174-
forall(VarAccess o | o = v.getAnAccess() | o = callee) and
181+
exists (LocalVariable v |
182+
getOnlyAccess(this, v) = invk.getCalleeNode().asExpr() and
175183
not exists(v.getAnAssignedExpr()) and
176184
not exists(ExportDeclaration export | export.exportsAs(v, _))
177185
) and

0 commit comments

Comments
 (0)