Skip to content

Commit 440cbb7

Browse files
committed
JS: Add inline-expectation test for type tracking
1 parent 6349903 commit 440cbb7

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function m0() {
2+
const x = source("m0.1");
3+
sink(x); // $ track=m0.1
4+
}
5+
6+
function m1() {
7+
const fn = mkSummary("Argument[0]", "ReturnValue");
8+
const obj = source("m1.1");
9+
sink(fn(obj)); // $ MISSING: track=m1.1
10+
sink(fn(obj.p));
11+
sink(fn(obj).p);
12+
sink(fn({ p: obj }));
13+
sink(fn({ p: obj }).q);
14+
}
15+
16+
function m2() {
17+
const fn = mkSummary("Argument[0].Member[p]", "ReturnValue");
18+
const obj = source("m2.1");
19+
sink(fn(obj));
20+
sink(fn(obj.p));
21+
sink(fn(obj).p);
22+
sink(fn({ p: obj })); // $ MISSING: track=m2.1
23+
sink(fn({ p: obj }).q);
24+
}
25+
26+
function m3() {
27+
const fn = mkSummary("Argument[0]", "ReturnValue.Member[p]");
28+
const obj = source("m3.1");
29+
sink(fn(obj));
30+
sink(fn(obj.p));
31+
sink(fn(obj).p); // $ MISSING: track=m3.1
32+
sink(fn({ p: obj }));
33+
sink(fn({ p: obj }).q);
34+
}
35+
36+
37+
function m4() {
38+
const fn = mkSummary("Argument[0].Member[p]", "ReturnValue.Member[q]");
39+
const obj = source("m4.1");
40+
sink(fn(obj));
41+
sink(fn(obj.p));
42+
sink(fn(obj).p);
43+
sink(fn({ p: obj }));
44+
sink(fn({ p: obj }).q); // $ MISSING: track=m4.1
45+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import javascript
2+
import testUtilities.InlineSummaries
3+
import testUtilities.InlineExpectationsTest
4+
5+
private DataFlow::SourceNode typeTrack(DataFlow::TypeTracker t, string name) {
6+
t.start() and
7+
exists(DataFlow::CallNode call |
8+
call.getCalleeName() = "source" and
9+
name = call.getArgument(0).getStringValue() and
10+
result = call
11+
)
12+
or
13+
exists(DataFlow::TypeTracker t2 | result = typeTrack(t2, name).track(t2, t))
14+
}
15+
16+
DataFlow::SourceNode typeTrack(string name) {
17+
result = typeTrack(DataFlow::TypeTracker::end(), name)
18+
}
19+
20+
module TestConfig implements TestSig {
21+
string getARelevantTag() { result = "track" }
22+
23+
predicate hasActualResult(Location location, string element, string tag, string value) {
24+
element = "" and
25+
tag = "track" and
26+
exists(DataFlow::CallNode call, DataFlow::Node arg |
27+
call.getCalleeName() = "sink" and
28+
arg = call.getArgument(0) and
29+
typeTrack(value).flowsTo(arg) and
30+
location = arg.getLocation()
31+
)
32+
}
33+
34+
predicate hasOptionalResult(Location location, string element, string tag, string value) {
35+
none()
36+
}
37+
}
38+
39+
import MakeTest<TestConfig>

0 commit comments

Comments
 (0)