Merge pull request #921 from asger-semmle/class-node-absval

JS: use type inference to back up function-style classes
This commit is contained in:
Max Schaefer
2019-02-13 10:12:20 +00:00
committed by GitHub
4 changed files with 25 additions and 9 deletions

View File

@@ -725,8 +725,15 @@ module ClassNode {
*/
class FunctionStyleClass extends Range, DataFlow::ValueNode {
override Function astNode;
AbstractFunction function;
FunctionStyleClass() { exists(getAPropertyReference("prototype")) }
FunctionStyleClass() {
function.getFunction() = astNode and
exists (DataFlow::PropRef read |
read.getPropertyName() = "prototype" and
read.getBase().analyze().getAValue() = function
)
}
override string getName() { result = astNode.getName() }
@@ -775,14 +782,16 @@ module ClassNode {
/**
* Gets a reference to the prototype of this class.
*/
private DataFlow::SourceNode getAPrototypeReference() {
result = getAPropertyRead("prototype")
or
result = getAPropertySource("prototype")
or
exists(ExtendCall call |
call.getDestinationOperand() = getAPropertyRead("prototype") and
result = call.getASourceOperand()
DataFlow::SourceNode getAPrototypeReference() {
exists (DataFlow::SourceNode base | base.analyze().getAValue() = function |
result = base.getAPropertyRead("prototype")
or
result = base.getAPropertySource("prototype")
or
exists(ExtendCall call |
call.getDestinationOperand() = base.getAPropertyRead("prototype") and
result = call.getASourceOperand()
)
)
}