@@ -28,49 +28,51 @@ private import Expressions.ExprHasNoEffect
28
28
class AmdModuleDefinition extends CallExpr {
29
29
AmdModuleDefinition ( ) {
30
30
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 ( ) |
33
33
n = 1
34
34
or
35
- n = 2 and getArgument ( 0 ) instanceof ArrayExpr
35
+ n = 2 and this . getArgument ( 0 ) instanceof ArrayExpr
36
36
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
38
40
)
39
41
}
40
42
41
43
/** Gets the array of module dependencies, if any. */
42
44
ArrayExpr getDependencies ( ) {
43
- result = getArgument ( 0 ) or
44
- result = getArgument ( 1 )
45
+ result = this . getArgument ( 0 ) or
46
+ result = this . getArgument ( 1 )
45
47
}
46
48
47
49
/** 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 ) }
49
51
50
52
/** Gets a dependency of this module definition. */
51
53
PathExpr getADependency ( ) {
52
- result = getDependency ( _) or
53
- result = getARequireCall ( ) .getAnArgument ( )
54
+ result = this . getDependency ( _) or
55
+ result = this . getARequireCall ( ) .getAnArgument ( )
54
56
}
55
57
56
58
/**
57
59
* Gets a data flow node containing the factory value of this module definition.
58
60
*/
59
61
pragma [ nomagic]
60
62
DataFlow:: SourceNode getFactoryNode ( ) {
61
- result = getFactoryNodeInternal ( ) and
63
+ result = this . getFactoryNodeInternal ( ) and
62
64
result instanceof DataFlow:: ValueNode
63
65
}
64
66
65
67
private DataFlow:: Node getFactoryNodeInternal ( ) {
66
68
// 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 ( )
69
71
}
70
72
71
73
/** Gets the expression defining this module. */
72
74
Expr getModuleExpr ( ) {
73
- exists ( DataFlow:: Node f | f = getFactoryNode ( ) |
75
+ exists ( DataFlow:: Node f | f = this . getFactoryNode ( ) |
74
76
if f instanceof DataFlow:: FunctionNode
75
77
then
76
78
exists ( ReturnStmt ret | ret .getContainer ( ) = f .( DataFlow:: FunctionNode ) .getAstNode ( ) |
@@ -81,15 +83,15 @@ class AmdModuleDefinition extends CallExpr {
81
83
}
82
84
83
85
/** 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 ( ) ) }
85
87
86
88
/**
87
89
* Holds if `p` is the parameter corresponding to dependency `dep`.
88
90
*/
89
91
predicate dependencyParameter ( PathExpr dep , Parameter p ) {
90
92
exists ( int i |
91
- dep = getDependency ( i ) and
92
- p = getFactoryParameter ( i )
93
+ dep = this . getDependency ( i ) and
94
+ p = this . getFactoryParameter ( i )
93
95
)
94
96
}
95
97
@@ -107,7 +109,7 @@ class AmdModuleDefinition extends CallExpr {
107
109
*/
108
110
Parameter getDependencyParameter ( string name ) {
109
111
exists ( PathExpr dep |
110
- dependencyParameter ( dep , result ) and
112
+ this . dependencyParameter ( dep , result ) and
111
113
dep .getValue ( ) = name
112
114
)
113
115
}
@@ -116,54 +118,54 @@ class AmdModuleDefinition extends CallExpr {
116
118
* Gets the `i`th parameter of the factory function of this module.
117
119
*/
118
120
private Parameter getFactoryParameter ( int i ) {
119
- getFactoryNodeInternal ( ) .asExpr ( ) .( Function ) .getParameter ( i ) = result
121
+ this . getFactoryNodeInternal ( ) .asExpr ( ) .( Function ) .getParameter ( i ) = result
120
122
}
121
123
122
124
/**
123
125
* Gets the parameter corresponding to the pseudo-dependency `require`.
124
126
*/
125
127
Parameter getRequireParameter ( ) {
126
- result = getDependencyParameter ( "require" )
128
+ result = this . getDependencyParameter ( "require" )
127
129
or
128
130
// 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 )
130
132
}
131
133
132
134
pragma [ noinline]
133
- private Variable getRequireVariable ( ) { result = getRequireParameter ( ) .getVariable ( ) }
135
+ private Variable getRequireVariable ( ) { result = this . getRequireParameter ( ) .getVariable ( ) }
134
136
135
137
/**
136
138
* Gets the parameter corresponding to the pseudo-dependency `exports`.
137
139
*/
138
140
Parameter getExportsParameter ( ) {
139
- result = getDependencyParameter ( "exports" )
141
+ result = this . getDependencyParameter ( "exports" )
140
142
or
141
143
// 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 )
143
145
}
144
146
145
147
/**
146
148
* Gets the parameter corresponding to the pseudo-dependency `module`.
147
149
*/
148
150
Parameter getModuleParameter ( ) {
149
- result = getDependencyParameter ( "module" )
151
+ result = this . getDependencyParameter ( "module" )
150
152
or
151
153
// 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 )
153
155
}
154
156
155
157
/**
156
158
* Gets an abstract value representing one or more values that may flow
157
159
* into this module's `module.exports` property.
158
160
*/
159
161
DefiniteAbstractValue getAModuleExportsValue ( ) {
160
- result = [ getAnImplicitExportsValue ( ) , getAnExplicitExportsValue ( ) ]
162
+ result = [ this . getAnImplicitExportsValue ( ) , this . getAnExplicitExportsValue ( ) ]
161
163
}
162
164
163
165
pragma [ noinline, nomagic]
164
166
private AbstractValue getAnImplicitExportsValue ( ) {
165
167
// implicit exports: anything that is returned from the factory function
166
- result = getModuleExpr ( ) .analyze ( ) .getAValue ( )
168
+ result = this . getModuleExpr ( ) .analyze ( ) .getAValue ( )
167
169
}
168
170
169
171
pragma [ noinline]
@@ -182,7 +184,7 @@ class AmdModuleDefinition extends CallExpr {
182
184
* Gets a call to `require` inside this module.
183
185
*/
184
186
CallExpr getARequireCall ( ) {
185
- result .getCallee ( ) .getUnderlyingValue ( ) = getRequireVariable ( ) .getAnAccess ( )
187
+ result .getCallee ( ) .getUnderlyingValue ( ) = this . getRequireVariable ( ) .getAnAccess ( )
186
188
}
187
189
}
188
190
@@ -200,7 +202,7 @@ private class AmdDependencyPath extends PathExprCandidate {
200
202
private class ConstantAmdDependencyPathElement extends PathExpr , ConstantString {
201
203
ConstantAmdDependencyPathElement ( ) { this = any ( AmdDependencyPath amd ) .getAPart ( ) }
202
204
203
- override string getValue ( ) { result = getStringValue ( ) }
205
+ override string getValue ( ) { result = this . getStringValue ( ) }
204
206
}
205
207
206
208
/**
@@ -239,7 +241,7 @@ private class AmdDependencyImport extends Import {
239
241
*/
240
242
private File guessTarget ( ) {
241
243
exists ( PathString imported , string abspath , string dirname , string basename |
242
- targetCandidate ( result , abspath , imported , dirname , basename )
244
+ this . targetCandidate ( result , abspath , imported , dirname , basename )
243
245
|
244
246
abspath .regexpMatch ( ".*/\\Q" + imported + "\\E" )
245
247
or
@@ -262,7 +264,7 @@ private class AmdDependencyImport extends Import {
262
264
private predicate targetCandidate (
263
265
File f , string abspath , PathString imported , string dirname , string basename
264
266
) {
265
- imported = getImportedPath ( ) .getValue ( ) and
267
+ imported = this . getImportedPath ( ) .getValue ( ) and
266
268
f .getStem ( ) = imported .getStem ( ) and
267
269
f .getAbsolutePath ( ) = abspath and
268
270
dirname = imported .getDirName ( ) and
@@ -273,14 +275,14 @@ private class AmdDependencyImport extends Import {
273
275
* Gets the module whose absolute path matches this import, if there is only a single such module.
274
276
*/
275
277
private Module resolveByAbsolutePath ( ) {
276
- result .getFile ( ) = unique( File file | file = guessTarget ( ) )
278
+ result .getFile ( ) = unique( File file | file = this . guessTarget ( ) )
277
279
}
278
280
279
281
override Module getImportedModule ( ) {
280
282
result = super .getImportedModule ( )
281
283
or
282
284
not exists ( super .getImportedModule ( ) ) and
283
- result = resolveByAbsolutePath ( )
285
+ result = this . resolveByAbsolutePath ( )
284
286
}
285
287
286
288
override DataFlow:: Node getImportedModuleNode ( ) {
@@ -314,7 +316,7 @@ class AmdModule extends Module {
314
316
315
317
override DataFlow:: Node getAnExportedValue ( string name ) {
316
318
exists ( DataFlow:: PropWrite pwn | result = pwn .getRhs ( ) |
317
- pwn .getBase ( ) .analyze ( ) .getAValue ( ) = getDefine ( ) .getAModuleExportsValue ( ) and
319
+ pwn .getBase ( ) .analyze ( ) .getAValue ( ) = this . getDefine ( ) .getAModuleExportsValue ( ) and
318
320
name = pwn .getPropertyName ( )
319
321
)
320
322
}
@@ -329,6 +331,6 @@ class AmdModule extends Module {
329
331
)
330
332
or
331
333
// Returned from factory function
332
- result = getDefine ( ) .getModuleExpr ( ) .flow ( )
334
+ result = this . getDefine ( ) .getModuleExpr ( ) .flow ( )
333
335
}
334
336
}
0 commit comments