add explicit this to all member calls

This commit is contained in:
Erik Krogh Kristensen
2021-11-01 09:51:15 +01:00
parent 1c78c792ff
commit db40ccae81
85 changed files with 2063 additions and 1937 deletions

View File

@@ -106,14 +106,14 @@ class AngularModule extends TAngularModule {
* Get the array of dependencies from this module's definition.
*/
ArrayExpr getDependencyArray() {
getADefinition().getArgument(1).getALocalSource().asExpr() = result
this.getADefinition().getArgument(1).getALocalSource().asExpr() = result
}
/**
* Gets another module that this module lists as a dependency.
*/
AngularModule getADependency() {
getDependencyArray().getAnElement().mayHaveStringValue(result.getName())
this.getDependencyArray().getAnElement().mayHaveStringValue(result.getName())
}
/**
@@ -185,7 +185,7 @@ class ModuleApiCallDependencyInjection extends DependencyInjection {
}
override DataFlow::Node getAnInjectableFunction() {
result = call.getArgument(injectableArgPos())
result = call.getArgument(this.injectableArgPos())
}
}
@@ -231,15 +231,15 @@ class DirectiveInstance extends TDirectiveInstance {
/**
* Gets a DOM element matching this directive.
*/
DOM::ElementDefinition getAMatchingElement() { result = getATarget().getElement() }
DOM::ElementDefinition getAMatchingElement() { result = this.getATarget().getElement() }
/** Gets a textual representation of this directive. */
string toString() { result = getName() }
string toString() { result = this.getName() }
/**
* Gets a scope object for this directive.
*/
AngularScope getAScope() { result.mayApplyTo(getAMatchingElement()) }
AngularScope getAScope() { result.mayApplyTo(this.getAMatchingElement()) }
}
/**
@@ -265,10 +265,10 @@ abstract class CustomDirective extends DirectiveInstance {
abstract DataFlow::ValueNode getMemberInit(string name);
/** Gets the member `name` of this directive. */
DataFlow::SourceNode getMember(string name) { result.flowsTo(getMemberInit(name)) }
DataFlow::SourceNode getMember(string name) { result.flowsTo(this.getMemberInit(name)) }
/** Gets the method `name` of this directive. */
Function getMethod(string name) { DataFlow::valueNode(result) = getMember(name) }
Function getMethod(string name) { DataFlow::valueNode(result) = this.getMember(name) }
/** Gets a link function of this directive. */
abstract Function getALinkFunction();
@@ -283,39 +283,39 @@ abstract class CustomDirective extends DirectiveInstance {
abstract DataFlow::SourceNode getAnInstantiation();
/** Gets the controller function of this directive, if any. */
InjectableFunction getController() { result = getMember("controller") }
InjectableFunction getController() { result = this.getMember("controller") }
/** Gets the template URL of this directive, if any. */
string getTemplateUrl() { getMember("templateUrl").asExpr().mayHaveStringValue(result) }
string getTemplateUrl() { this.getMember("templateUrl").asExpr().mayHaveStringValue(result) }
/**
* Gets a template file for this directive, if any.
*/
HTML::HtmlFile getATemplateFile() {
result.getAbsolutePath().regexpMatch(".*/\\Q" + getTemplateUrl() + "\\E")
result.getAbsolutePath().regexpMatch(".*/\\Q" + this.getTemplateUrl() + "\\E")
}
/**
* Gets a scope object for this directive.
*/
override AngularScope getAScope() {
if hasIsolateScope()
if this.hasIsolateScope()
then result = MkIsolateScope(this)
else result = DirectiveInstance.super.getAScope()
}
private string getRestrictionString() {
getMember("restrict").asExpr().mayHaveStringValue(result)
this.getMember("restrict").asExpr().mayHaveStringValue(result)
}
private predicate hasTargetType(DirectiveTargetType type) {
not exists(getRestrictionString()) or
getRestrictionString().indexOf(type.toString()) != -1
not exists(this.getRestrictionString()) or
this.getRestrictionString().indexOf(type.toString()) != -1
}
override DirectiveTarget getATarget() {
result = DirectiveInstance.super.getATarget() and
hasTargetType(result.getType())
this.hasTargetType(result.getType())
}
}
@@ -342,11 +342,11 @@ class GeneralDirective extends CustomDirective, MkCustomDirective {
}
override DataFlow::ValueNode getMemberInit(string name) {
getAnInstantiation().hasPropertyWrite(name, result)
this.getAnInstantiation().hasPropertyWrite(name, result)
}
/** Gets the compile function of this directive, if any. */
Function getCompileFunction() { result = getMethod("compile") }
Function getCompileFunction() { result = this.getMethod("compile") }
/**
* Gets a pre/post link function of this directive defined on its definition object.
@@ -360,15 +360,15 @@ class GeneralDirective extends CustomDirective, MkCustomDirective {
private DataFlow::FunctionNode getLinkFunction(string kind) {
// { link: function postLink() { ... } }
kind = "post" and
result = getMember("link")
result = this.getMember("link")
or
// { link: { pre: function preLink() { ... }, post: function postLink() { ... } } }
(kind = "pre" or kind = "post") and
result = getMember("link").getAPropertySource(kind)
result = this.getMember("link").getAPropertySource(kind)
or
// { compile: function() { ... return link; } }
exists(Expr compileReturn, DataFlow::SourceNode compileReturnSrc |
compileReturn = getCompileFunction().getAReturnedExpr() and
compileReturn = this.getCompileFunction().getAReturnedExpr() and
compileReturnSrc.flowsToExpr(compileReturn)
|
// link = function postLink() { ... }
@@ -382,18 +382,18 @@ class GeneralDirective extends CustomDirective, MkCustomDirective {
}
/** Gets the pre-link function of this directive. */
Function getPreLinkFunction() { result = getLinkFunction("pre").getAstNode() }
Function getPreLinkFunction() { result = this.getLinkFunction("pre").getAstNode() }
/** Gets the post-link function of this directive. */
Function getPostLinkFunction() { result = getLinkFunction("post").getAstNode() }
Function getPostLinkFunction() { result = this.getLinkFunction("post").getAstNode() }
override Function getALinkFunction() { result = getLinkFunction(_).getAstNode() }
override Function getALinkFunction() { result = this.getLinkFunction(_).getAstNode() }
override predicate bindsToController() {
getMemberInit("bindToController").asExpr().mayHaveBooleanValue(true)
this.getMemberInit("bindToController").asExpr().mayHaveBooleanValue(true)
}
override predicate hasIsolateScope() { getMember("scope").asExpr() instanceof ObjectExpr }
override predicate hasIsolateScope() { this.getMember("scope").asExpr() instanceof ObjectExpr }
}
/**
@@ -527,7 +527,9 @@ class DirectiveTargetName extends string {
* Holds if the first component of this name is `x` or `data`,
* and hence should be stripped when normalizing.
*/
predicate stripFirstComponent() { getRawComponent(0) = "x" or getRawComponent(0) = "data" }
predicate stripFirstComponent() {
this.getRawComponent(0) = "x" or this.getRawComponent(0) = "data"
}
/**
* Gets the `i`th component of this name after processing:
@@ -537,9 +539,9 @@ class DirectiveTargetName extends string {
string getProcessedComponent(int i) {
exists(int j, string raw |
i >= 0 and
if stripFirstComponent() then j = i + 1 else j = i
if this.stripFirstComponent() then j = i + 1 else j = i
|
raw = getRawComponent(j) and
raw = this.getRawComponent(j) and
if i = 0 then result = raw else result = capitalize(raw)
)
}
@@ -548,7 +550,7 @@ class DirectiveTargetName extends string {
* Gets the camelCase version of this name.
*/
string normalize() {
result = concat(string c, int i | c = getProcessedComponent(i) | c, "" order by i)
result = concat(string c, int i | c = this.getProcessedComponent(i) | c, "" order by i)
}
}
@@ -760,27 +762,27 @@ class LinkFunction extends Function {
/**
* Gets the scope parameter of this function.
*/
Parameter getScopeParameter() { result = getParameter(0) }
Parameter getScopeParameter() { result = this.getParameter(0) }
/**
* Gets the element parameter of this function (contains a jqLite-wrapped DOM element).
*/
Parameter getElementParameter() { result = getParameter(1) }
Parameter getElementParameter() { result = this.getParameter(1) }
/**
* Gets the attributes parameter of this function.
*/
Parameter getAttributesParameter() { result = getParameter(2) }
Parameter getAttributesParameter() { result = this.getParameter(2) }
/**
* Gets the controller parameter of this function.
*/
Parameter getControllerParameter() { result = getParameter(3) }
Parameter getControllerParameter() { result = this.getParameter(3) }
/**
* Gets the transclude-function parameter of this function.
*/
Parameter getTranscludeFnParameter() { result = getParameter(4) }
Parameter getTranscludeFnParameter() { result = this.getParameter(4) }
}
/**
@@ -912,7 +914,7 @@ class RouteSetup extends DataFlow::CallNode, DependencyInjection {
* Gets the value of property `name` of the params-object provided to this call.
*/
DataFlow::SourceNode getRouteParam(string name) {
result.flowsTo(getOptionArgument(optionsArgumentIndex, name))
result.flowsTo(this.getOptionArgument(optionsArgumentIndex, name))
}
/**
@@ -921,7 +923,7 @@ class RouteSetup extends DataFlow::CallNode, DependencyInjection {
InjectableFunction getController() {
exists(DataFlow::SourceNode controllerProperty |
// Note that `.getController` cannot be used here, since that involves a cast to InjectableFunction, and that cast only succeeds because of this method
controllerProperty = getRouteParam("controller")
controllerProperty = this.getRouteParam("controller")
|
result = controllerProperty
or
@@ -933,7 +935,7 @@ class RouteSetup extends DataFlow::CallNode, DependencyInjection {
)
}
override DataFlow::Node getAnInjectableFunction() { result = getRouteParam("controller") }
override DataFlow::Node getAnInjectableFunction() { result = this.getRouteParam("controller") }
}
/**
@@ -974,7 +976,7 @@ private class DirectiveController extends Controller {
}
override predicate boundTo(DOM::ElementDefinition elem) {
boundAnonymously(elem) or boundToAs(elem, _)
this.boundAnonymously(elem) or this.boundToAs(elem, _)
}
override predicate boundToAs(DOM::ElementDefinition elem, string alias) {
@@ -1014,7 +1016,7 @@ private class RouteInstantiatedController extends Controller {
}
override predicate boundToAs(DOM::ElementDefinition elem, string name) {
boundTo(elem) and
this.boundTo(elem) and
setup.getRouteParam("controllerAs").asExpr().mayHaveStringValue(name)
}
}
@@ -1049,18 +1051,18 @@ private class BindCall extends DataFlow::PartialInvokeNode::Range, DataFlow::Cal
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
index >= 0 and
callback = getArgument(1) and
argument = getArgument(index + 2)
callback = this.getArgument(1) and
argument = this.getArgument(index + 2)
}
override DataFlow::SourceNode getBoundFunction(DataFlow::Node callback, int boundArgs) {
callback = getArgument(1) and
boundArgs = getNumArgument() - 2 and
callback = this.getArgument(1) and
boundArgs = this.getNumArgument() - 2 and
result = this
}
override DataFlow::Node getBoundReceiver(DataFlow::Node callback) {
callback = getArgument(1) and
result = getArgument(0)
callback = this.getArgument(1) and
result = this.getArgument(0)
}
}

View File

@@ -52,7 +52,7 @@ class NgSource extends MkNgSource {
NgSourceProvider getProvider() { result = provider }
/** Gets a textual representation of this element. */
string toString() { result = getText() }
string toString() { result = this.getText() }
}
/**
@@ -68,17 +68,17 @@ private class HtmlTextNodeAsNgSourceProvider extends NgSourceProvider, HTML::Tex
int offset;
HtmlTextNodeAsNgSourceProvider() {
source = getText().regexpFind(getInterpolatedExpressionPattern(), _, offset)
source = this.getText().regexpFind(getInterpolatedExpressionPattern(), _, offset)
}
override predicate providesSourceAt(
string src, string path, int startLine, int startColumn, int endLine, int endColumn
) {
src = source and
getLocation().hasLocationInfo(path, startLine, startColumn, endLine, endColumn) // this is the entire surrounding text element, we could be more precise by counting lines
this.getLocation().hasLocationInfo(path, startLine, startColumn, endLine, endColumn) // this is the entire surrounding text element, we could be more precise by counting lines
}
override DOM::ElementDefinition getEnclosingElement() { result = getParent() }
override DOM::ElementDefinition getEnclosingElement() { result = this.getParent() }
}
/**
@@ -88,8 +88,8 @@ abstract private class HtmlAttributeAsNgSourceProvider extends NgSourceProvider,
override predicate providesSourceAt(
string src, string path, int startLine, int startColumn, int endLine, int endColumn
) {
src = getSource() and
getLocation().hasLocationInfo(path, startLine, startColumn - getOffset(), endLine, _) and
src = this.getSource() and
this.getLocation().hasLocationInfo(path, startLine, startColumn - this.getOffset(), endLine, _) and
endColumn = startColumn + src.length() - 1
}
@@ -99,7 +99,7 @@ abstract private class HtmlAttributeAsNgSourceProvider extends NgSourceProvider,
/** The offset into the attribute where the expression starts. */
abstract int getOffset();
override DOM::ElementDefinition getEnclosingElement() { result = getElement() }
override DOM::ElementDefinition getEnclosingElement() { result = this.getElement() }
}
/**
@@ -110,7 +110,7 @@ private class HtmlAttributeAsInterpolatedNgSourceProvider extends HtmlAttributeA
int offset;
HtmlAttributeAsInterpolatedNgSourceProvider() {
source = getValue().regexpFind(getInterpolatedExpressionPattern(), _, offset) and
source = this.getValue().regexpFind(getInterpolatedExpressionPattern(), _, offset) and
not this instanceof HtmlAttributeAsPlainNgSourceProvider
}
@@ -137,7 +137,7 @@ private class HtmlAttributeAsPlainNgSourceProvider extends HtmlAttributeAsNgSour
)
}
override string getSource() { result = getValue() }
override string getSource() { result = this.getValue() }
override int getOffset() { result = 0 }
}
@@ -162,7 +162,7 @@ private class TemplateFieldNgSourceProvider extends NgSourceProvider {
string src, string path, int startLine, int startColumn, int endLine, int endColumn
) {
src = source and
getLocation().hasLocationInfo(path, startLine, startColumn - offset, endLine, _) and
this.getLocation().hasLocationInfo(path, startLine, startColumn - offset, endLine, _) and
endColumn = startColumn + src.length() - 1
}
@@ -180,7 +180,7 @@ abstract class NgToken extends TNgToken {
/** Gets a textual representation of this element. */
string toString() {
exists(string content |
is(content) and
this.is(content) and
result = "(" + this.ppKind() + ": " + content + ")"
)
}
@@ -370,7 +370,7 @@ abstract class NgAstNode extends TNode {
string ppChildren() {
result =
concat(NgAstNode child, int idx |
child = getChild(idx) and
child = this.getChild(idx) and
not child instanceof Empty
|
child.pp(), " " order by idx
@@ -378,7 +378,7 @@ abstract class NgAstNode extends TNode {
}
/** Gets a textual representation of this element. */
string toString() { result = pp() }
string toString() { result = this.pp() }
/**
* Pretty-prints this node.
@@ -394,8 +394,8 @@ class NgAst extends TNgAst, NgAstNode {
override string pp() {
exists(string oneTime |
(if isOneTime() then oneTime = " <oneTime>" else oneTime = "") and
result = "(NgAst:" + oneTime + " " + ppChildren() + ")"
(if this.isOneTime() then oneTime = " <oneTime>" else oneTime = "") and
result = "(NgAst:" + oneTime + " " + this.ppChildren() + ")"
)
}
@@ -413,7 +413,7 @@ class NgAst extends TNgAst, NgAstNode {
class NgExprStmt extends TNgExprStmt, NgAstNode {
override predicate at(NgToken start, NgToken end) { this = TNgExprStmt(start, end, _) }
override string pp() { result = "(NgExprStmt: " + ppChildren() + ")" }
override string pp() { result = "(NgExprStmt: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) { n = 0 and this = TNgExprStmt(_, _, result) }
}
@@ -426,12 +426,12 @@ class NgExprStmt extends TNgExprStmt, NgAstNode {
class NgFilterChain extends TNgFilterChain, NgAstNode {
override predicate at(NgToken start, NgToken end) { this = TNgFilterChain(start, end, _, _) }
override string pp() { result = "(NgFilterChain: " + ppChildren() + ")" }
override string pp() { result = "(NgFilterChain: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) {
n = 0 and result = getExpr()
n = 0 and result = this.getExpr()
or
n = 1 and result = getFilter()
n = 1 and result = this.getFilter()
}
/**
@@ -458,12 +458,12 @@ abstract class NgMaybeFilter extends NgAstNode { }
class NgFilter extends TNgFilter, NgMaybeFilter {
override predicate at(NgToken start, NgToken end) { this = TNgFilter(start, end, _, _) }
override string pp() { result = "(NgFilter: " + ppChildren() + ")" }
override string pp() { result = "(NgFilter: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) {
n = 0 and result = getHeadFilter()
n = 0 and result = this.getHeadFilter()
or
n = 1 and result = getTailFilter()
n = 1 and result = this.getTailFilter()
}
/**
@@ -488,11 +488,11 @@ class NgSingleFilter extends TNgSingleFilter, NgAstNode {
override string pp() {
exists(string sep |
(
if forall(NgAstNode child | child = getChild(_) | child instanceof Empty)
if forall(NgAstNode child | child = this.getChild(_) | child instanceof Empty)
then sep = ""
else sep = " "
) and
result = "(NgSingleFilter: " + getName() + sep + ppChildren() + ")"
result = "(NgSingleFilter: " + this.getName() + sep + this.ppChildren() + ")"
)
}
@@ -506,7 +506,7 @@ class NgSingleFilter extends TNgSingleFilter, NgAstNode {
/**
* Gets the `i`th argument expression of this filter call.
*/
NgExpr getArgument(int i) { result = getChild(0).(NgFilterArgument).getElement(i) }
NgExpr getArgument(int i) { result = this.getChild(0).(NgFilterArgument).getElement(i) }
}
/**
@@ -524,7 +524,7 @@ class NgVarExpr extends TNgVarExpr, NgExpr {
override predicate at(NgToken start, NgToken end) { start = end and start = identifier }
override string pp() { result = "(NgVarExpr: " + getName() + ")" }
override string pp() { result = "(NgVarExpr: " + this.getName() + ")" }
override NgAstNode getChild(int n) { none() }
@@ -540,9 +540,11 @@ class NgVarExpr extends TNgVarExpr, NgExpr {
class NgDotExpr extends TNgDotExpr, NgExpr {
override predicate at(NgToken start, NgToken end) { this = TNgDotExpr(start, end, _, _) }
override string pp() { result = "(NgDotExpr: " + getBase().pp() + "." + getName() + ")" }
override string pp() {
result = "(NgDotExpr: " + this.getBase().pp() + "." + this.getName() + ")"
}
override NgAstNode getChild(int n) { n = 0 and result = getBase() }
override NgAstNode getChild(int n) { n = 0 and result = this.getBase() }
/**
* Gets the node for the base expression of this expression.
@@ -561,7 +563,7 @@ class NgDotExpr extends TNgDotExpr, NgExpr {
class NgCallExpr extends TNgCallExpr, NgExpr {
override predicate at(NgToken start, NgToken end) { this = TNgCallExpr(start, end, _, _) }
override string pp() { result = "(NgCallExpr: " + ppChildren() + ")" }
override string pp() { result = "(NgCallExpr: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) {
n = 0 and this = TNgCallExpr(_, _, result, _)
@@ -572,12 +574,12 @@ class NgCallExpr extends TNgCallExpr, NgExpr {
/**
* Gets the callee expression of this call.
*/
NgExpr getCallee() { result = getChild(0) }
NgExpr getCallee() { result = this.getChild(0) }
/**
* Gets the `i`th argument expression of this call.
*/
NgExpr getArgument(int i) { result = getChild(1).(NgConsCallArgument).getElement(i) }
NgExpr getArgument(int i) { result = this.getChild(1).(NgConsCallArgument).getElement(i) }
}
/**
@@ -590,7 +592,7 @@ class NgString extends TNgString, NgExpr {
override predicate at(NgToken start, NgToken end) { start = end and start = stringToken }
override string pp() { result = getRawValue() }
override string pp() { result = this.getRawValue() }
override NgAstNode getChild(int n) { none() }
@@ -602,7 +604,9 @@ class NgString extends TNgString, NgExpr {
/**
* Gets the string value of this expression, excluding surrounding quotes.
*/
string getStringValue() { result = getRawValue().substring(1, getRawValue().length() - 1) }
string getStringValue() {
result = this.getRawValue().substring(1, this.getRawValue().length() - 1)
}
}
/**
@@ -615,7 +619,7 @@ class NgNumber extends TNgNumber, NgExpr {
override predicate at(NgToken start, NgToken end) { start = end and start = numberToken }
override string pp() { result = getValue() }
override string pp() { result = this.getValue() }
override NgAstNode getChild(int n) { none() }
@@ -636,7 +640,7 @@ abstract class NgMaybeFilterArgument extends NgAstNode { }
class NgFilterArgument extends TNgFilterArgument, NgMaybeFilterArgument {
override predicate at(NgToken start, NgToken end) { this = TNgFilterArgument(start, end, _, _) }
override string pp() { result = "(NgFilterArgument: " + ppChildren() + ")" }
override string pp() { result = "(NgFilterArgument: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) {
n = 0 and this = TNgFilterArgument(_, _, result, _)
@@ -649,8 +653,8 @@ class NgFilterArgument extends TNgFilterArgument, NgMaybeFilterArgument {
*/
NgExpr getElement(int i) {
if i = 0
then result = getChild(0)
else result = getChild(1).(NgFilterArgument).getElement(i - 1)
then result = this.getChild(0)
else result = this.getChild(1).(NgFilterArgument).getElement(i - 1)
}
}
@@ -665,7 +669,7 @@ abstract class NgCallArguments extends NgAstNode { }
class NgConsCallArgument extends TNgConsCallArgument, NgCallArguments {
override predicate at(NgToken start, NgToken end) { this = TNgConsCallArgument(start, end, _, _) }
override string pp() { result = "(NgConsCallArgument: " + ppChildren() + ")" }
override string pp() { result = "(NgConsCallArgument: " + this.ppChildren() + ")" }
override NgAstNode getChild(int n) {
n = 0 and this = TNgConsCallArgument(_, _, result, _)
@@ -678,8 +682,8 @@ class NgConsCallArgument extends TNgConsCallArgument, NgCallArguments {
*/
NgExpr getElement(int i) {
if i = 0
then result = getChild(0)
else result = getChild(1).(NgConsCallArgument).getElement(i - 1)
then result = this.getChild(0)
else result = this.getChild(1).(NgConsCallArgument).getElement(i - 1)
}
}