Skip to content

Commit 0d76206

Browse files
authored
Merge pull request #3504 from erik-krogh/unique
Approved by esbena
2 parents 192bf91 + 202b8a5 commit 0d76206

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-20
lines changed

javascript/ql/src/semmle/javascript/AMD.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ private class AmdDependencyImport extends Import {
259259
* Gets the module whose absolute path matches this import, if there is only a single such module.
260260
*/
261261
private Module resolveByAbsolutePath() {
262-
count(guessTarget()) = 1 and
263-
result.getFile() = guessTarget()
262+
result.getFile() = unique(File file | file = guessTarget())
264263
}
265264

266265
override Module getImportedModule() {
@@ -291,7 +290,7 @@ private class AmdDependencyImport extends Import {
291290
*/
292291
class AmdModule extends Module {
293292
cached
294-
AmdModule() { strictcount(AmdModuleDefinition def | amdModuleTopLevel(def, this)) = 1 }
293+
AmdModule() { exists(unique(AmdModuleDefinition def | amdModuleTopLevel(def, this))) }
295294

296295
/** Gets the definition of this module. */
297296
AmdModuleDefinition getDefine() { amdModuleTopLevel(result, this) }

javascript/ql/src/semmle/javascript/InclusionTests.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ module InclusionTest {
6666
Function callee;
6767

6868
IndirectInclusionTest() {
69-
inner.getEnclosingExpr() = callee.getAReturnedExpr() and
70-
this.getACallee() = callee and
71-
count(this.getACallee()) = 1 and
72-
count(callee.getAReturnedExpr()) = 1 and
69+
inner.getEnclosingExpr() = unique(Expr ret | ret = callee.getAReturnedExpr()) and
70+
callee = unique(Function f | f = this.getACallee()) and
7371
not this.isImprecise() and
7472
inner.getContainedNode().getALocalSource() = DataFlow::parameterNode(callee.getAParameter()) and
7573
inner.getContainerNode().getALocalSource() = DataFlow::parameterNode(callee.getAParameter())

javascript/ql/src/semmle/javascript/StringOps.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ module StringOps {
6464
Function callee;
6565

6666
IndirectStartsWith() {
67-
inner.getEnclosingExpr() = callee.getAReturnedExpr() and
68-
this.getACallee() = callee and
69-
count(this.getACallee()) = 1 and
70-
count(callee.getAReturnedExpr()) = 1 and
67+
inner.getEnclosingExpr() = unique(Expr ret | ret = callee.getAReturnedExpr()) and
68+
callee = unique(Function f | f = this.getACallee()) and
7169
not this.isImprecise() and
7270
inner.getBaseString().getALocalSource().getEnclosingExpr() = callee.getAParameter() and
7371
inner.getSubstring().getALocalSource().getEnclosingExpr() = callee.getAParameter()
@@ -295,10 +293,8 @@ module StringOps {
295293
Function callee;
296294

297295
IndirectEndsWith() {
298-
inner.getEnclosingExpr() = callee.getAReturnedExpr() and
299-
this.getACallee() = callee and
300-
count(this.getACallee()) = 1 and
301-
count(callee.getAReturnedExpr()) = 1 and
296+
inner.getEnclosingExpr() = unique(Expr ret | ret = callee.getAReturnedExpr()) and
297+
callee = unique(Function f | f = this.getACallee()) and
302298
not this.isImprecise() and
303299
inner.getBaseString().getALocalSource().getEnclosingExpr() = callee.getAParameter() and
304300
inner.getSubstring().getALocalSource().getEnclosingExpr() = callee.getAParameter()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ module DataFlow {
218218
// IIFE call -> return value of IIFE
219219
exists(Function fun |
220220
localCall(this.asExpr(), fun) and
221-
result = fun.getAReturnedExpr().flow() and
222-
strictcount(fun.getAReturnedExpr()) = 1 and
221+
result = unique(Expr ret | ret = fun.getAReturnedExpr()).flow() and
223222
not fun.getExit().isJoin() // can only reach exit by the return statement
224223
)
225224
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class AnalyzedNode extends DataFlow::Node {
100100
boolean getTheBooleanValue() { forex(boolean bv | bv = getABooleanValue() | result = bv) }
101101

102102
/** Gets the unique type inferred for this node, if any. */
103-
InferredType getTheType() { count(getAType()) = 1 and result = getAType() }
103+
InferredType getTheType() { result = unique(InferredType t | t = getAType()) }
104104

105105
/**
106106
* Gets a pretty-printed representation of all types inferred for this node

javascript/ql/src/semmle/javascript/dataflow/internal/InterProceduralTypeInference.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ private class IIFEWithAnalyzedReturnFlow extends CallWithAnalyzedReturnFlow {
187187
*/
188188
private VarAccess getOnlyAccess(FunctionDeclStmt fn, LocalVariable v) {
189189
v = fn.getVariable() and
190-
result = v.getAnAccess() and
191-
strictcount(v.getAnAccess()) = 1
190+
result = unique(VarAccess acc | acc = v.getAnAccess())
192191
}
193192

194193
/** A function that only is used locally, making it amenable to type inference. */

0 commit comments

Comments
 (0)