Skip to content

Commit 8a89849

Browse files
authored
Merge pull request #11660 from erik-krogh/dynamic-useInstanceOf
Py/JS/RB: Use instanceof in more places
2 parents 8e500ec + b3a9c1c commit 8a89849

File tree

88 files changed

+256
-574
lines changed

Some content is hidden

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

88 files changed

+256
-574
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/TaintedPathATM.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ class TaintedPathAtmConfig extends AtmConfig {
5151
* of barrier guards, we port the barrier guards for the boosted query from the standard library to
5252
* sanitizer guards here.
5353
*/
54-
private class BarrierGuardNodeAsSanitizerGuardNode extends TaintTracking::LabeledSanitizerGuardNode {
55-
BarrierGuardNodeAsSanitizerGuardNode() { this instanceof TaintedPath::BarrierGuardNode }
56-
54+
private class BarrierGuardNodeAsSanitizerGuardNode extends TaintTracking::LabeledSanitizerGuardNode instanceof TaintedPath::BarrierGuardNode {
5755
override predicate sanitizes(boolean outcome, Expr e) {
5856
blocks(outcome, e) or blocks(outcome, e, _)
5957
}

javascript/ql/lib/semmle/javascript/Closure.qll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ module Closure {
7575
/**
7676
* A top-level call to `goog.provide`.
7777
*/
78-
class ClosureProvideCall extends ClosureNamespaceRef, DataFlow::MethodCallNode {
79-
ClosureProvideCall() { this instanceof DefaultClosureProvideCall }
78+
class ClosureProvideCall extends ClosureNamespaceRef, DataFlow::MethodCallNode instanceof DefaultClosureProvideCall {
8079
}
8180

8281
/**
@@ -89,8 +88,7 @@ module Closure {
8988
/**
9089
* A call to `goog.require`.
9190
*/
92-
class ClosureRequireCall extends ClosureNamespaceAccess, DataFlow::MethodCallNode {
93-
ClosureRequireCall() { this instanceof DefaultClosureRequireCall }
91+
class ClosureRequireCall extends ClosureNamespaceAccess, DataFlow::MethodCallNode instanceof DefaultClosureRequireCall {
9492
}
9593

9694
/**
@@ -106,8 +104,7 @@ module Closure {
106104
/**
107105
* A top-level call to `goog.module` or `goog.declareModuleId`.
108106
*/
109-
class ClosureModuleDeclaration extends ClosureNamespaceRef, DataFlow::MethodCallNode {
110-
ClosureModuleDeclaration() { this instanceof DefaultClosureModuleDeclaration }
107+
class ClosureModuleDeclaration extends ClosureNamespaceRef, DataFlow::MethodCallNode instanceof DefaultClosureModuleDeclaration {
111108
}
112109

113110
private GlobalVariable googVariable() { variables(result, "goog", any(GlobalScope sc)) }

javascript/ql/lib/semmle/javascript/DOM.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,14 @@ module DOM {
138138
/**
139139
* A JSX attribute, viewed as an `AttributeDefinition`.
140140
*/
141-
private class JsxAttributeDefinition extends AttributeDefinition, @jsx_attribute {
142-
JsxAttribute attr;
141+
private class JsxAttributeDefinition extends AttributeDefinition, @jsx_attribute instanceof JsxAttribute {
142+
override string getName() { result = JsxAttribute.super.getName() }
143143

144-
JsxAttributeDefinition() { this = attr }
145-
146-
override string getName() { result = attr.getName() }
147-
148-
override DataFlow::Node getValueNode() { result = DataFlow::valueNode(attr.getValue()) }
144+
override DataFlow::Node getValueNode() {
145+
result = DataFlow::valueNode(JsxAttribute.super.getValue())
146+
}
149147

150-
override ElementDefinition getElement() { result = attr.getElement() }
148+
override ElementDefinition getElement() { result = JsxAttribute.super.getElement() }
151149
}
152150

153151
/**

javascript/ql/lib/semmle/javascript/DefUse.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ class VarDef extends ControlFlowNode {
222222
*
223223
* Some variable definitions are also uses, notably the operands of update expressions.
224224
*/
225-
class VarUse extends ControlFlowNode, @varref {
226-
VarUse() { this instanceof RValue }
227-
225+
class VarUse extends ControlFlowNode, @varref instanceof RValue {
228226
/** Gets the variable this use refers to. */
229227
Variable getVariable() { result = this.(VarRef).getVariable() }
230228

javascript/ql/lib/semmle/javascript/DefensiveProgramming.qll

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,11 @@ module DefensiveExpressionTest {
384384
*
385385
* Example: `typeof x === "undefined"'.
386386
*/
387-
class TypeofUndefinedTest extends UndefinedNullTest {
388-
TypeofTest test;
389-
390-
TypeofUndefinedTest() {
391-
this = test and
392-
test.getTag() = "undefined"
393-
}
387+
class TypeofUndefinedTest extends UndefinedNullTest instanceof TypeofTest {
388+
TypeofUndefinedTest() { super.getTag() = "undefined" }
394389

395-
override boolean getTheTestResult() { result = test.getTheTestResult() }
390+
override boolean getTheTestResult() { result = TypeofTest.super.getTheTestResult() }
396391

397-
override Expr getOperand() { result = test.getOperand() }
392+
override Expr getOperand() { result = TypeofTest.super.getOperand() }
398393
}
399394
}

javascript/ql/lib/semmle/javascript/GeneratedCode.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ abstract class GeneratedCodeMarkerComment extends Comment { }
1616
/**
1717
* A source mapping comment, viewed as a marker comment indicating generated code.
1818
*/
19-
private class SourceMappingCommentMarkerComment extends GeneratedCodeMarkerComment {
20-
SourceMappingCommentMarkerComment() { this instanceof SourceMappingComment }
19+
private class SourceMappingCommentMarkerComment extends GeneratedCodeMarkerComment instanceof SourceMappingComment {
2120
}
2221

2322
/**

javascript/ql/lib/semmle/javascript/Routing.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,7 @@ module Routing {
508508
/**
509509
* An array which has been determined to be a route node, seen as a route node with arguments.
510510
*/
511-
private class ImpliedArrayRoute extends ValueNode::WithArguments, DataFlow::ArrayCreationNode {
512-
ImpliedArrayRoute() { this instanceof ValueNode::UseSite }
513-
511+
private class ImpliedArrayRoute extends ValueNode::WithArguments, DataFlow::ArrayCreationNode instanceof ValueNode::UseSite {
514512
override DataFlow::Node getArgumentNode(int n) { result = this.getElement(n) }
515513
}
516514
}

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,7 @@ class MethodCallNode extends CallNode instanceof DataFlow::Impl::MethodCallNodeD
298298
* new Array(16)
299299
* ```
300300
*/
301-
class NewNode extends InvokeNode {
302-
NewNode() { this instanceof DataFlow::Impl::NewNodeDef }
303-
}
301+
class NewNode extends InvokeNode instanceof DataFlow::Impl::NewNodeDef { }
304302

305303
/**
306304
* A data flow node corresponding to the `this` parameter in a function or `this` at the top-level.

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,9 @@ class AnalyzedValueNode extends AnalyzedNode, DataFlow::ValueNode { }
180180
* exports are modeled as property writes on `module.exports`, and imports
181181
* as property reads on any potential value of `module.exports`.
182182
*/
183-
class AnalyzedModule extends TopLevel {
184-
Module m;
185-
186-
AnalyzedModule() { this = m }
187-
183+
class AnalyzedModule extends TopLevel instanceof Module {
188184
/** Gets the name of this module. */
189-
string getName() { result = m.getName() }
185+
string getName() { result = super.getName() }
190186

191187
/**
192188
* Gets the abstract value representing this module's `module` object.
@@ -216,7 +212,7 @@ class AnalyzedModule extends TopLevel {
216212
exists(AbstractValue exports | exports = getAnExportsValue() |
217213
// CommonJS modules export `module.exports` as their `default`
218214
// export in an ES2015 setting
219-
not m instanceof ES2015Module and
215+
not this instanceof ES2015Module and
220216
name = "default" and
221217
result = exports
222218
or

javascript/ql/lib/semmle/javascript/dataflow/internal/PropertyTypeInference.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,13 @@ abstract class AnalyzedPropertyWrite extends DataFlow::Node {
120120
/**
121121
* Flow analysis for property writes.
122122
*/
123-
private class AnalyzedExplicitPropertyWrite extends AnalyzedPropertyWrite {
124-
AnalyzedExplicitPropertyWrite() { this instanceof DataFlow::PropWrite }
125-
123+
private class AnalyzedExplicitPropertyWrite extends AnalyzedPropertyWrite instanceof DataFlow::PropWrite {
126124
override predicate writes(AbstractValue base, string prop, DataFlow::AnalyzedNode source) {
127125
explicitPropertyWrite(this, base, prop, source)
128126
}
129127

130128
override predicate baseIsIncomplete(DataFlow::Incompleteness reason) {
131-
this.(DataFlow::PropWrite).getBase().isIncomplete(reason)
129+
super.getBase().isIncomplete(reason)
132130
}
133131
}
134132

0 commit comments

Comments
 (0)