Skip to content

Commit cd57c9d

Browse files
authored
fix(ecmascript): FlattenIntoArray increment targetIndex (#594)
1 parent 7eaa965 commit cd57c9d

File tree

3 files changed

+2300
-2317
lines changed

3 files changed

+2300
-2317
lines changed

nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_prototype.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,9 +3991,8 @@ fn flatten_into_array(
39913991
// 2. Let targetIndex be start.
39923992
let mut target_index = start;
39933993
// 3. Let sourceIndex be +0𝔽.
3994-
let mut source_index = 0;
39953994
// 4. Repeat, while ℝ(sourceIndex) < sourceLen,
3996-
while source_index < source_len {
3995+
for source_index in 0..source_len {
39973996
// a. Let P be ! ToString(sourceIndex).
39983997
let source_index_number = Number::try_from(source_index).unwrap();
39993998
let p = PropertyKey::try_from(source_index).unwrap();
@@ -4002,7 +4001,6 @@ fn flatten_into_array(
40024001
// c. If exists is true, then
40034002
if !exists {
40044003
// d. Set sourceIndex to sourceIndex + 1𝔽.
4005-
source_index += 1;
40064004
continue;
40074005
}
40084006
// i. Let element be ? Get(source, P).
@@ -4037,7 +4035,7 @@ fn flatten_into_array(
40374035
}
40384036
// v. If shouldFlatten is true, then
40394037
if should_flatten {
4040-
// Note: Element is necessary an Array.
4038+
// Note: Element is necessarily an Array.
40414039
let element = Object::try_from(element)
40424040
.unwrap()
40434041
.bind(gc.nogc())
@@ -4077,9 +4075,9 @@ fn flatten_into_array(
40774075
gc.reborrow(),
40784076
)?;
40794077
// 3. Set targetIndex to targetIndex + 1.
4078+
target_index += 1;
40804079
}
40814080
// d. Set sourceIndex to sourceIndex + 1𝔽.
4082-
source_index += 1;
40834081
}
40844082
// 5. Return targetIndex.
40854083
Ok(target_index)

0 commit comments

Comments
 (0)