Skip to content

Commit 2d82a55

Browse files
authored
Merge pull request #1608 from asger-semmle/thisnode-basicblock
Approved by xiemaisi
2 parents f70e7d7 + e9c03c9 commit 2d82a55

File tree

6 files changed

+95
-12
lines changed

6 files changed

+95
-12
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,10 @@ module DataFlow {
788788
function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
789789
}
790790

791+
override BasicBlock getBasicBlock() {
792+
result = function.(ExprOrStmt).getBasicBlock()
793+
}
794+
791795
/**
792796
* Gets the function corresponding to this exceptional return node.
793797
*/
@@ -810,6 +814,10 @@ module DataFlow {
810814
invoke.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
811815
}
812816

817+
override BasicBlock getBasicBlock() {
818+
result = invoke.getBasicBlock()
819+
}
820+
813821
/**
814822
* Gets the invocation corresponding to this exceptional return node.
815823
*/
@@ -991,6 +999,30 @@ module DataFlow {
991999
override ControlFlowNode getWriteNode() { result = arr }
9921000
}
9931001

1002+
/**
1003+
* A data flow node representing `this` in a function or top-level.
1004+
*/
1005+
private class ThisNodeInternal extends Node, TThisNode {
1006+
override string toString() { result = "this" }
1007+
1008+
override BasicBlock getBasicBlock() {
1009+
exists(StmtContainer container | this = TThisNode(container) |
1010+
result = container.getEntry()
1011+
)
1012+
}
1013+
1014+
override predicate hasLocationInfo(
1015+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1016+
) {
1017+
// Use the function entry as the location
1018+
exists(StmtContainer container | this = TThisNode(container) |
1019+
container.getEntry()
1020+
.getLocation()
1021+
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1022+
)
1023+
}
1024+
}
1025+
9941026
/**
9951027
* Gets the data flow node corresponding to `nd`.
9961028
*

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,6 @@ class ThisNode extends DataFlow::Node, DataFlow::SourceNode {
276276
* which is the nearest enclosing non-arrow function or top-level.
277277
*/
278278
StmtContainer getBindingContainer() { DataFlow::thisNode(this, result) }
279-
280-
override string toString() { result = "this" }
281-
282-
override predicate hasLocationInfo(
283-
string filepath, int startline, int startcolumn, int endline, int endcolumn
284-
) {
285-
// Use the function entry as the location
286-
getBindingContainer()
287-
.getEntry()
288-
.getLocation()
289-
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
290-
}
291279
}
292280

