@@ -152,34 +152,29 @@ private module CollectionDataFlow {
152152 }
153153
154154 /**
155- * A step for a `for of` statement on a Map, Set, or Iterator.
156- * For Sets and iterators the l-value are the elements of the set/iterator.
157- * For Maps the l-value is a tuple containing a key and a value.
155+ * A step for modelling `for of` iteration on arrays, maps, sets, and iterators.
156+ *
157+ * For sets and iterators the l-value are the elements of the set/iterator.
158+ * For maps the l-value is a tuple containing a key and a value.
158159 */
159- // This is partially duplicated behavior with the `for of` step for Arrays (`ArrayDataFlow::ForOfStep`).
160- // This duplication is required for the type-tracking steps defined in `CollectionsTypeTracking`.
161- private class ForOfStep extends CollectionFlowStep , DataFlow:: ValueNode {
162- ForOfStmt forOf ;
163- DataFlow:: Node element ;
164-
165- ForOfStep ( ) {
166- this .asExpr ( ) = forOf .getIterationDomain ( ) and
167- element = DataFlow:: lvalueNode ( forOf .getLValue ( ) )
168- }
169-
170- override predicate load ( DataFlow:: Node obj , DataFlow:: Node e , PseudoProperty prop ) {
171- obj = this and
172- e = element and
173- prop = arrayLikeElement ( )
160+ private class ForOfStep extends PreCallGraphStep {
161+ override predicate loadStep ( DataFlow:: Node obj , DataFlow:: Node e , string prop ) {
162+ exists ( ForOfStmt forOf |
163+ obj = forOf .getIterationDomain ( ) .flow ( ) and
164+ e = DataFlow:: lvalueNode ( forOf .getLValue ( ) ) and
165+ prop = arrayLikeElement ( )
166+ )
174167 }
175168
176- override predicate loadStore (
177- DataFlow:: Node pred , DataFlow:: Node succ , PseudoProperty fromProp , PseudoProperty toProp
169+ override predicate loadStoreStep (
170+ DataFlow:: Node pred , DataFlow:: SourceNode succ , string fromProp , string toProp
178171 ) {
179- pred = this and
180- succ = element and
181- fromProp = mapValueAll ( ) and
182- toProp = "1"
172+ exists ( ForOfStmt forOf |
173+ pred = forOf .getIterationDomain ( ) .flow ( ) and
174+ succ = DataFlow:: lvalueNode ( forOf .getLValue ( ) ) and
175+ fromProp = mapValueAll ( ) and
176+ toProp = "1"
177+ )
183178 }
184179 }
185180
0 commit comments