avm1: Fix panic with [].unshift(x)

This commit is contained in:
Nathan Adams 2020-04-16 10:19:56 +02:00 committed by Mike Welsh
parent 0cac118b59
commit d0fd26a89c
4 changed files with 10 additions and 2 deletions

View File

@ -147,8 +147,10 @@ pub fn unshift<'gc>(
let new_length = old_length + args.len();
let offset = new_length - old_length;
for i in (old_length - 1..new_length).rev() {
this.set_array_element(i, this.array_element(i - offset), context.gc_context);
if old_length > 0 {
for i in (old_length - 1..new_length).rev() {
this.set_array_element(i, this.array_element(i - offset), context.gc_context);
}
}
for i in 0..args.len() {

View File

@ -185,3 +185,9 @@ undefined
// array[2]
undefined
// array.unshift(1,2)
2
// array
1,2