Skip to content

Commit 4f46908

Browse files
asger-semmleasgerf
authored andcommitted
JS: Add test with ES getters/setters
1 parent 7c20c4a commit 4f46908

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as dummy from 'dummy';
2+
3+
function testGetterSource() {
4+
class C {
5+
get x() {
6+
return source();
7+
}
8+
};
9+
sink(new C().x); // NOT OK
10+
11+
function indirection(c) {
12+
if (c) {
13+
sink(c.x); // NOT OK
14+
}
15+
}
16+
indirection(new C());
17+
indirection(null);
18+
}
19+
20+
function testSetterSink() {
21+
class C {
22+
set x(v) {
23+
sink(v); // NOT OK
24+
}
25+
};
26+
function indirection(c) {
27+
c.x = source();
28+
}
29+
indirection(new C());
30+
indirection(null);
31+
}
32+
33+
function testFlowThroughGetter() {
34+
class C {
35+
constructor(x) {
36+
this._x = x;
37+
}
38+
39+
get x() {
40+
return this._x;
41+
}
42+
};
43+
44+
function indirection(c) {
45+
sink(c.x); // NOT OK
46+
}
47+
indirection(new C(source()));
48+
indirection(null);
49+
50+
function getX(c) {
51+
return c.x;
52+
}
53+
sink(getX(new C(source()))); // NOT OK
54+
sink(getX(new C(source()))); // NOT OK
55+
}

0 commit comments

Comments
 (0)