Skip to content

Commit 4d6da19

Browse files
committed
JS: Improve performance of getExceptionTarget
1 parent 639f043 commit 4d6da19

File tree

1 file changed

+16
-11
lines changed
  • javascript/ql/src/semmle/javascript

1 file changed

+16
-11
lines changed

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,30 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
234234
)
235235
}
236236

237+
pragma[inline]
238+
private Stmt getRawEnclosingStmt(Expr e) {
239+
// For performance reasons, we need the enclosing statement without overrides
240+
enclosingStmt(e, result)
241+
}
242+
237243
/**
238244
* Gets the data-flow node where exceptions thrown by this expression will
239245
* propagate if this expression causes an exception to be thrown.
240246
*/
247+
pragma[inline]
241248
DataFlow::Node getExceptionTarget() {
242-
if exists(this.getEnclosingStmt().getEnclosingTryCatchStmt())
243-
then
244-
result =
245-
DataFlow::parameterNode(this
246-
.getEnclosingStmt()
247-
.getEnclosingTryCatchStmt()
248-
.getACatchClause()
249-
.getAParameter())
250-
else
251-
result =
252-
any(DataFlow::FunctionNode f | f.getFunction() = this.getContainer()).getExceptionalReturn()
249+
result = getCatchParameterFromStmt(getRawEnclosingStmt(this))
250+
or
251+
not exists(getCatchParameterFromStmt(getRawEnclosingStmt(this))) and
252+
result = any(DataFlow::FunctionNode f | f.getFunction() = this.getContainer()).getExceptionalReturn()
253253
}
254254
}
255255

256+
cached
257+
private DataFlow::Node getCatchParameterFromStmt(Stmt stmt) {
258+
result = DataFlow::parameterNode(stmt.getEnclosingTryCatchStmt().getACatchClause().getAParameter())
259+
}
260+
256261
/**
257262
* An identifier.
258263
*

0 commit comments

Comments
 (0)