@@ -118,7 +118,11 @@ module DataFlow {
118
118
predicate accessesGlobal ( string g ) { globalVarRef ( g ) .flowsTo ( this ) }
119
119
120
120
/** Holds if this node may evaluate to the string `s`, possibly through local data flow. */
121
- predicate mayHaveStringValue ( string s ) { getAPredecessor ( ) .mayHaveStringValue ( s ) }
121
+ predicate mayHaveStringValue ( string s ) {
122
+ getAPredecessor ( ) .mayHaveStringValue ( s )
123
+ or
124
+ s = getStringValue ( )
125
+ }
122
126
123
127
/** Gets the string value of this node, if it is a string literal or constant string concatenation. */
124
128
string getStringValue ( ) { result = asExpr ( ) .getStringValue ( ) }
@@ -297,11 +301,6 @@ module DataFlow {
297
301
/** Gets the expression or declaration this node corresponds to. */
298
302
override AST:: ValueNode getAstNode ( ) { result = astNode }
299
303
300
- override predicate mayHaveStringValue ( string s ) {
301
- Node .super .mayHaveStringValue ( s ) or
302
- astNode .( ConstantString ) .getStringValue ( ) = s
303
- }
304
-
305
304
override BasicBlock getBasicBlock ( ) { astNode = result .getANode ( ) }
306
305
307
306
override predicate hasLocationInfo (
@@ -587,6 +586,7 @@ module DataFlow {
587
586
* This predicate is undefined for spread properties, accessor
588
587
* properties, and most uses of `Object.defineProperty`.
589
588
*/
589
+ pragma [ nomagic]
590
590
abstract Node getRhs ( ) ;
591
591
592
592
/**
@@ -648,25 +648,24 @@ module DataFlow {
648
648
* writes to the corresponding property.
649
649
*/
650
650
private class ObjectDefinePropertyAsPropWrite extends PropWrite , ValueNode {
651
- CallToObjectDefineProperty odp ;
651
+ override MethodCallExpr astNode ;
652
652
653
- ObjectDefinePropertyAsPropWrite ( ) { odp = this }
653
+ ObjectDefinePropertyAsPropWrite ( ) {
654
+ astNode .getReceiver ( ) .( GlobalVarAccess ) .getName ( ) = "Object" and
655
+ astNode .getMethodName ( ) = "defineProperty"
656
+ }
654
657
655
- override Node getBase ( ) { result = odp . getBaseObject ( ) }
658
+ override Node getBase ( ) { result = astNode . getArgument ( 0 ) . flow ( ) }
656
659
657
- override Expr getPropertyNameExpr ( ) { result = odp .getArgument ( 1 ) . asExpr ( ) }
660
+ override Expr getPropertyNameExpr ( ) { result = astNode .getArgument ( 1 ) }
658
661
659
- override string getPropertyName ( ) { result = odp . getPropertyName ( ) }
662
+ override string getPropertyName ( ) { result = astNode . getArgument ( 1 ) . getStringValue ( ) }
660
663
661
664
override Node getRhs ( ) {
662
- // not using `CallToObjectDefineProperty::getAPropertyAttribute` for performance reasons
663
- exists ( ObjectLiteralNode propdesc |
664
- propdesc .flowsTo ( odp .getPropertyDescriptor ( ) ) and
665
- propdesc .hasPropertyWrite ( "value" , result )
666
- )
665
+ result = astNode .getArgument ( 2 ) .( ObjectExpr ) .getPropertyByName ( "value" ) .getInit ( ) .flow ( )
667
666
}
668
667
669
- override ControlFlowNode getWriteNode ( ) { result = odp . getAstNode ( ) }
668
+ override ControlFlowNode getWriteNode ( ) { result = astNode }
670
669
}
671
670
672
671
/**
0 commit comments