Skip to content

Commit 65deb9d

Browse files
authored
Merge pull request github#13016 from kaspersv/kaspersv/js-explicit-this-receivers3
JS: Make implicit this receivers explicit
2 parents 149722a + 67950c8 commit 65deb9d

File tree

125 files changed

+1060
-1001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1060
-1001
lines changed

javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitizationGeneralized.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class DecodingCall extends CallNode {
2121
Node input;
2222

2323
DecodingCall() {
24-
getCalleeName().matches("decodeURI%") and
25-
input = getArgument(0) and
24+
this.getCalleeName().matches("decodeURI%") and
25+
input = this.getArgument(0) and
2626
kind = "URI decoding"
2727
or
2828
input = this.(JsonParserCall).getInput() and

javascript/ql/lib/Declarations/UnusedVariable.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import LanguageFeatures.UnusedIndexVariable
1111
*/
1212
class UnusedLocal extends LocalVariable {
1313
UnusedLocal() {
14-
not exists(getAnAccess()) and
14+
not exists(this.getAnAccess()) and
1515
not exists(Parameter p | this = p.getAVariable()) and
1616
not exists(FunctionExpr fe | this = fe.getVariable()) and
1717
not exists(ClassExpr ce | this = ce.getVariable()) and
@@ -20,6 +20,6 @@ class UnusedLocal extends LocalVariable {
2020
// avoid double reporting
2121
not unusedIndexVariable(_, this, _) and
2222
// common convention: variables with leading underscore are intentionally unused
23-
getName().charAt(0) != "_"
23+
this.getName().charAt(0) != "_"
2424
}
2525
}

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ predicate isGetterProperty(string name) {
8383
* A property access that may invoke a getter.
8484
*/
8585
class GetterPropertyAccess extends PropAccess {
86-
override predicate isImpure() { isGetterProperty(getPropertyName()) }
86+
override predicate isImpure() { isGetterProperty(this.getPropertyName()) }
8787
}
8888

8989
/**

javascript/ql/lib/semmle/javascript/AMD.qll

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,51 @@ private import Expressions.ExprHasNoEffect
2828
class AmdModuleDefinition extends CallExpr {
2929
AmdModuleDefinition() {
3030
inVoidContext(this) and
31-
getCallee().(GlobalVarAccess).getName() = "define" and
32-
exists(int n | n = getNumArgument() |
31+
this.getCallee().(GlobalVarAccess).getName() = "define" and
32+
exists(int n | n = this.getNumArgument() |
3333
n = 1
3434
or
35-
n = 2 and getArgument(0) instanceof ArrayExpr
35+
n = 2 and this.getArgument(0) instanceof ArrayExpr
3636
or
37-
n = 3 and getArgument(0) instanceof ConstantString and getArgument(1) instanceof ArrayExpr
37+
n = 3 and
38+
this.getArgument(0) instanceof ConstantString and
39+
this.getArgument(1) instanceof ArrayExpr
3840
)
3941
}
4042

4143
/** Gets the array of module dependencies, if any. */
4244
ArrayExpr getDependencies() {
43-
result = getArgument(0) or
44-
result = getArgument(1)
45+
result = this.getArgument(0) or
46+
result = this.getArgument(1)
4547
}
4648

4749
/** Gets the `i`th dependency of this module definition. */
48-
PathExpr getDependency(int i) { result = getDependencies().getElement(i) }
50+
PathExpr getDependency(int i) { result = this.getDependencies().getElement(i) }
4951

5052
/** Gets a dependency of this module definition. */
5153
PathExpr getADependency() {
52-
result = getDependency(_) or
53-
result = getARequireCall().getAnArgument()
54+
result = this.getDependency(_) or
55+
result = this.getARequireCall().getAnArgument()
5456
}
5557

5658
/**
5759
* Gets a data flow node containing the factory value of this module definition.
5860
*/
5961
pragma[nomagic]
6062
DataFlow::SourceNode getFactoryNode() {
61-
result = getFactoryNodeInternal() and
63+
result = this.getFactoryNodeInternal() and
6264
result instanceof DataFlow::ValueNode
6365
}
6466

6567
private DataFlow::Node getFactoryNodeInternal() {
6668
// To avoid recursion, this should not depend on `SourceNode`.
67-
result = DataFlow::valueNode(getLastArgument()) or
68-
result = getFactoryNodeInternal().getAPredecessor()
69+
result = DataFlow::valueNode(this.getLastArgument()) or
70+
result = this.getFactoryNodeInternal().getAPredecessor()
6971
}
7072

7173
/** Gets the expression defining this module. */
7274
Expr getModuleExpr() {
73-
exists(DataFlow::Node f | f = getFactoryNode() |
75+
exists(DataFlow::Node f | f = this.getFactoryNode() |
7476
if f instanceof DataFlow::FunctionNode
7577
then
7678
exists(ReturnStmt ret | ret.getContainer() = f.(DataFlow::FunctionNode).getAstNode() |
@@ -81,15 +83,15 @@ class AmdModuleDefinition extends CallExpr {
8183
}
8284

8385
/** Gets a source node whose value becomes the definition of this module. */
84-
DataFlow::SourceNode getAModuleSource() { result.flowsToExpr(getModuleExpr()) }
86+
DataFlow::SourceNode getAModuleSource() { result.flowsToExpr(this.getModuleExpr()) }
8587

8688
/**
8789
* Holds if `p` is the parameter corresponding to dependency `dep`.
8890
*/
8991
predicate dependencyParameter(PathExpr dep, Parameter p) {
9092
exists(int i |
91-
dep = getDependency(i) and
92-
p = getFactoryParameter(i)
93+
dep = this.getDependency(i) and
94+
p = this.getFactoryParameter(i)
9395
)
9496
}
9597

@@ -107,7 +109,7 @@ class AmdModuleDefinition extends CallExpr {
107109
*/
108110
Parameter getDependencyParameter(string name) {
109111
exists(PathExpr dep |
110-
dependencyParameter(dep, result) and
112+
this.dependencyParameter(dep, result) and
111113
dep.getValue() = name
112114
)
113115
}
@@ -116,54 +118,54 @@ class AmdModuleDefinition extends CallExpr {
116118
* Gets the `i`th parameter of the factory function of this module.
117119
*/
118120
private Parameter getFactoryParameter(int i) {
119-
getFactoryNodeInternal().asExpr().(Function).getParameter(i) = result
121+
this.getFactoryNodeInternal().asExpr().(Function).getParameter(i) = result
120122
}
121123

122124
/**
123125
* Gets the parameter corresponding to the pseudo-dependency `require`.
124126
*/
125127
Parameter getRequireParameter() {
126-
result = getDependencyParameter("require")
128+
result = this.getDependencyParameter("require")
127129
or
128130
// if no dependencies are listed, the first parameter is assumed to be `require`
129-
not exists(getDependencies()) and result = getFactoryParameter(0)
131+
not exists(this.getDependencies()) and result = this.getFactoryParameter(0)
130132
}
131133

132134
pragma[noinline]
133-
private Variable getRequireVariable() { result = getRequireParameter().getVariable() }
135+
private Variable getRequireVariable() { result = this.getRequireParameter().getVariable() }
134136

135137
/**
136138
* Gets the parameter corresponding to the pseudo-dependency `exports`.
137139
*/
138140
Parameter getExportsParameter() {
139-
result = getDependencyParameter("exports")
141+
result = this.getDependencyParameter("exports")
140142
or
141143
// if no dependencies are listed, the second parameter is assumed to be `exports`
142-
not exists(getDependencies()) and result = getFactoryParameter(1)
144+
not exists(this.getDependencies()) and result = this.getFactoryParameter(1)
143145
}
144146

145147
/**
146148
* Gets the parameter corresponding to the pseudo-dependency `module`.
147149
*/
148150
Parameter getModuleParameter() {
149-
result = getDependencyParameter("module")
151+
result = this.getDependencyParameter("module")
150152
or
151153
// if no dependencies are listed, the third parameter is assumed to be `module`
152-
not exists(getDependencies()) and result = getFactoryParameter(2)
154+
not exists(this.getDependencies()) and result = this.getFactoryParameter(2)
153155
}
154156

155157
/**
156158
* Gets an abstract value representing one or more values that may flow
157159
* into this module's `module.exports` property.
158160
*/
159161
DefiniteAbstractValue getAModuleExportsValue() {
160-
result = [getAnImplicitExportsValue(), getAnExplicitExportsValue()]
162+
result = [this.getAnImplicitExportsValue(), this.getAnExplicitExportsValue()]
161163
}
162164

163165
pragma[noinline, nomagic]
164166
private AbstractValue getAnImplicitExportsValue() {
165167
// implicit exports: anything that is returned from the factory function
166-
result = getModuleExpr().analyze().getAValue()
168+
result = this.getModuleExpr().analyze().getAValue()
167169
}
168170

169171
pragma[noinline]
@@ -182,7 +184,7 @@ class AmdModuleDefinition extends CallExpr {
182184
* Gets a call to `require` inside this module.
183185
*/
184186
CallExpr getARequireCall() {
185-
result.getCallee().getUnderlyingValue() = getRequireVariable().getAnAccess()
187+
result.getCallee().getUnderlyingValue() = this.getRequireVariable().getAnAccess()
186188
}
187189
}
188190

@@ -200,7 +202,7 @@ private class AmdDependencyPath extends PathExprCandidate {
200202
private class ConstantAmdDependencyPathElement extends PathExpr, ConstantString {
201203
ConstantAmdDependencyPathElement() { this = any(AmdDependencyPath amd).getAPart() }
202204

203-
override string getValue() { result = getStringValue() }
205+
override string getValue() { result = this.getStringValue() }
204206
}
205207

206208
/**
@@ -239,7 +241,7 @@ private class AmdDependencyImport extends Import {
239241
*/
240242
private File guessTarget() {
241243
exists(PathString imported, string abspath, string dirname, string basename |
242-
targetCandidate(result, abspath, imported, dirname, basename)
244+
this.targetCandidate(result, abspath, imported, dirname, basename)
243245
|
244246
abspath.regexpMatch(".*/\\Q" + imported + "\\E")
245247
or
@@ -262,7 +264,7 @@ private class AmdDependencyImport extends Import {
262264
private predicate targetCandidate(
263265
File f, string abspath, PathString imported, string dirname, string basename
264266
) {
265-
imported = getImportedPath().getValue() and
267+
imported = this.getImportedPath().getValue() and
266268
f.getStem() = imported.getStem() and
267269
f.getAbsolutePath() = abspath and
268270
dirname = imported.getDirName() and
@@ -273,14 +275,14 @@ private class AmdDependencyImport extends Import {
273275
* Gets the module whose absolute path matches this import, if there is only a single such module.
274276
*/
275277
private Module resolveByAbsolutePath() {
276-
result.getFile() = unique(File file | file = guessTarget())
278+
result.getFile() = unique(File file | file = this.guessTarget())
277279
}
278280

279281
override Module getImportedModule() {
280282
result = super.getImportedModule()
281283
or
282284
not exists(super.getImportedModule()) and
283-
result = resolveByAbsolutePath()
285+
result = this.resolveByAbsolutePath()
284286
}
285287

286288
override DataFlow::Node getImportedModuleNode() {
@@ -314,7 +316,7 @@ class AmdModule extends Module {
314316

315317
override DataFlow::Node getAnExportedValue(string name) {
316318
exists(DataFlow::PropWrite pwn | result = pwn.getRhs() |
317-
pwn.getBase().analyze().getAValue() = getDefine().getAModuleExportsValue() and
319+
pwn.getBase().analyze().getAValue() = this.getDefine().getAModuleExportsValue() and
318320
name = pwn.getPropertyName()
319321
)
320322
}
@@ -329,6 +331,6 @@ class AmdModule extends Module {
329331
)
330332
or
331333
// Returned from factory function
332-
result = getDefine().getModuleExpr().flow()
334+
result = this.getDefine().getModuleExpr().flow()
333335
}
334336
}

javascript/ql/lib/semmle/javascript/Base64.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module Base64 {
7373
private class Btoa extends Base64::Encode::Range, DataFlow::CallNode {
7474
Btoa() { this = DataFlow::globalVarRef("btoa").getACall() }
7575

76-
override DataFlow::Node getInput() { result = getArgument(0) }
76+
override DataFlow::Node getInput() { result = this.getArgument(0) }
7777

7878
override DataFlow::Node getOutput() { result = this }
7979
}
@@ -82,7 +82,7 @@ private class Btoa extends Base64::Encode::Range, DataFlow::CallNode {
8282
private class Atob extends Base64::Decode::Range, DataFlow::CallNode {
8383
Atob() { this = DataFlow::globalVarRef("atob").getACall() }
8484

85-
override DataFlow::Node getInput() { result = getArgument(0) }
85+
override DataFlow::Node getInput() { result = this.getArgument(0) }
8686

8787
override DataFlow::Node getOutput() { result = this }
8888
}
@@ -93,11 +93,11 @@ private class Atob extends Base64::Decode::Range, DataFlow::CallNode {
9393
*/
9494
private class Buffer_toString extends Base64::Encode::Range, DataFlow::MethodCallNode {
9595
Buffer_toString() {
96-
getMethodName() = "toString" and
97-
getArgument(0).mayHaveStringValue("base64")
96+
this.getMethodName() = "toString" and
97+
this.getArgument(0).mayHaveStringValue("base64")
9898
}
9999

100-
override DataFlow::Node getInput() { result = getReceiver() }
100+
override DataFlow::Node getInput() { result = this.getReceiver() }
101101

102102
override DataFlow::Node getOutput() { result = this }
103103
}
@@ -106,10 +106,10 @@ private class Buffer_toString extends Base64::Encode::Range, DataFlow::MethodCal
106106
private class Buffer_from extends Base64::Decode::Range, DataFlow::CallNode {
107107
Buffer_from() {
108108
this = DataFlow::globalVarRef("Buffer").getAMemberCall("from") and
109-
getArgument(1).mayHaveStringValue("base64")
109+
this.getArgument(1).mayHaveStringValue("base64")
110110
}
111111

112-
override DataFlow::Node getInput() { result = getArgument(0) }
112+
override DataFlow::Node getInput() { result = this.getArgument(0) }
113113

114114
override DataFlow::Node getOutput() { result = this }
115115
}
@@ -149,7 +149,7 @@ private class NpmBase64Encode extends Base64::Encode::Range, DataFlow::CallNode
149149
)
150150
}
151151

152-
override DataFlow::Node getInput() { result = getArgument(0) }
152+
override DataFlow::Node getInput() { result = this.getArgument(0) }
153153

154154
override DataFlow::Node getOutput() { result = this }
155155
}
@@ -186,7 +186,7 @@ private class NpmBase64Decode extends Base64::Decode::Range, DataFlow::CallNode
186186
)
187187
}
188188

189-
override DataFlow::Node getInput() { result = getArgument(0) }
189+
override DataFlow::Node getInput() { result = this.getArgument(0) }
190190

191191
override DataFlow::Node getOutput() { result = this }
192192
}

0 commit comments

Comments
 (0)