add indirect calls to logging methods as logging methods

This commit is contained in:
Erik Krogh Kristensen 2019-10-29 11:45:54 +01:00
Родитель 351cb46bb9
Коммит b12e255fd8
1 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -62,7 +62,40 @@ private module Console {
then result = getArgument([1 .. getNumArgument()])
else result = getAnArgument()
}
/**
* Gets the name of the console logging method, e.g. "log", "error", "assert", etc.
*/
string getName() {
result = name
}
}
/**
* A call to a function that forwards all arguments to some console logging mechanism.
* The called function contain a single statement similar to: `console.log.apply(this, arguments)`.
*/
class IndirectConsoleLoggerCall extends LoggerCall {
ConsoleLoggerCall consoleCall;
DataFlow::MethodCallNode applyCall;
IndirectConsoleLoggerCall() {
forex(Function f | f = this.getACallee() |
f.getNumBodyStmt() = 1 and
consoleCall.getContainer() = f and
applyCall.getContainer() = f and
applyCall.getMethodName() = "apply" and
applyCall.getReceiver() = consoleCall.getCalleeNode() and
applyCall.getArgument(1).asExpr().(VarAccess).getName() = "arguments"
)
}
override DataFlow::Node getAMessageComponent() {
if consoleCall.getName() = "assert"
then result = getArgument([1 .. getNumArgument()])
else result = getAnArgument()
}
}
}
/**