Skip to content

Commit a2993f1

Browse files
committed
massively improve performance for detecting one-shot closures
1 parent 0b8ea3c commit a2993f1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

javascript/ql/src/Statements/UseOfReturnlessFunction.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ predicate benignContext(Expr e) {
7272
e = any(ResolvedPromiseDefinition promise).getValue().asExpr()
7373
}
7474

75+
predicate oneshotClosure(InvokeExpr call) {
76+
call.getCallee().getUnderlyingValue() instanceof ImmediatelyInvokedFunctionExpr
77+
}
7578

7679
from DataFlow::CallNode call
7780
where
@@ -81,7 +84,7 @@ where
8184
not benignContext(call.asExpr()) and
8285

8386
// anonymous one-shot closure. Those are used in weird ways and we ignore them.
84-
call.asExpr() != any(ImmediatelyInvokedFunctionExpr f).getInvocation()
87+
not oneshotClosure(call.asExpr())
8588
select
8689
call, "the function $@ does not return anything, yet the return value is used.", call.getACallee(), call.getCalleeName()
8790

0 commit comments

Comments
 (0)