Skip to content

Commit ef6059a

Browse files
authored
Merge pull request #22844 from ku-plrg/js/array-flatmap-thisarg
JS: Fix flatMap thisArg flowing to the callback index
2 parents 781e068 + 0d5f3aa commit ef6059a

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed the flow summary for `Array.prototype.flatMap`. The `thisArg` argument now flows to the callback's `this` instead of its index parameter.

‎javascript/ql/lib/semmle/javascript/internal/flow_summaries/Arrays.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class FlatMap extends SummarizedCallable::Range {
290290
output = "Argument[0].Parameter[2]"
291291
or
292292
input = "Argument[1]" and
293-
output = "Argument[0].Parameter[1]"
293+
output = "Argument[0].Parameter[this]"
294294
or
295295
input = "Argument[0].ReturnValue." + ["ArrayElement", "WithoutArrayElement"] and
296296
output = "ReturnValue.ArrayElement"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function flatMapThisArg() {
2+
[0].flatMap(function (x, i) {
3+
sink(this); // $ hasValueFlow=flatMap.thisArg
4+
sink(i); // OK - the index, not thisArg
5+
return [];
6+
}, source('flatMap.thisArg'));
7+
}

0 commit comments

Comments
 (0)