Skip to content

Commit 1ca27e2

Browse files
authored
Merge pull request #647 from xiemaisi/js/fix-msita-perf
Approved by esben-semmle
2 parents 3b383e3 + 74e7061 commit 1ca27e2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

javascript/ql/src/Declarations/MixedStaticInstanceThisAccess.ql

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,31 @@ predicate hasMethod(ClassDefinition base, string name, MethodDefinition m) {
1717
}
1818

1919
/**
20-
* Holds if `access` is in`fromMethod`, and it references `toMethod` through `this`.
20+
* Holds if `access` is in`fromMethod`, and it references `toMethod` through `this`,
21+
* where `fromMethod` and `toMethod` are of kind `fromKind` and `toKind`, respectively.
2122
*/
22-
predicate isLocalMethodAccess(PropAccess access, MethodDefinition fromMethod, MethodDefinition toMethod) {
23-
hasMethod(fromMethod.getDeclaringClass(), access.getPropertyName(), toMethod) and
24-
access.getEnclosingFunction() = fromMethod.getBody() and
25-
access.getBase() instanceof ThisExpr
23+
predicate isLocalMethodAccess(PropAccess access, MethodDefinition fromMethod, string fromKind,
24+
MethodDefinition toMethod, string toKind) {
25+
hasMethod(fromMethod.getDeclaringClass(), access.getPropertyName(), toMethod) and
26+
access.getEnclosingFunction() = fromMethod.getBody() and
27+
access.getBase() instanceof ThisExpr and
28+
fromKind = getKind(fromMethod) and
29+
toKind = getKind(toMethod)
2630
}
2731

2832
string getKind(MethodDefinition m) {
29-
if m.isStatic() then result = "static" else result = "instance"
33+
if m.isStatic() then result = "static" else result = "instance"
3034
}
3135

3236
from PropAccess access, MethodDefinition fromMethod, MethodDefinition toMethod, string fromKind, string toKind
3337
where
34-
isLocalMethodAccess(access, fromMethod, toMethod) and
35-
fromKind = getKind(fromMethod) and
36-
toKind = getKind(toMethod) and
38+
isLocalMethodAccess(access, fromMethod, fromKind, toMethod, toKind) and
3739
toKind != fromKind and
3840

3941
// exceptions
4042
not (
4143
// the class has a second member with the same name and the right kind
42-
exists (MethodDefinition toMethodWithSameKind |
43-
isLocalMethodAccess(access, fromMethod, toMethodWithSameKind) and
44-
fromKind = getKind(toMethodWithSameKind)
45-
)
44+
isLocalMethodAccess(access, fromMethod, _, _, fromKind)
4645
or
4746
// there is a dynamically assigned second member with the same name and the right kind
4847
exists (AnalyzedPropertyWrite apw, AbstractClass declaringClass, AbstractValue base |

0 commit comments

Comments
 (0)