JS: address review comments

This commit is contained in:
Esben Sparre Andreasen
2018-11-20 08:37:23 +01:00
parent daed0653cb
commit ee7a6af7c7
9 changed files with 23 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
/**
* Provides classes for working with analysis-specific abstract values.
*
* Implement a subclass of `CustomAbstractValueDefinition` When the builtin
* Implement a subclass of `CustomAbstractValueDefinition` when the builtin
* abstract values of `AbstractValues.qll` are not expressive enough.
*
* For performance reasons, all subclasses of `CustomAbstractValueDefinition`
@@ -17,12 +17,12 @@ private import InferredTypes
*
* Wraps a `CustomAbstractValueDefinition`.
*/
class DefinedCustomAbstractValue extends AbstractValue, TDefinedCustomAbstractValue {
class CustomAbstractValueFromDefinition extends AbstractValue, TCustomAbstractValueFromDefinition {
CustomAbstractValueDefinition def;
DefinedCustomAbstractValue() {
this = TDefinedCustomAbstractValue(def)
CustomAbstractValueFromDefinition() {
this = TCustomAbstractValueFromDefinition(def)
}
override InferredType getType() {
@@ -57,10 +57,14 @@ class DefinedCustomAbstractValue extends AbstractValue, TDefinedCustomAbstractVa
result = def.toString()
}
/**
* Gets the definition that induces this value.
*/
CustomAbstractValueDefinition getDefinition() {
result = def
}
/** Holds if this is a value whose properties the type inference tracks. */
predicate shouldTrackProperties() {
def.shouldTrackProperties()
}
@@ -68,7 +72,7 @@ class DefinedCustomAbstractValue extends AbstractValue, TDefinedCustomAbstractVa
}
/**
* A node that induces an analysis-specific abstract value.
* A data-flow node that induces an analysis-specific abstract value.
*
* Enables modular extensions of `AbstractValue`.
*
@@ -128,9 +132,10 @@ abstract class CustomAbstractValueDefinition extends Locatable {
* Gets the induced abstract value.
*/
AbstractValue getAbstractValue() {
result.(DefinedCustomAbstractValue).getDefinition() = this
result.(CustomAbstractValueFromDefinition).getDefinition() = this
}
/** Holds if this is a value whose properties the type inference tracks. */
abstract predicate shouldTrackProperties();
}
@@ -138,12 +143,12 @@ abstract class CustomAbstractValueDefinition extends Locatable {
/**
* Flow analysis for custom abstract values.
*/
class DefinedCustomAbstractValueNode extends DataFlow::AnalyzedNode, DataFlow::ValueNode {
class CustomAbstractValueFromDefinitionNode extends DataFlow::AnalyzedNode, DataFlow::ValueNode {
DefinedCustomAbstractValue val;
CustomAbstractValueFromDefinition val;
DefinedCustomAbstractValueNode() {
val = TDefinedCustomAbstractValue(this.getAstNode())
CustomAbstractValueFromDefinitionNode() {
val = TCustomAbstractValueFromDefinition(this.getAstNode())
}
override AbstractValue getALocalValue() {

View File

@@ -78,5 +78,5 @@ predicate shouldTrackProperties(AbstractValue baseVal) {
shouldAlwaysTrackProperties(baseVal) or
baseVal instanceof AbstractObjectLiteral or
baseVal instanceof AbstractInstance or
baseVal.(DefinedCustomAbstractValue).shouldTrackProperties()
baseVal.(CustomAbstractValueFromDefinition).shouldTrackProperties()
}

View File

@@ -6,7 +6,7 @@
import semmle.javascript.dataflow.AbstractValues
private import semmle.javascript.dataflow.InferredTypes
import semmle.javascript.dataflow.DefinedCustomAbstractValues
import semmle.javascript.dataflow.CustomAbstractValueDefinitions
/** An abstract value inferred by the flow analysis. */
cached newtype TAbstractValue =
@@ -104,7 +104,7 @@ cached newtype TAbstractValue =
TCustomAbstractValue(CustomAbstractValueTag tag)
or
/** A custom abstract value induced by `def`. */
TDefinedCustomAbstractValue(CustomAbstractValueDefinition def)
TCustomAbstractValueFromDefinition(CustomAbstractValueDefinition def)
/**
* Gets a definite abstract value with the given type.

View File

@@ -14,8 +14,7 @@ import semmle.javascript.dataflow.Configuration
*/
predicate shouldTrackProperties(AbstractValue obj) {
obj instanceof AbstractExportsObject or
obj instanceof AbstractModuleObject or
obj.(DefinedCustomAbstractValue).shouldTrackProperties()
obj instanceof AbstractModuleObject
}
/**