Skip to content

Commit 46b5ded

Browse files
committed
JS: Enhance void context propagation
1 parent bf48b59 commit 46b5ded

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ predicate inVoidContext(Expr e) {
2222
)
2323
)
2424
or
25+
// propagate void context through parenthesized expressions
26+
inVoidContext(e.getParent().(ParExpr))
27+
or
2528
exists(SeqExpr seq, int i, int n |
2629
e = seq.getOperand(i) and
2730
n = seq.getNumOperands()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
| tst.js:49:3:49:49 | new Syn ... o me?") | This expression has no effect. |
1212
| tst.js:50:3:50:36 | new Err ... age(e)) | This expression has no effect. |
1313
| tst.js:61:2:61:20 | o.trivialNonGetter1 | This expression has no effect. |
14+
| tst.js:75:3:75:3 | o | This expression has no effect. |
1415
| tst.js:77:24:77:24 | o | This expression has no effect. |
16+
| uselessfn.js:1:2:1:26 | functio ... d.");\\n} | This expression has no effect. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function g() {
7272
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
7373
o.nonTrivialGetter2;
7474

75-
(o: empty);
75+
(o: empty); // $SPURIOUS:Alert
7676

7777
testSomeCondition() ? o : // $ Alert
7878
doSomethingDangerous();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(function f() { // $MISSING: Alert
1+
(function f() { // $ Alert
22
console.log("I'm never called.");
33
})

0 commit comments

Comments
 (0)