Skip to content

Commit a6b7f2d

Browse files
authored
Merge pull request #1561 from xiemaisi/js/await-sourcenode
Approved by asger-semmle
2 parents 10172af + fec87ac commit a6b7f2d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

javascript/ql/src/semmle/javascript/dataflow/Sources.qll

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,13 @@ module SourceNode {
200200
/**
201201
* A data flow node that is considered a source node by default.
202202
*
203-
* Currently, the following nodes are source nodes:
203+
* This includes all nodes that evaluate to a new object and all nodes whose
204+
* value is computed using non-local data flow (that is, flow between functions,
205+
* between modules, or through the heap):
206+
*
204207
* - import specifiers
205208
* - function parameters
206-
* - `this` nodes
209+
* - function receivers
207210
* - property accesses
208211
* - function invocations
209212
* - global variable accesses
@@ -213,6 +216,12 @@ module SourceNode {
213216
* - array expressions
214217
* - JSX literals
215218
* - regular expression literals
219+
* - `yield` expressions
220+
* - `await` expressions
221+
* - dynamic `import` expressions
222+
* - function-bind expressions
223+
* - `function.sent` expressions
224+
* - comprehension expressions.
216225
*
217226
* This class is for internal use only and should not normally be used directly.
218227
*/
@@ -227,7 +236,13 @@ module SourceNode {
227236
astNode instanceof JSXNode or
228237
astNode instanceof GlobalVarAccess or
229238
astNode instanceof ExternalModuleReference or
230-
astNode instanceof RegExpLiteral
239+
astNode instanceof RegExpLiteral or
240+
astNode instanceof YieldExpr or
241+
astNode instanceof ComprehensionExpr or
242+
astNode instanceof AwaitExpr or
243+
astNode instanceof FunctionSentExpr or
244+
astNode instanceof FunctionBindExpr or
245+
astNode instanceof DynamicImportExpr
231246
)
232247
or
233248
this = DataFlow::ssaDefinitionNode(SSA::definition(any(ImportSpecifier imp)))

javascript/ql/test/library-tests/DataFlow/sources.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,24 @@
4343
| tst.js:50:14:53:3 | () {\\n ... et`\\n } |
4444
| tst.js:51:5:51:13 | super(42) |
4545
| tst.js:58:1:58:3 | tag |
46+
| tst.js:61:1:61:5 | ::o.m |
4647
| tst.js:61:3:61:5 | o.m |
48+
| tst.js:62:1:62:4 | o::g |
4749
| tst.js:64:1:64:0 | this |
4850
| tst.js:64:1:67:1 | functio ... lysed\\n} |
51+
| tst.js:65:3:65:10 | yield 42 |
52+
| tst.js:66:13:66:25 | function.sent |
4953
| tst.js:68:12:68:14 | h() |
5054
| tst.js:69:1:69:9 | iter.next |
5155
| tst.js:69:1:69:13 | iter.next(23) |
5256
| tst.js:71:1:71:0 | this |
5357
| tst.js:71:1:73:1 | async f ... lysed\\n} |
58+
| tst.js:72:3:72:11 | await p() |
5459
| tst.js:72:9:72:9 | p |
5560
| tst.js:72:9:72:11 | p() |
61+
| tst.js:75:9:75:21 | import('foo') |
62+
| tst.js:83:11:83:28 | [ for (v of o) v ] |
63+
| tst.js:85:11:85:28 | ( for (v of o) v ) |
5664
| tst.js:87:1:96:2 | (functi ... r: 0\\n}) |
5765
| tst.js:87:2:87:1 | this |
5866
| tst.js:87:2:92:1 | functio ... + z;\\n} |

0 commit comments

Comments
 (0)