Skip to content

Commit a54a73c

Browse files
committed
JS: Detect more FunctionStyleClasses
1 parent 4ab7ace commit a54a73c

File tree

1 file changed

+12
-3
lines changed
  • javascript/ql/lib/semmle/javascript/dataflow

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,12 @@ module ClassNode {
12621262
result.getFile() = f
12631263
}
12641264

1265+
pragma[nomagic]
1266+
private DataFlow::NewNode getAnInstantiationInFile(string name, File f) {
1267+
result = AccessPath::getAReferenceTo(name).(DataFlow::LocalSourceNode).getAnInstantiation() and
1268+
result.getFile() = f
1269+
}
1270+
12651271
/**
12661272
* Gets a reference to the function `func`, where there exists a read/write of the "prototype" property on that reference.
12671273
*/
@@ -1273,7 +1279,7 @@ module ClassNode {
12731279
}
12741280

12751281
/**
1276-
* A function definition with prototype manipulation as a `ClassNode` instance.
1282+
* A function definition, targeted by a `new`-call or with prototype manipulation, seen as a `ClassNode` instance.
12771283
*/
12781284
class FunctionStyleClass extends Range, DataFlow::ValueNode {
12791285
override Function astNode;
@@ -1284,9 +1290,12 @@ module ClassNode {
12841290
(
12851291
exists(getAFunctionValueWithPrototype(function))
12861292
or
1287-
exists(string name |
1288-
this = AccessPath::getAnAssignmentTo(name) and
1293+
function = any(NewNode new).getCalleeNode().analyze().getAValue()
1294+
or
1295+
exists(string name | this = AccessPath::getAnAssignmentTo(name) |
12891296
exists(getAPrototypeReferenceInFile(name, this.getFile()))
1297+
or
1298+
exists(getAnInstantiationInFile(name, this.getFile()))
12901299
)
12911300
)
12921301
}

0 commit comments

Comments
 (0)