Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2993b9

Browse files
author
Max Schaefer
committed
JavaScript: Model data flow of destructuring assignments more precisely.
1 parent c577f6d commit d2993b9

5 files changed

Lines changed: 31 additions & 1 deletion

File tree

javascript/ql/src/semmle/javascript/BasicBlocks.qll

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,27 @@ private cached module Internal {
6767
}
6868

6969
cached predicate defAt(BasicBlock bb, int i, Variable v, VarDef d) {
70-
v = d.getAVariable() and bbIndex(bb, d, i)
70+
exists (VarRef def |
71+
def = d.getTarget().(BindingPattern).getABindingVarRef() and
72+
v = def.getVariable() |
73+
def = d.getTarget() and
74+
bbIndex(bb, d, i)
75+
or
76+
exists (PropertyPattern pp |
77+
def = pp.getValuePattern() and
78+
bbIndex(bb, pp, i)
79+
)
80+
or
81+
exists (ObjectPattern op |
82+
def = op.getRest() and
83+
bbIndex(bb, def, i)
84+
)
85+
or
86+
exists (ArrayPattern ap |
87+
def = ap.getAnElement() and
88+
bbIndex(bb, def, i)
89+
)
90+
)
7191
}
7292

7393
cached predicate reachableBB(BasicBlock bb) {

javascript/ql/test/library-tests/Flow/AbstractValues.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
| d.js:1:1:4:0 | exports object of module d |
6060
| d.js:1:1:4:0 | module object of module d |
6161
| d.js:1:18:3:1 | object literal |
62+
| destructuring.js:1:1:4:1 | function f |
63+
| destructuring.js:1:1:4:1 | instance of function f |
6264
| e.js:1:1:6:0 | exports object of module e |
6365
| e.js:1:1:6:0 | module object of module e |
6466
| es2015.js:1:1:50:0 | exports object of module es2015 |

javascript/ql/test/library-tests/Flow/abseval.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
| classAccessors.js:11:9:11:11 | myY | classAccessors.js:11:15:11:20 | this.y | file://:0:0:0:0 | indefinite value (heap) |
6969
| classAccessors.js:12:9:12:11 | myZ | classAccessors.js:12:15:12:20 | this.z | file://:0:0:0:0 | indefinite value (call) |
7070
| classAccessors.js:12:9:12:11 | myZ | classAccessors.js:12:15:12:20 | this.z | file://:0:0:0:0 | indefinite value (heap) |
71+
| destructuring.js:2:7:2:24 | { x, y = (z = x) } | destructuring.js:2:28:2:28 | o | file://:0:0:0:0 | indefinite value (call) |
72+
| destructuring.js:3:7:3:8 | z1 | destructuring.js:3:12:3:12 | z | file://:0:0:0:0 | indefinite value (heap) |
7173
| es2015.js:1:5:1:7 | Sup | es2015.js:1:11:6:1 | class { ... ;\\n }\\n} | es2015.js:1:11:6:1 | class Sup |
7274
| es2015.js:4:9:4:12 | ctor | es2015.js:4:16:4:25 | new.target | file://:0:0:0:0 | indefinite value (call) |
7375
| es2015.js:19:7:19:11 | _args | es2015.js:19:15:19:18 | args | file://:0:0:0:0 | object |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function f(o) {
2+
var { x, y = (z = x) } = o, z;
3+
var z1 = z;
4+
}

javascript/ql/test/library-tests/Flow/types.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
| classAccessors.js:10:9:10:11 | myX | classAccessors.js:10:15:10:20 | this.x | boolean, class, date, function, null, number, object, regular expression,string or undefined |
3939
| classAccessors.js:11:9:11:11 | myY | classAccessors.js:11:15:11:20 | this.y | boolean, class, date, function, null, number, object, regular expression,string or undefined |
4040
| classAccessors.js:12:9:12:11 | myZ | classAccessors.js:12:15:12:20 | this.z | boolean, class, date, function, null, number, object, regular expression,string or undefined |
41+
| destructuring.js:2:7:2:24 | { x, y = (z = x) } | destructuring.js:2:28:2:28 | o | boolean, class, date, function, null, number, object, regular expression,string or undefined |
42+
| destructuring.js:3:7:3:8 | z1 | destructuring.js:3:12:3:12 | z | boolean, class, date, function, null, number, object, regular expression,string or undefined |
4143
| es2015.js:1:5:1:7 | Sup | es2015.js:1:11:6:1 | class { ... ;\\n }\\n} | class |
4244
| es2015.js:4:9:4:12 | ctor | es2015.js:4:16:4:25 | new.target | boolean, class, date, function, null, number, object, regular expression,string or undefined |
4345
| es2015.js:19:7:19:11 | _args | es2015.js:19:15:19:18 | args | object |

0 commit comments

Comments
 (0)