JS: use inheritance in js/mixed-static-instance-this-access

This commit is contained in:
Esben Sparre Andreasen
2018-11-20 09:29:16 +01:00
parent 26a248b14a
commit caea6212ed
5 changed files with 41 additions and 3 deletions

View File

@@ -10,15 +10,19 @@
*/
import javascript
/** Holds if `base` declares or inherits method `m` with the given `name`. */
predicate hasMethod(ClassDefinition base, string name, MethodDefinition m) {
m = base.getMethod(name) or
hasMethod(base.getSuperClassDefinition(), name, m)
}
/**
* Holds if `access` is in`fromMethod`, and it references `toMethod` through `this`.
*/
predicate isLocalMethodAccess(PropAccess access, MethodDefinition fromMethod, MethodDefinition toMethod) {
fromMethod.getDeclaringClass() = toMethod.getDeclaringClass() and
hasMethod(fromMethod.getDeclaringClass(), access.getPropertyName(), toMethod) and
access.getEnclosingFunction() = fromMethod.getBody() and
access.getBase() instanceof ThisExpr and
access.getPropertyName() = toMethod.getName()
access.getBase() instanceof ThisExpr
}
string getKind(MethodDefinition m) {

View File

@@ -216,6 +216,13 @@ class ClassDefinition extends @classdefinition, ClassOrInterface, AST::ValueNode
)
}
/**
* Gets the definition of the super class of this class, if it can be determined.
*/
ClassDefinition getSuperClassDefinition() {
result = getSuperClass().analyze().getAValue().(AbstractClass).getClass()
}
}
/**