Skip to content

Commit bfd80b4

Browse files
authored
Merge pull request github#3260 from asger-semmle/js/___location-tweaks
Approved by erik-krogh
2 parents 34d40b5 + 1107e7c commit bfd80b4

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

javascript/ql/src/semmle/javascript/AST.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import javascript
2323
class ASTNode extends @ast_node, Locatable {
2424
override Location getLocation() { hasLocation(this, result) }
2525

26+
override File getFile() {
27+
result = getLocation().getFile() // Specialized for performance reasons
28+
}
29+
2630
/** Gets the first token belonging to this element. */
2731
Token getFirstToken() {
2832
exists(Location l1, Location l2 |

javascript/ql/src/semmle/javascript/NPM.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class BugTrackerInfo extends JSONValue {
190190
}
191191

192192
/** Gets the bug tracker URL. */
193-
string getURL() {
193+
string getUrl() {
194194
result = this.(JSONObject).getPropStringValue("url") or
195195
result = this.(JSONString).getValue()
196196
}
@@ -233,7 +233,7 @@ class ContributorInfo extends JSONValue {
233233
}
234234

235235
/** Gets the contributor's homepage URL. */
236-
string getURL() {
236+
string getUrl() {
237237
result = this.(JSONObject).getPropStringValue("url") or
238238
result = parseInfo(3)
239239
}
@@ -249,7 +249,7 @@ class RepositoryInfo extends JSONObject {
249249
string getType() { result = getPropStringValue("type") }
250250

251251
/** Gets the repository URL. */
252-
string getURL() { result = getPropStringValue("url") }
252+
string getUrl() { result = getPropStringValue("url") }
253253
}
254254

255255
/**

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,11 @@ module DataFlow {
166166
predicate hasLocationInfo(
167167
string filepath, int startline, int startcolumn, int endline, int endcolumn
168168
) {
169-
filepath = "" and
170-
startline = 0 and
171-
startcolumn = 0 and
172-
endline = 0 and
173-
endcolumn = 0
169+
none()
174170
}
175171

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

179175
/** Gets the start line of this data flow node. */
180176
int getStartLine() { hasLocationInfo(_, result, _, _, _) }
@@ -314,6 +310,8 @@ module DataFlow {
314310
astNode.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
315311
}
316312

313+
override File getFile() { result = astNode.getFile() }
314+
317315
override string toString() { result = astNode.toString() }
318316
}
319317

@@ -338,6 +336,8 @@ module DataFlow {
338336

339337
override string toString() { result = ssa.getSourceVariable().getName() }
340338

339+
override File getFile() { result = ssa.getBasicBlock().getFile() }
340+
341341
override ASTNode getAstNode() { none() }
342342
}
343343

@@ -362,6 +362,8 @@ module DataFlow {
362362

363363
override string toString() { result = prop.(ASTNode).toString() }
364364

365+
override File getFile() { result = prop.(ASTNode).getFile() }
366+
365367
override ASTNode getAstNode() { result = prop }
366368
}
367369

@@ -385,6 +387,8 @@ module DataFlow {
385387

386388
override string toString() { result = "..." + rest.toString() }
387389

390+
override File getFile() { result = pattern.getFile() }
391+
388392
override ASTNode getAstNode() { result = rest }
389393
}
390394

@@ -407,6 +411,8 @@ module DataFlow {
407411

408412
override string toString() { result = pattern.toString() }
409413

414+
override File getFile() { result = pattern.getFile() }
415+
410416
override ASTNode getAstNode() { result = pattern }
411417
}
412418

@@ -430,6 +436,8 @@ module DataFlow {
430436

431437
override string toString() { result = elt.toString() }
432438

439+
override File getFile() { result = pattern.getFile() }
440+
433441
override ASTNode getAstNode() { result = elt }
434442
}
435443

@@ -457,6 +465,8 @@ module DataFlow {
457465

458466
override string toString() { result = elt.toString() }
459467

468+
override File getFile() { result = arr.getFile() }
469+
460470
override ASTNode getAstNode() { result = elt }
461471
}
462472

@@ -479,6 +489,8 @@ module DataFlow {
479489
}
480490

481491
override string toString() { result = "reflective call" }
492+
493+
override File getFile() { result = call.getFile() }
482494
}
483495

484496
/**
@@ -498,6 +510,8 @@ module DataFlow {
498510
}
499511

500512
override string toString() { result = imprt.toString() }
513+
514+
override File getFile() { result = imprt.getFile() }
501515
}
502516

503517
/**
@@ -925,6 +939,8 @@ module DataFlow {
925939
) {
926940
p.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
927941
}
942+
943+
override File getFile() { result = p.getFile() }
928944
}
929945

930946
/**
@@ -945,6 +961,8 @@ module DataFlow {
945961

946962
/** Gets the attribute corresponding to this data flow node. */
947963
HTML::Attribute getAttribute() { result = attr }
964+
965+
override File getFile() { result = attr.getFile() }
948966
}
949967

950968
/**
@@ -969,6 +987,8 @@ module DataFlow {
969987
* Gets the function corresponding to this exceptional return node.
970988
*/
971989
Function getFunction() { result = function }
990+
991+
override File getFile() { result = function.getFile() }
972992
}
973993

974994
/**
@@ -993,6 +1013,8 @@ module DataFlow {
9931013
* Gets the invocation corresponding to this exceptional return node.
9941014
*/
9951015
DataFlow::InvokeNode getInvocation() { result = invoke.flow() }
1016+
1017+
override File getFile() { result = invoke.getFile() }
9961018
}
9971019

9981020
/**
@@ -1220,6 +1242,10 @@ module DataFlow {
12201242
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
12211243
)
12221244
}
1245+
1246+
override File getFile() {
1247+
exists(StmtContainer container | this = TThisNode(container) | result = container.getFile())
1248+
}
12231249
}
12241250

12251251
/**

0 commit comments

Comments
 (0)