Skip to content

Commit 85e1c87

Browse files
committed
use the new non-extending-subtypes syntax
1 parent 8d4af3a commit 85e1c87

File tree

14 files changed

+87
-147
lines changed

14 files changed

+87
-147
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import javascript
66

77
module Base64 {
88
/** A call to a base64 encoder. */
9-
class Encode extends DataFlow::Node {
10-
Encode() { this instanceof Encode::Range }
11-
9+
class Encode extends DataFlow::Node instanceof Encode::Range {
1210
/** Gets the input passed to the encoder. */
13-
DataFlow::Node getInput() { result = this.(Encode::Range).getInput() }
11+
DataFlow::Node getInput() { result = super.getInput() }
1412

1513
/** Gets the base64-encoded output of the encoder. */
16-
DataFlow::Node getOutput() { result = this.(Encode::Range).getOutput() }
14+
DataFlow::Node getOutput() { result = super.getOutput() }
1715
}
1816

1917
module Encode {
@@ -32,14 +30,12 @@ module Base64 {
3230
}
3331

3432
/** A call to a base64 decoder. */
35-
class Decode extends DataFlow::Node {
36-
Decode() { this instanceof Decode::Range }
37-
33+
class Decode extends DataFlow::Node instanceof Decode::Range {
3834
/** Gets the base64-encoded input passed to the decoder. */
39-
DataFlow::Node getInput() { result = this.(Decode::Range).getInput() }
35+
DataFlow::Node getInput() { result = super.getInput() }
4036

4137
/** Gets the output of the decoder. */
42-
DataFlow::Node getOutput() { result = this.(Decode::Range).getOutput() }
38+
DataFlow::Node getOutput() { result = super.getOutput() }
4339
}
4440

4541
module Decode {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ module Closure {
88
/**
99
* A reference to a Closure namespace.
1010
*/
11-
class ClosureNamespaceRef extends DataFlow::Node {
12-
ClosureNamespaceRef() { this instanceof ClosureNamespaceRef::Range }
13-
11+
class ClosureNamespaceRef extends DataFlow::Node instanceof ClosureNamespaceRef::Range {
1412
/**
1513
* Gets the namespace being referenced.
1614
*/
17-
string getClosureNamespace() {
18-
result = this.(ClosureNamespaceRef::Range).getClosureNamespace()
19-
}
15+
string getClosureNamespace() { result = super.getClosureNamespace() }
2016
}
2117

2218
module ClosureNamespaceRef {
@@ -36,8 +32,7 @@ module Closure {
3632
/**
3733
* A data flow node that returns the value of a closure namespace.
3834
*/
39-
class ClosureNamespaceAccess extends ClosureNamespaceRef {
40-
ClosureNamespaceAccess() { this instanceof ClosureNamespaceAccess::Range }
35+
class ClosureNamespaceAccess extends ClosureNamespaceRef instanceof ClosureNamespaceAccess::Range {
4136
}
4237

4338
module ClosureNamespaceAccess {

javascript/ql/lib/semmle/javascript/InclusionTests.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ private import javascript
1616
* ~A.indexOf(B)
1717
* ```
1818
*/
19-
class InclusionTest extends DataFlow::Node {
20-
InclusionTest() { this instanceof InclusionTest::Range }
21-
19+
class InclusionTest extends DataFlow::Node instanceof InclusionTest::Range {
2220
/** Gets the `A` in `A.includes(B)`. */
23-
DataFlow::Node getContainerNode() { result = this.(InclusionTest::Range).getContainerNode() }
21+
DataFlow::Node getContainerNode() { result = super.getContainerNode() }
2422

2523
/** Gets the `B` in `A.includes(B)`. */
26-
DataFlow::Node getContainedNode() { result = this.(InclusionTest::Range).getContainedNode() }
24+
DataFlow::Node getContainedNode() { result = super.getContainedNode() }
2725

2826
/**
2927
* Gets the polarity of the check.
3028
*
3129
* If the polarity is `false` the check returns `true` if the container does not contain
3230
* the given element.
3331
*/
34-
boolean getPolarity() { result = this.(InclusionTest::Range).getPolarity() }
32+
boolean getPolarity() { result = super.getPolarity() }
3533
}
3634

3735
module InclusionTest {

javascript/ql/lib/semmle/javascript/MembershipCandidates.qll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,31 @@ import javascript
99
*
1010
* Additional candidates can be added by subclassing `MembershipCandidate::Range`
1111
*/
12-
class MembershipCandidate extends DataFlow::Node {
13-
MembershipCandidate() { this instanceof MembershipCandidate::Range }
14-
12+
class MembershipCandidate extends DataFlow::Node instanceof MembershipCandidate::Range {
1513
/**
1614
* Gets the expression that performs the membership test, if any.
1715
*/
18-
DataFlow::Node getTest() { result = this.(MembershipCandidate::Range).getTest() }
16+
DataFlow::Node getTest() { result = super.getTest() }
1917

2018
/**
2119
* Gets a string that this candidate is tested against, if
2220
* it can be determined.
2321
*/
24-
string getAMemberString() { result = this.(MembershipCandidate::Range).getAMemberString() }
22+
string getAMemberString() { result = super.getAMemberString() }
2523

2624
/**
2725
* Gets a node that this candidate is tested against, if
2826
* it can be determined.
2927
*/
30-
DataFlow::Node getAMemberNode() { result = this.(MembershipCandidate::Range).getAMemberNode() }
28+
DataFlow::Node getAMemberNode() { result = super.getAMemberNode() }
3129

3230
/**
3331
* Gets the polarity of the test.
3432
*
3533
* If the polarity is `false` the test returns `true` if the
3634
* collection does not contain this candidate.
3735
*/
38-
boolean getTestPolarity() { result = this.(MembershipCandidate::Range).getTestPolarity() }
36+
boolean getTestPolarity() { result = super.getTestPolarity() }
3937
}
4038

4139
/**

javascript/ql/lib/semmle/javascript/StringOps.qll

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ module StringOps {
88
/**
99
* A expression that is equivalent to `A.startsWith(B)` or `!A.startsWith(B)`.
1010
*/
11-
class StartsWith extends DataFlow::Node {
12-
StartsWith() { this instanceof StartsWith::Range }
13-
11+
class StartsWith extends DataFlow::Node instanceof StartsWith::Range {
1412
/**
1513
* Gets the `A` in `A.startsWith(B)`.
1614
*/
17-
DataFlow::Node getBaseString() { result = this.(StartsWith::Range).getBaseString() }
15+
DataFlow::Node getBaseString() { result = super.getBaseString() }
1816

1917
/**
2018
* Gets the `B` in `A.startsWith(B)`.
2119
*/
22-
DataFlow::Node getSubstring() { result = this.(StartsWith::Range).getSubstring() }
20+
DataFlow::Node getSubstring() { result = super.getSubstring() }
2321

2422
/**
2523
* Gets the polarity of the check.
2624
*
2725
* If the polarity is `false` the check returns `true` if the string does not start
2826
* with the given substring.
2927
*/
30-
boolean getPolarity() { result = this.(StartsWith::Range).getPolarity() }
28+
boolean getPolarity() { result = super.getPolarity() }
3129
}
3230

3331
module StartsWith {
@@ -235,26 +233,24 @@ module StringOps {
235233
/**
236234
* An expression that is equivalent to `A.endsWith(B)` or `!A.endsWith(B)`.
237235
*/
238-
class EndsWith extends DataFlow::Node {
239-
EndsWith() { this instanceof EndsWith::Range }
240-
236+
class EndsWith extends DataFlow::Node instanceof EndsWith::Range {
241237
/**
242238
* Gets the `A` in `A.startsWith(B)`.
243239
*/
244-
DataFlow::Node getBaseString() { result = this.(EndsWith::Range).getBaseString() }
240+
DataFlow::Node getBaseString() { result = super.getBaseString() }
245241

246242
/**
247243
* Gets the `B` in `A.startsWith(B)`.
248244
*/
249-
DataFlow::Node getSubstring() { result = this.(EndsWith::Range).getSubstring() }
245+
DataFlow::Node getSubstring() { result = super.getSubstring() }
250246

251247
/**
252248
* Gets the polarity if the check.
253249
*
254250
* If the polarity is `false` the check returns `true` if the string does not end
255251
* with the given substring.
256252
*/
257-
boolean getPolarity() { result = this.(EndsWith::Range).getPolarity() }
253+
boolean getPolarity() { result = super.getPolarity() }
258254
}
259255

260256
module EndsWith {
@@ -658,37 +654,35 @@ module StringOps {
658654
* if (!match) { ... } // <--- 'match' is the RegExpTest
659655
* ```
660656
*/
661-
class RegExpTest extends DataFlow::Node {
662-
RegExpTest() { this instanceof RegExpTest::Range }
663-
657+
class RegExpTest extends DataFlow::Node instanceof RegExpTest::Range {
664658
/**
665659
* Gets the AST of the regular expression used in the test, if it can be seen locally.
666660
*/
667661
RegExpTerm getRegExp() {
668662
result = getRegExpOperand().getALocalSource().(DataFlow::RegExpCreationNode).getRoot()
669663
or
670-
result = this.(RegExpTest::Range).getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
664+
result = super.getRegExpOperand(true).asExpr().(StringLiteral).asRegExp()
671665
}
672666

673667
/**
674668
* Gets the data flow node corresponding to the regular expression object used in the test.
675669
*
676670
* In some cases this represents a string value being coerced to a RegExp object.
677671
*/
678-
DataFlow::Node getRegExpOperand() { result = this.(RegExpTest::Range).getRegExpOperand(_) }
672+
DataFlow::Node getRegExpOperand() { result = super.getRegExpOperand(_) }
679673

680674
/**
681675
* Gets the data flow node corresponding to the string being tested against the regular expression.
682676
*/
683-
DataFlow::Node getStringOperand() { result = this.(RegExpTest::Range).getStringOperand() }
677+
DataFlow::Node getStringOperand() { result = super.getStringOperand() }
684678

685679
/**
686680
* Gets the return value indicating that the string matched the regular expression.
687681
*
688682
* For example, for `regexp.exec(str) == null`, the polarity is `false`, and for
689683
* `regexp.exec(str) != null` the polarity is `true`.
690684
*/
691-
boolean getPolarity() { result = this.(RegExpTest::Range).getPolarity() }
685+
boolean getPolarity() { result = super.getPolarity() }
692686
}
693687

694688
/**

0 commit comments

Comments
 (0)