293281
/** A data flow node corresponding to a global variable access. */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| tst.js:1:10:1:11 | fs |
2+
| tst.js:1:10:1:11 | fs |
3+
| tst.js:1:20:1:23 | 'fs' |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import javascript
2+
3+
from DataFlow::Node node
4+
where not exists(node.getBasicBlock())
5+
select node
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
missingBasicBlock
2+
basicBlock
3+
| tst.js:1:1:1:0 | this | tst.js:1:1:1:0 | entry node of <toplevel> |
4+
| tst.js:1:16:1:15 | this | tst.js:1:16:1:15 | entry node of () {} |
5+
| tst.js:3:7:3:6 | this | tst.js:3:7:3:6 | entry node of () {\\n ... ;\\n } |
6+
| tst.js:7:7:7:6 | this | tst.js:7:7:7:6 | entry node of () {\\n ... ;\\n } |
7+
| tst.js:13:14:13:13 | this | tst.js:13:14:13:13 | entry node of () {} |
8+
| tst.js:15:13:15:12 | this | tst.js:15:13:15:12 | entry node of () {\\n ... ;\\n } |
9+
| tst.js:16:10:16:9 | this | tst.js:16:10:16:9 | entry node of functio ... } |
10+
| tst.js:21:13:21:12 | this | tst.js:21:13:21:12 | entry node of () {\\n ... ;\\n } |
11+
| tst.js:23:10:23:9 | this | tst.js:23:10:23:9 | entry node of functio ... } |
12+
| tst.js:28:13:28:12 | this | tst.js:28:13:28:12 | entry node of () {\\n ... ;\\n } |
13+
| tst.js:29:9:29:8 | this | tst.js:29:9:29:8 | entry node of functio ... } |
14+
| tst.js:35:13:35:12 | this | tst.js:35:13:35:12 | entry node of () {\\n ... ;\\n } |
15+
| tst.js:36:10:36:9 | this | tst.js:36:10:36:9 | entry node of functio ... } |
16+
| tst.js:37:14:37:13 | this | tst.js:37:14:37:13 | entry node of functio ... } |
17+
| tst.js:45:14:45:13 | this | tst.js:45:14:45:13 | entry node of () {} |
18+
| tst.js:47:13:47:12 | this | tst.js:47:13:47:12 | entry node of () {\\n ... ;\\n } |
19+
| tst.js:48:10:48:9 | this | tst.js:48:10:48:9 | entry node of functio ... } |
20+
| tst.js:55:15:55:14 | this | tst.js:55:15:55:14 | entry node of () {} |
21+
| tst.js:57:13:57:12 | this | tst.js:57:13:57:12 | entry node of () {\\n ... ;\\n } |
22+
| tst.js:59:10:59:9 | this | tst.js:59:10:59:9 | entry node of functio ... } |
23+
| tst.js:66:13:66:12 | this | tst.js:66:13:66:12 | entry node of () {} |
24+
| tst.js:68:13:68:12 | this | tst.js:68:13:68:12 | entry node of () {\\n ... ;\\n } |
25+
| tst.js:69:15:69:14 | this | tst.js:69:15:69:14 | entry node of functio ... } |
26+
| tst.js:74:13:74:12 | this | tst.js:74:13:74:12 | entry node of () {\\n ... )\\n } |
27+
| tst.js:76:10:76:9 | this | tst.js:76:10:76:9 | entry node of functio ... } |
28+
| tst.js:83:22:83:21 | this | tst.js:83:22:83:21 | entry node of () {} |
29+
| tst.js:85:13:85:12 | this | tst.js:85:13:85:12 | entry node of () {\\n ... `\\n } |
30+
| tst.js:87:21:87:20 | this | tst.js:87:21:87:20 | entry node of functio ... } |
31+
| tst.js:95:13:95:12 | this | tst.js:95:13:95:12 | entry node of () {\\n ... ;\\n } |
32+
| tst.js:96:9:96:8 | this | tst.js:96:9:96:8 | entry node of functio ... } |
33+
| tst.js:105:20:105:19 | this | tst.js:105:20:105:19 | entry node of () {} |
34+
| tst.js:107:13:107:12 | this | tst.js:107:13:107:12 | entry node of () {\\n ... ;\\n } |
35+
| tst.js:108:18:108:17 | this | tst.js:108:18:108:17 | entry node of functio ... } |
36+
| tst.js:113:13:113:12 | this | tst.js:113:13:113:12 | entry node of () {\\n ... ;\\n } |
37+
| tst.js:114:21:114:20 | this | tst.js:114:21:114:20 | entry node of functio ... } |
38+
| tst.js:119:13:119:12 | this | tst.js:119:13:119:12 | entry node of () {\\n ... ;\\n } |
39+
| tst.js:120:27:120:26 | this | tst.js:120:27:120:26 | entry node of functio ... } |
40+
| tst.js:128:16:128:15 | this | tst.js:128:16:128:15 | entry node of () {} |
41+
| tst.js:130:13:130:12 | this | tst.js:130:13:130:12 | entry node of () {\\n ... ;\\n } |
42+
| tst.js:131:18:131:17 | this | tst.js:131:18:131:17 | entry node of functio ... } |
43+
| tst.js:136:13:136:12 | this | tst.js:136:13:136:12 | entry node of () {\\n ... ;\\n } |
44+
| tst.js:137:21:137:20 | this | tst.js:137:21:137:20 | entry node of functio ... } |
45+
| tst.js:142:13:142:12 | this | tst.js:142:13:142:12 | entry node of () {\\n ... ;\\n } |
46+
| tst.js:143:23:143:22 | this | tst.js:143:23:143:22 | entry node of functio ... } |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import javascript
2+
3+
query predicate missingBasicBlock(DataFlow::ThisNode node) {
4+
not exists(node.getBasicBlock())
5+
}
6+
7+
query BasicBlock basicBlock(DataFlow::ThisNode node) {
8+
result = node.getBasicBlock()
9+
}

0 commit comments

Comments
 (0)