Skip to content

Commit 54f191c

Browse files
committed
add support for rejected promise values in API graphs
1 parent 744c495 commit 54f191c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

javascript/ql/src/semmle/javascript/ApiGraphs.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ module API {
183183
*/
184184
Node getPromised() { result = getASuccessor(Label::promised()) }
185185

186+
/**
187+
* Gets a node representing the error wrapped in the `Promise` object represented by this node.
188+
*/
189+
Node getPromisedError() { result = getASuccessor(Label::promisedError()) }
190+
186191
/**
187192
* Gets a string representation of the lexicographically least among all shortest access paths
188193
* from the root to this node.
@@ -468,6 +473,9 @@ module API {
468473
or
469474
lbl = Label::promised() and
470475
PromiseFlow::storeStep(rhs, pred, Promises::valueProp())
476+
or
477+
lbl = Label::promisedError() and
478+
PromiseFlow::storeStep(rhs, pred, Promises::errorProp())
471479
)
472480
or
473481
exists(DataFlow::ClassNode cls, string name |
@@ -482,6 +490,12 @@ module API {
482490
rhs = f.getAReturn()
483491
)
484492
or
493+
exists(DataFlow::FunctionNode f |
494+
base = MkAsyncFuncResult(f) and
495+
lbl = Label::promisedError() and
496+
rhs = f.getExceptionalReturn()
497+
)
498+
or
485499
exists(int i |
486500
lbl = Label::parameter(i) and
487501
argumentPassing(base, i, rhs)
@@ -559,6 +573,9 @@ module API {
559573
or
560574
lbl = Label::promised() and
561575
PromiseFlow::loadStep(pred, ref, Promises::valueProp())
576+
or
577+
lbl = Label::promisedError() and
578+
PromiseFlow::loadStep(pred, ref, Promises::errorProp())
562579
)
563580
or
564581
exists(DataFlow::Node def, DataFlow::FunctionNode fn |
@@ -962,6 +979,9 @@ private module Label {
962979

963980
/** Gets the `promised` edge label connecting a promise to its contained value. */
964981
string promised() { result = "promised" }
982+
983+
/** Gets the `promisedError` edge label connecting a promise to its rejected value. */
984+
string promisedError() { result = "promisedError" }
965985
}
966986

967987
private class NodeModuleSourcesNodes extends DataFlow::SourceNode::Range {

0 commit comments

Comments
 (0)