Skip to content

Commit 244a304

Browse files
committed
JS: Implement getFile() directly instead of via locations
1 parent dc08462 commit 244a304

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ module DataFlow {
173173
}
174174

175175
/** Gets the file this data flow node comes from. */
176-
File getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
176+
File getFile() { none() } // overridden in subclasses
177177

178178
/** Gets the start line of this data flow node. */
179179
int getStartLine() { hasLocationInfo(_, result, _, _, _) }
@@ -313,6 +313,8 @@ module DataFlow {
313313
astNode.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
314314
}
315315

316+
override File getFile() { result = astNode.getFile() }
317+
316318
override string toString() { result = astNode.toString() }
317319
}
318320

@@ -337,6 +339,8 @@ module DataFlow {
337339

338340
override string toString() { result = ssa.getSourceVariable().getName() }
339341

342+
override File getFile() { result = ssa.getBasicBlock().getFile() }
343+
340344
override ASTNode getAstNode() { none() }
341345
}
342346

@@ -361,6 +365,8 @@ module DataFlow {
361365

362366
override string toString() { result = prop.(ASTNode).toString() }
363367

368+
override File getFile() { result = prop.(ASTNode).getFile() }
369+
364370
override ASTNode getAstNode() { result = prop }
365371
}
366372

@@ -384,6 +390,8 @@ module DataFlow {
384390

385391
override string toString() { result = "..." + rest.toString() }
386392

393+
override File getFile() { result = pattern.getFile() }
394+
387395
override ASTNode getAstNode() { result = rest }
388396
}
389397

@@ -406,6 +414,8 @@ module DataFlow {
406414

407415
override string toString() { result = pattern.toString() }
408416

417+
override File getFile() { result = pattern.getFile() }
418+
409419
override ASTNode getAstNode() { result = pattern }
410420
}
411421

@@ -429,6 +439,8 @@ module DataFlow {
429439

430440
override string toString() { result = elt.toString() }
431441

442+
override File getFile() { result = pattern.getFile() }
443+
432444
override ASTNode getAstNode() { result = elt }
433445
}
434446

@@ -456,6 +468,8 @@ module DataFlow {
456468

457469
override string toString() { result = elt.toString() }
458470

471+
override File getFile() { result = arr.getFile() }
472+
459473
override ASTNode getAstNode() { result = elt }
460474
}
461475

@@ -478,6 +492,8 @@ module DataFlow {
478492
}
479493

480494
override string toString() { result = "reflective call" }
495+
496+
override File getFile() { result = call.getFile() }
481497
}
482498

483499
/**
@@ -497,6 +513,8 @@ module DataFlow {
497513
}
498514

499515
override string toString() { result = imprt.toString() }
516+
517+
override File getFile() { result = imprt.getFile() }
500518
}
501519

502520
/**
@@ -924,6 +942,8 @@ module DataFlow {
924942
) {
925943
p.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
926944
}
945+
946+
override File getFile() { result = p.getFile() }
927947
}
928948

929949
/**
@@ -944,6 +964,8 @@ module DataFlow {
944964

945965
/** Gets the attribute corresponding to this data flow node. */
946966
HTML::Attribute getAttribute() { result = attr }
967+
968+
override File getFile() { result = attr.getFile() }
947969
}
948970

949971
/**
@@ -968,6 +990,8 @@ module DataFlow {
968990
* Gets the function corresponding to this exceptional return node.
969991
*/
970992
Function getFunction() { result = function }
993+
994+
override File getFile() { result = function.getFile() }
971995
}
972996

973997
/**
@@ -992,6 +1016,8 @@ module DataFlow {
9921016
* Gets the invocation corresponding to this exceptional return node.
9931017
*/
9941018
DataFlow::InvokeNode getInvocation() { result = invoke.flow() }
1019+
1020+
override File getFile() { result = invoke.getFile() }
9951021
}
9961022

9971023
/**
@@ -1219,6 +1245,10 @@ module DataFlow {
12191245
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
12201246
)
12211247
}
1248+
1249+
override File getFile() {
1250+
exists(StmtContainer container | this = TThisNode(container) | result = container.getFile())
1251+
}
12221252
}
12231253

12241254
/**

0 commit comments

Comments
 (0)