parent
70caf983ab
commit
95acc14190
|
@ -182,10 +182,11 @@ pub fn unshift<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let old_length = this.length();
|
||||
let new_length = old_length + args.len();
|
||||
let offset = new_length - old_length;
|
||||
let offset = args.len();
|
||||
|
||||
if old_length > 0 {
|
||||
for i in (old_length - 1..new_length).rev() {
|
||||
// Move all elements up by [offset], in reverse order.
|
||||
for i in (offset..new_length).rev() {
|
||||
this.set_array_element(
|
||||
i,
|
||||
this.array_element(i - offset),
|
||||
|
@ -195,6 +196,7 @@ pub fn unshift<'gc>(
|
|||
}
|
||||
|
||||
for i in 0..args.len() {
|
||||
// Put the new elements at the start of the array.
|
||||
this.set_array_element(
|
||||
i,
|
||||
args.get(i).unwrap().to_owned(),
|
||||
|
|
|
@ -191,3 +191,15 @@ undefined
|
|||
// array
|
||||
1,2
|
||||
|
||||
// array.unshift(1,2)
|
||||
4
|
||||
|
||||
// array
|
||||
1,2,1,2
|
||||
|
||||
// array.unshift(3,4,5)
|
||||
7
|
||||
|
||||
// array
|
||||
3,4,5,1,2,1,2
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue