add support for try-statements with no catch block

This commit is contained in:
Erik Krogh Kristensen
2019-11-19 13:37:35 +01:00
parent 91674f681b
commit 9fa7393d56
4 changed files with 38 additions and 18 deletions

View File

@@ -251,11 +251,11 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
* causes an exception to be thrown.
*/
DataFlow::Node getThrowsToNode() {
if exists(this.getEnclosingStmt().getEnclosingTryStmt())
if exists(this.getEnclosingStmt().getEnclosingTryCatchStmt())
then
result = DataFlow::parameterNode(this
.getEnclosingStmt()
.getEnclosingTryStmt()
.getEnclosingTryCatchStmt()
.getACatchClause()
.getAParameter())
else result = any(DataFlow::FunctionNode f | f.getFunction() = this.getContainer()).getExceptionalReturn()

View File

@@ -57,12 +57,13 @@ class Stmt extends @stmt, ExprOrStmt, Documentable {
override predicate isAmbient() { hasDeclareKeyword(this) or getParent().isAmbient() }
/**
* Gets the `try` statement containing this statement without crossing function
* boundaries or other `try ` statements.
* Gets the `try` statement with a catch block containing this statement without
* crossing function boundaries or other `try ` statements with catch blocks.
*/
TryStmt getEnclosingTryStmt() {
TryStmt getEnclosingTryCatchStmt() {
getParentStmt+() = result.getBody() and
not exists(TryStmt mid |
exists(result.getACatchClause()) and
not exists(TryStmt mid | exists(mid.getACatchClause()) |
getParentStmt+() = mid.getBody() and mid.getParentStmt+() = result.getBody()
)
}