Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ module DataFlow {
PropReadAsSourceNode() {
this = TPropNode(any(PropertyPattern p)) or
this instanceof RestPatternNode or
this instanceof ElementPatternNode
this instanceof ElementPatternNode or
this = lvalueNode(any(ForOfStmt stmt).getLValue())
}
}

Expand Down Expand Up @@ -826,6 +827,24 @@ module DataFlow {
override string getPropertyName() { result = astNode.getImportedName() }
}

/**
* The left-hand side of a `for..of` statement, seen as a property read
* on the object being iterated over.
*/
private class ForOfLvalueAsPropRead extends PropRead {
ForOfStmt stmt;

ForOfLvalueAsPropRead() {
this = lvalueNode(stmt.getLValue())
}

override Node getBase() { result = stmt.getIterationDomain().flow() }

override Expr getPropertyNameExpr() { none() }

override string getPropertyName() { none() }
}

/**
* A data flow node representing an unused parameter.
*
Expand Down
5 changes: 5 additions & 0 deletions javascript/ql/test/library-tests/DataFlow/flowStep.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
| sources.js:3:11:3:11 | x | sources.js:4:10:4:10 | x |
| sources.js:4:10:4:13 | x+19 | sources.js:3:1:5:6 | (functi ... \\n})(23) |
| sources.js:5:4:5:5 | 23 | sources.js:3:11:3:11 | x |
| sources.js:9:14:9:18 | array | sources.js:10:19:10:23 | array |
| sources.js:9:14:9:18 | array | sources.js:11:23:11:27 | array |
| sources.js:10:12:10:14 | key | sources.js:10:28:10:30 | key |
| sources.js:11:12:11:18 | key | sources.js:11:32:11:34 | key |
| sources.js:11:14:11:16 | key | sources.js:11:12:11:18 | key |
| tst.js:1:1:1:1 | x | tst.js:28:2:28:1 | x |
| tst.js:1:1:1:1 | x | tst.js:32:1:32:0 | x |
| tst.js:1:10:1:11 | fs | tst.js:1:10:1:11 | fs |
Expand Down
5 changes: 5 additions & 0 deletions javascript/ql/test/library-tests/DataFlow/incomplete.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
| sources.js:1:6:1:11 | exceptional return of anonymous function | call |
| sources.js:3:1:5:6 | exceptional return of (functi ... \\n})(23) | call |
| sources.js:3:2:5:1 | exceptional return of anonymous function | call |
| sources.js:9:1:12:1 | exceptional return of function foo | call |
| sources.js:9:14:9:18 | array | call |
| sources.js:10:12:10:14 | key | heap |
| sources.js:11:12:11:18 | key | heap |
| sources.js:11:14:11:16 | key | heap |
| tst.js:1:10:1:11 | fs | import |
| tst.js:16:1:20:9 | exceptional return of (functi ... ("arg") | call |
| tst.js:16:2:20:1 | exceptional return of function f | call |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| sources.js:1:6:1:6 | x |
| sources.js:3:11:3:11 | x |
| sources.js:9:14:9:18 | array |
| tst.js:16:13:16:13 | a |
| tst.js:32:12:32:12 | b |
| tst.js:87:11:87:24 | { p: x, ...o } |
Expand Down
7 changes: 7 additions & 0 deletions javascript/ql/test/library-tests/DataFlow/sources.expected
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
| sources.js:3:2:5:1 | functio ... x+19;\\n} |
| sources.js:3:11:3:11 | x |
| sources.js:7:1:7:3 | /x/ |
| sources.js:9:1:9:0 | this |
| sources.js:9:1:12:1 | functio ... ey; }\\n} |
| sources.js:9:14:9:18 | array |
| sources.js:10:12:10:14 | key |
| sources.js:11:12:11:18 | { key } |
| sources.js:11:14:11:16 | key |
| tst.js:1:1:1:0 | this |
| tst.js:1:1:1:24 | import ... m 'fs'; |
| tst.js:1:10:1:11 | fs |
Expand Down Expand Up @@ -60,6 +66,7 @@
| tst.js:72:9:72:9 | p |
| tst.js:72:9:72:11 | p() |
| tst.js:75:9:75:21 | import('foo') |
| tst.js:80:10:80:10 | v |
| tst.js:83:11:83:28 | [ for (v of o) v ] |
| tst.js:85:11:85:28 | ( for (v of o) v ) |
| tst.js:87:1:96:2 | (functi ... r: 0\\n}) |
Expand Down
5 changes: 5 additions & 0 deletions javascript/ql/test/library-tests/DataFlow/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ new (x => x);
})(23);

/x/;

function foo(array) {
for (let key of array) { key; }
for (let { key } of array) { key; }
}