Skip to content

Commit 9653fbd

Browse files
authored
Merge pull request #1311 from emarteca/unreachableThrows
Approved by xiemaisi
2 parents 13e04f4 + 893f62f commit 9653fbd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| Server-side URL redirect | Fewer false-positive results | This rule now treats URLs as safe in more cases where the hostname cannot be tampered with. |
3939
| Type confusion through parameter tampering | Fewer false-positive results | This rule now recognizes additional emptiness checks. |
4040
| Useless assignment to property | Fewer false-positive results | This rule now ignore reads of additional getters. |
41+
| Unreachable statement | Unreachable throws no longer give an alert | This ignores unreachable throws, as they could be intentional (for example, to placate the TS compiler). |
4142

4243
## Changes to QL libraries
4344

javascript/ql/src/Statements/UnreachableStatement.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ where
2626
// ignore ambient statements
2727
not s.isAmbient() and
2828
// ignore empty statements
29-
not s instanceof EmptyStmt
29+
not s instanceof EmptyStmt and
30+
// ignore unreachable throws
31+
not s instanceof ThrowStmt
3032
select s.(FirstLineOf), "This statement is unreachable."

javascript/ql/test/query-tests/Statements/UnreachableStatement/tst.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,9 @@ function f(){
7373
return z;
7474
}; // ';' is unreachable, but alert is squelched
7575
}
76+
77+
// test for unreachable throws
78+
function z() {
79+
return 10;
80+
throw new Error(); // this throws is unreachable, but alert should not be produced
81+
}

0 commit comments

Comments
 (0)