Skip to content

Commit 47e425a

Browse files
Max Schaefererik-krogh
authored andcommitted
Improve inVoidContext to take conditional expressions into account.
1 parent 2f436c8 commit 47e425a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ predicate inVoidContext(Expr e) {
3737
)
3838
or
3939
exists(LogicalBinaryExpr logical | e = logical.getRightOperand() and inVoidContext(logical))
40+
or
41+
exists(ConditionalExpr cond | e = cond.getABranch() | inVoidContext(cond))
4042
}
4143

4244
/**

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
| tst.js:50:3:50:49 | new Syn ... o me?") | This expression has no effect. |
1111
| tst.js:51:3:51:36 | new Err ... age(e)) | This expression has no effect. |
1212
| tst.js:62:2:62:20 | o.trivialNonGetter1 | This expression has no effect. |
13+
| tst.js:78:24:78:24 | o | This expression has no effect. |
1314
| uselessfn.js:1:1:1:15 | (functi ... .");\\n}) | This expression has no effect. |

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/tst.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@ function g() {
7373
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
7474
o.nonTrivialGetter2; // OK
7575

76-
(o: empty); // OK.
76+
(o: empty); // OK
77+
78+
testSomeCondition() ? o : // NOT OK
79+
doSomethingDangerous();
80+
81+
consume(testSomeCondition() ? o : // OK
82+
doSomethingDangerous());
7783
};

0 commit comments

Comments
 (0)