Skip to content

Commit 30a8769

Browse files
committed
JS: Add more bad promise contexts
1 parent 45524d8 commit 30a8769

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

javascript/ql/src/Expressions/MissingAwait.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ predicate isBadPromiseContext(Expr expr) {
4646
expr = any(UnaryExpr e).getOperand()
4747
or
4848
expr = any(UpdateExpr e).getOperand()
49+
or
50+
expr = any(ConditionalExpr e).getCondition()
51+
or
52+
expr = any(IfStmt stmt).getCondition()
53+
or
54+
expr = any(ForInStmt stmt).getIterationDomain()
55+
or
56+
expr = any(IndexExpr e).getIndex()
4957
}
5058

5159
string tryGetPromiseExplanation(Expr e) {
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
| tst.js:8:9:8:13 | thing | Missing await. The value 'thing' is always a promise. |
2-
| tst.js:32:12:32:16 | thing | Missing await. The value 'thing' is always a promise. |
2+
| tst.js:10:9:10:13 | thing | Missing await. The value 'thing' is always a promise. |
3+
| tst.js:12:15:12:19 | thing | Missing await. The value 'thing' is always a promise. |
4+
| tst.js:14:19:14:23 | thing | Missing await. The value 'thing' is always a promise. |
5+
| tst.js:19:19:19:23 | thing | Missing await. The value 'thing' is always a promise. |
6+
| tst.js:20:9:20:13 | thing | Missing await. The value 'thing' is always a promise. |
7+
| tst.js:22:15:22:19 | thing | Missing await. The value 'thing' is always a promise. |
8+
| tst.js:25:13:25:17 | thing | Missing await. The value 'thing' is always a promise. |
9+
| tst.js:48:12:48:16 | thing | Missing await. The value 'thing' is always a promise. |

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@ function useThing() {
99

1010
if (thing == null) {} // NOT OK
1111

12-
return thing + "bar"; // NOT OK
12+
something(thing ? 1 : 2); // NOT OK
13+
14+
for (let x in thing) { // NOT OK
15+
something(x);
16+
}
17+
18+
let obj = something();
19+
something(obj[thing]); // NOT OK
20+
obj[thing] = 5; // NOT OK
21+
22+
something(thing + "bar"); // NOT OK
23+
24+
if (something()) {
25+
if (thing) { // NOT OK
26+
something(3);
27+
}
28+
}
1329
}
1430

1531
async function useThingCorrectly() {

0 commit comments

Comments
 (0)