Skip to content

Commit e9ee713

Browse files
committed
Refactor prototype reference retrieval in ClassNode and update expected test output
1 parent c8ee8dc commit e9ee713

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ module ClassNode {
12331233
private DataFlow::SourceNode getAFunctionValueWithPrototype(AbstractValue func) {
12341234
exists(result.getAPropertyReference("prototype")) and
12351235
result.analyze().getAValue() = pragma[only_bind_into](func) and
1236-
func instanceof AbstractFunction // the join-order goes bad if `func` has type `AbstractFunction`.
1236+
func instanceof AbstractCallable // the join-order goes bad if `func` has type `AbstractFunction`.
12371237
}
12381238

12391239
/**
@@ -1413,22 +1413,26 @@ module ClassNode {
14131413
* Only applies to function-style classes.
14141414
*/
14151415
DataFlow::SourceNode getAPrototypeReference() {
1416-
(
1417-
exists(DataFlow::SourceNode base | base = getAFunctionValueWithPrototype(function) |
1418-
result = base.getAPropertyRead("prototype")
1419-
or
1420-
result = base.getAPropertySource("prototype")
1421-
)
1416+
exists(DataFlow::SourceNode base | base = getAFunctionValueWithPrototype(function) |
1417+
result = base.getAPropertyRead("prototype")
14221418
or
1423-
exists(string name |
1424-
this = AccessPath::getAnAssignmentTo(name) and
1425-
result = getAPrototypeReferenceInFile(name, this.getFile())
1426-
)
1427-
or
1428-
exists(ExtendCall call |
1429-
call.getDestinationOperand() = this.getAPrototypeReference() and
1430-
result = call.getASourceOperand()
1431-
)
1419+
result = base.getAPropertySource("prototype")
1420+
)
1421+
or
1422+
exists(string name |
1423+
this = AccessPath::getAnAssignmentTo(name) and
1424+
result = getAPrototypeReferenceInFile(name, this.getFile())
1425+
)
1426+
or
1427+
exists(string name, DataFlow::SourceNode root |
1428+
result =
1429+
AccessPath::getAReferenceOrAssignmentTo(root, name + ".prototype").getALocalSource() and
1430+
this = AccessPath::getAnAssignmentTo(root, name)
1431+
)
1432+
or
1433+
exists(ExtendCall call |
1434+
call.getDestinationOperand() = this.getAPrototypeReference() and
1435+
result = call.getASourceOperand()
14321436
)
14331437
}
14341438

javascript/ql/test/library-tests/CallGraphs/AnnotatedTest/Test.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ spuriousCallee
22
missingCallee
33
| constructor-field.ts:40:5:40:14 | f3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
44
| constructor-field.ts:71:1:71:11 | bf3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
5-
| prototypes.js:96:5:96:15 | this.read() | prototypes.js:104:27:104:39 | function() {} | -1 | calls |
6-
| prototypes.js:96:5:96:15 | this.read() | prototypes.js:109:27:109:39 | function() {} | -1 | calls |
75
badAnnotation
86
accessorCall
97
| accessors.js:12:1:12:5 | obj.f | accessors.js:5:8:5:12 | () {} |

javascript/ql/test/library-tests/ClassNode/tests.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ getAReceiverNode
1515
| tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:4:17:4:16 | this |
1616
| tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:7:6:7:5 | this |
1717
| tst.js:3:1:10:1 | class A ... () {}\\n} | tst.js:9:10:9:9 | this |
18+
| tst.js:3:9:3:8 | () {} | tst.js:3:9:3:8 | this |
1819
| tst.js:13:1:13:21 | class A ... ds A {} | tst.js:13:20:13:19 | this |
1920
| tst.js:15:1:15:15 | function B() {} | tst.js:15:1:15:0 | this |
2021
| tst.js:15:1:15:15 | function B() {} | tst.js:17:19:17:18 | this |

0 commit comments

Comments
 (0)