File tree Expand file tree Collapse file tree 8 files changed +57
-0
lines changed
src/semmle/javascript/dataflow
test/library-tests/ClassNode Expand file tree Collapse file tree 8 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -1078,6 +1078,16 @@ module DataFlow {
10781078 )
10791079 }
10801080
1081+ /**
1082+ * Holds if there is a step from `pred` to `succ` through a field accessed through `this` in a class.
1083+ */
1084+ predicate localFieldStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
1085+ exists ( ClassNode cls , string prop |
1086+ pred = cls .getAReceiverNode ( ) .getAPropertyWrite ( prop ) .getRhs ( ) and
1087+ succ = cls .getAReceiverNode ( ) .getAPropertyRead ( prop )
1088+ )
1089+ }
1090+
10811091 /**
10821092 * Gets the data flow node representing the source of definition `def`, taking
10831093 * flow through IIFE calls into account.
Original file line number Diff line number Diff line change 1+ | tst2.js:3:14:3:14 | x | tst2.js:7:5:7:10 | this.x |
2+ | tst2.js:3:14:3:14 | x | tst2.js:8:25:8:30 | this.x |
3+ | tst2.js:3:14:3:14 | x | tst2.js:12:12:12:17 | this.x |
Original file line number Diff line number Diff line change 1+ import javascript
2+
3+ from DataFlow:: Node pred , DataFlow:: Node succ
4+ where DataFlow:: localFieldStep ( pred , succ )
5+ select pred , succ
Original file line number Diff line number Diff line change 11| namespace.js:5:32:5:44 | function() {} | Baz.method | method |
2+ | tst2.js:6:9:9:3 | () {\\n ... .x;\\n } | C.method | method |
3+ | tst2.js:11:13:13:3 | () {\\n ... .x;\\n } | C.getter | getter |
24| tst.js:4:17:4:21 | () {} | A.instanceMethod | method |
35| tst.js:7:6:7:10 | () {} | A.bar | method |
46| tst.js:9:10:9:14 | () {} | A.baz | getter |
Original file line number Diff line number Diff line change 11| namespace.js:5:32:5:44 | function() {} | Baz.method |
2+ | tst2.js:6:9:9:3 | () {\\n ... .x;\\n } | C.method |
23| tst.js:4:17:4:21 | () {} | A.instanceMethod |
34| tst.js:7:6:7:10 | () {} | A.bar |
45| tst.js:17:19:17:31 | function() {} | B.foo |
Original file line number Diff line number Diff line change 1+ | namespace.js:3:15:3:31 | function Baz() {} | namespace.js:3:15:3:14 | this |
2+ | namespace.js:3:15:3:31 | function Baz() {} | namespace.js:5:32:5:31 | this |
3+ | tst2.js:1:1:14:1 | class C ... ;\\n }\\n} | tst2.js:2:14:2:13 | this |
4+ | tst2.js:1:1:14:1 | class C ... ;\\n }\\n} | tst2.js:6:9:6:8 | this |
5+ | tst2.js:1:1:14:1 | class C ... ;\\n }\\n} | tst2.js:11:13:11:12 | this |
6+ | tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:3:9:3:8 | this |
7+ | tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:4:17:4:16 | this |
8+ | tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:7:6:7:5 | this |
9+ | tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:9:10:9:9 | this |
10+ | tst.js:13:1:13:21 | class A ... ds A {} | tst.js:13:20:13:19 | this |
11+ | tst.js:15:1:15:15 | function B() {} | tst.js:15:1:15:0 | this |
12+ | tst.js:15:1:15:15 | function B() {} | tst.js:17:19:17:18 | this |
13+ | tst.js:19:1:19:15 | function C() {} | tst.js:19:1:19:0 | this |
14+ | tst.js:19:1:19:15 | function C() {} | tst.js:21:19:21:18 | this |
15+ | tst.js:23:1:23:15 | function D() {} | tst.js:23:1:23:0 | this |
16+ | tst.js:23:1:23:15 | function D() {} | tst.js:25:13:25:12 | this |
17+ | tst.js:23:1:23:15 | function D() {} | tst.js:26:13:26:12 | this |
18+ | tst.js:23:1:23:15 | function D() {} | tst.js:27:4:27:3 | this |
Original file line number Diff line number Diff line change 1+ import javascript
2+
3+ from DataFlow:: ClassNode cls
4+ select cls , cls .getAReceiverNode ( )
Original file line number Diff line number Diff line change 1+ class C {
2+ constructor ( x ) {
3+ this . x = x ;
4+ }
5+
6+ method ( ) {
7+ this . x ;
8+ let closure = ( ) => this . x ;
9+ }
10+
11+ get getter ( ) {
12+ return this . x ;
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments