Skip to content

Commit 741a573

Browse files
committed
JS: Replace use of Type in MissingAwait
1 parent 3d0f11b commit 741a573

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

javascript/ql/lib/semmle/javascript/internal/TypeResolution.qll

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ module TypeResolution {
303303
}
304304
}
305305

306+
module ValueHasProperty<nodeSig/1 typeHasProperty> {
307+
predicate valueHasProperty(Node value) {
308+
exists(Node type |
309+
valueHasType(value, type) and
310+
typeHasProperty(type)
311+
)
312+
}
313+
}
314+
306315
private predicate isSanitizingPrimitiveTypeBase(Node node) {
307316
node.(TypeExpr).isNumbery()
308317
or
@@ -337,10 +346,18 @@ module TypeResolution {
337346
*
338347
* See `isSanitizingPrimitiveType`.
339348
*/
340-
predicate valueHasSanitizingPrimitiveType(Node value) {
341-
exists(Node type |
342-
valueHasType(value, type) and
343-
isSanitizingPrimitiveType(type)
344-
)
345-
}
349+
predicate valueHasSanitizingPrimitiveType =
350+
ValueHasProperty<isSanitizingPrimitiveType/1>::valueHasProperty/1;
351+
352+
private predicate isPromiseBase(Node node) { exists(unwrapPromiseType(node)) }
353+
354+
/**
355+
* Holds if the given type is a Promise object. Does not hold for unions unless all parts of the union are promises.
356+
*/
357+
predicate isPromiseType = TrackMustProp<isPromiseBase/1>::hasProperty/1;
358+
359+
/**
360+
* Holds if the given value has a type that implied it is a Promise object. Does not hold for unions unless all parts of the union are promises.
361+
*/
362+
predicate valueHasPromiseType = ValueHasProperty<isPromiseType/1>::valueHasProperty/1;
346363
}

javascript/ql/src/Expressions/MissingAwait.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import javascript
12+
private import semmle.javascript.internal.TypeResolution
1213

1314
/**
1415
* Holds if `call` is a call to an `async` function.
@@ -27,7 +28,7 @@ predicate isPromise(DataFlow::SourceNode node, boolean nullable) {
2728
isAsyncCall(node, nullable)
2829
or
2930
not isAsyncCall(node, _) and
30-
node.asExpr().getType() instanceof PromiseType and
31+
TypeResolution::valueHasPromiseType(node.asExpr()) and
3132
nullable = true
3233
}
3334

0 commit comments

Comments
 (0)