@@ -26,6 +26,7 @@ private import internal.AnalyzedParameters
2626private import internal.PreCallGraphStep
2727private import semmle.javascript.internal.CachedStages
2828private import semmle.javascript.dataflow.internal.DataFlowPrivate as Private
29+ private import semmle.javascript.dataflow.internal.VariableOrThis
2930
3031module DataFlow {
3132 /**
@@ -729,9 +730,7 @@ module DataFlow {
729730 private class ParameterFieldAsPropWrite extends PropWrite , PropNode {
730731 override ParameterField prop ;
731732
732- override Node getBase ( ) {
733- thisNode ( result , prop .getDeclaringClass ( ) .getConstructor ( ) .getBody ( ) )
734- }
733+ override Node getBase ( ) { result = TImplicitThisUse ( prop , false ) }
735734
736735 override Expr getPropertyNameExpr ( ) {
737736 none ( ) // The parameter value is not the name of the field
@@ -758,9 +757,7 @@ module DataFlow {
758757 exists ( prop .getInit ( ) )
759758 }
760759
761- override Node getBase ( ) {
762- thisNode ( result , prop .getDeclaringClass ( ) .getConstructor ( ) .getBody ( ) )
763- }
760+ override Node getBase ( ) { result = TImplicitThisUse ( prop , false ) }
764761
765762 override Expr getPropertyNameExpr ( ) { result = prop .getNameExpr ( ) }
766763
@@ -1045,12 +1042,12 @@ module DataFlow {
10451042 }
10461043
10471044 /**
1048- * A node representing the value passed as `this` argument in a `new` call or a `super` call .
1045+ * A node representing the value passed as `this` argument in a `new` call.
10491046 */
1050- class ConstructorThisArgumentNode extends TConstructorThisArgumentNode , DataFlow:: Node {
1051- private InvokeExpr expr ;
1047+ class NewCallThisArgumentNode extends TNewCallThisArgument , DataFlow:: Node {
1048+ private NewExpr expr ;
10521049
1053- ConstructorThisArgumentNode ( ) { this = TConstructorThisArgumentNode ( expr ) }
1050+ NewCallThisArgumentNode ( ) { this = TNewCallThisArgument ( expr ) }
10541051
10551052 override string toString ( ) { result = "implicit 'this' argument of " + expr }
10561053
@@ -1060,18 +1057,23 @@ module DataFlow {
10601057 }
10611058
10621059 /**
1063- * A node representing the post-update node corresponding to implicit uses of `this` in a constructor .
1060+ * A node representing an implicit use of `this` or its post-update node .
10641061 */
1065- private class ConstructorThisPostUpdateNode extends TConstructorThisPostUpdate , DataFlow:: Node {
1066- private Function constructor ;
1062+ private class ImplicitThisUseNode extends TImplicitThisUse , DataFlow:: Node {
1063+ private ImplicitThisUse use ;
1064+ private boolean isPost ;
10671065
1068- ConstructorThisPostUpdateNode ( ) { this = TConstructorThisPostUpdate ( constructor ) }
1066+ ImplicitThisUseNode ( ) { this = TImplicitThisUse ( use , isPost ) }
10691067
1070- override string toString ( ) { result = "[post-update] 'this' parameter of " + constructor }
1068+ override string toString ( ) {
1069+ if isPost = false
1070+ then result = "implicit 'this'"
1071+ else result = "[post-update] implicit 'this'"
1072+ }
10711073
1072- override StmtContainer getContainer ( ) { result = constructor }
1074+ override StmtContainer getContainer ( ) { result = use . getUseContainer ( ) }
10731075
1074- override Location getLocation ( ) { result = constructor .getLocation ( ) }
1076+ override Location getLocation ( ) { result = use .getLocation ( ) }
10751077 }
10761078
10771079 /**
@@ -1682,6 +1684,12 @@ module DataFlow {
16821684 pred = TReflectiveCallNode ( call , _) and
16831685 succ = TValueNode ( call )
16841686 )
1687+ or
1688+ // Pass 'this' into implicit uses of 'this'
1689+ exists ( ImplicitThisUse use |
1690+ pred = TThisNode ( use .getBindingContainer ( ) ) and
1691+ succ = TImplicitThisUse ( use , false )
1692+ )
16851693 }
16861694
16871695 pragma [ nomagic]
@@ -1772,12 +1780,6 @@ module DataFlow {
17721780 pred = TReflectiveParametersNode ( f ) and
17731781 succ = TValueNode ( f .getArgumentsVariable ( ) .getAnAccess ( ) )
17741782 )
1775- or
1776- // Pass 'this' into super calls
1777- exists ( SuperCall call |
1778- pred = TThisNode ( call .getBinder ( ) ) and
1779- succ = TConstructorThisArgumentNode ( call )
1780- )
17811783 }
17821784
17831785 private class ReflectiveParamsStep extends LegacyPreCallGraphStep {
0 commit comments