Skip to content

Commit 95a1edc

Browse files
committed
refactor FunctionStyleClass to get a better join-order
1 parent 4d33407 commit 95a1edc

File tree

1 file changed

+12
-5
lines changed
  • javascript/ql/src/semmle/javascript/dataflow

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,16 @@ module ClassNode {
11721172
result.getFile() = f
11731173
}
11741174

1175+
/**
1176+
* Gets a reference to the function `func`, where there exists a read/write of the "prototype" property on that reference.
1177+
*/
1178+
pragma[noinline]
1179+
private DataFlow::SourceNode getAFunctionValueWithPrototype(AbstractValue func) {
1180+
exists(result.getAPropertyReference("prototype")) and
1181+
result.analyze().getAValue() = pragma[only_bind_into](func) and
1182+
func instanceof AbstractFunction // the join-order goes bad if `func` has type `AbstractFunction`.
1183+
}
1184+
11751185
/**
11761186
* A function definition with prototype manipulation as a `ClassNode` instance.
11771187
*/
@@ -1182,10 +1192,7 @@ module ClassNode {
11821192
FunctionStyleClass() {
11831193
function.getFunction() = astNode and
11841194
(
1185-
exists(DataFlow::PropRef read |
1186-
read.getPropertyName() = "prototype" and
1187-
read.getBase().analyze().getAValue() = function
1188-
)
1195+
exists(getAFunctionValueWithPrototype(function))
11891196
or
11901197
exists(string name |
11911198
this = AccessPath::getAnAssignmentTo(name) and
@@ -1246,7 +1253,7 @@ module ClassNode {
12461253
* Gets a reference to the prototype of this class.
12471254
*/
12481255
DataFlow::SourceNode getAPrototypeReference() {
1249-
exists(DataFlow::SourceNode base | base.analyze().getAValue() = function |
1256+
exists(DataFlow::SourceNode base | base = getAFunctionValueWithPrototype(function) |
12501257
result = base.getAPropertyRead("prototype")
12511258
or
12521259
result = base.getAPropertySource("prototype")

0 commit comments

Comments
 (0)