avm2: `Array.every/some` should early return
This commit is contained in:
parent
07f979b582
commit
519feb9af7
|
@ -446,13 +446,12 @@ pub fn every<'gc>(
|
|||
.unwrap_or(Value::Null)
|
||||
.coerce_to_object(activation)
|
||||
.ok();
|
||||
let mut is_every = true;
|
||||
let mut iter = ArrayIter::new(activation, this)?;
|
||||
|
||||
while let Some(r) = iter.next(activation) {
|
||||
let (i, item) = r?;
|
||||
|
||||
is_every &= callback
|
||||
let result = callback
|
||||
.call(
|
||||
receiver,
|
||||
&[item, i.into(), this.into()],
|
||||
|
@ -460,9 +459,13 @@ pub fn every<'gc>(
|
|||
receiver.and_then(|r| r.proto()),
|
||||
)?
|
||||
.coerce_to_boolean();
|
||||
|
||||
if !result {
|
||||
return Ok(false.into());
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(is_every.into());
|
||||
return Ok(true.into());
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
@ -486,13 +489,12 @@ pub fn some<'gc>(
|
|||
.unwrap_or(Value::Null)
|
||||
.coerce_to_object(activation)
|
||||
.ok();
|
||||
let mut is_some = false;
|
||||
let mut iter = ArrayIter::new(activation, this)?;
|
||||
|
||||
while let Some(r) = iter.next(activation) {
|
||||
let (i, item) = r?;
|
||||
|
||||
is_some |= callback
|
||||
let result = callback
|
||||
.call(
|
||||
receiver,
|
||||
&[item, i.into(), this.into()],
|
||||
|
@ -500,9 +502,13 @@ pub fn some<'gc>(
|
|||
receiver.and_then(|r| r.proto()),
|
||||
)?
|
||||
.coerce_to_boolean();
|
||||
|
||||
if result {
|
||||
return Ok(true.into());
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(is_some.into());
|
||||
return Ok(false.into());
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
|
Loading…
Reference in New Issue