avm1: Correct `Math.{min,max}`
Don't use `abstract_lt` because it compares strings alphabetically, unlike `Math.min` and `Math.max` that coerce to a number before comparing.
This commit is contained in:
parent
384d04536f
commit
f92926af54
|
@ -103,23 +103,24 @@ fn max<'gc>(
|
||||||
_this: Object<'gc>,
|
_this: Object<'gc>,
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(a) = args.get(0) {
|
let result = if let Some(a) = args.get(0) {
|
||||||
return if let Some(b) = args.get(1) {
|
let a = a.coerce_to_f64(activation)?;
|
||||||
match a.abstract_lt(b.to_owned(), activation)? {
|
if let Some(b) = args.get(1) {
|
||||||
Value::Bool(value) => {
|
let b = b.coerce_to_f64(activation)?;
|
||||||
if value {
|
use std::cmp::Ordering;
|
||||||
Ok(b.coerce_to_f64(activation)?.into())
|
match a.partial_cmp(&b) {
|
||||||
} else {
|
Some(Ordering::Less) => b,
|
||||||
Ok(a.coerce_to_f64(activation)?.into())
|
Some(Ordering::Equal) => a,
|
||||||
}
|
Some(Ordering::Greater) => a,
|
||||||
}
|
None => f64::NAN,
|
||||||
_ => Ok(f64::NAN.into()),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(f64::NAN.into())
|
f64::NAN
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f64::NEG_INFINITY
|
||||||
};
|
};
|
||||||
}
|
Ok(result.into())
|
||||||
Ok(f64::NEG_INFINITY.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn min<'gc>(
|
fn min<'gc>(
|
||||||
|
@ -127,23 +128,24 @@ fn min<'gc>(
|
||||||
_this: Object<'gc>,
|
_this: Object<'gc>,
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(a) = args.get(0) {
|
let result = if let Some(a) = args.get(0) {
|
||||||
return if let Some(b) = args.get(1) {
|
let a = a.coerce_to_f64(activation)?;
|
||||||
match a.abstract_lt(b.to_owned(), activation)? {
|
if let Some(b) = args.get(1) {
|
||||||
Value::Bool(value) => {
|
let b = b.coerce_to_f64(activation)?;
|
||||||
if value {
|
use std::cmp::Ordering;
|
||||||
Ok(a.coerce_to_f64(activation)?.into())
|
match a.partial_cmp(&b) {
|
||||||
} else {
|
Some(Ordering::Less) => a,
|
||||||
Ok(b.coerce_to_f64(activation)?.into())
|
Some(Ordering::Equal) => a,
|
||||||
}
|
Some(Ordering::Greater) => b,
|
||||||
}
|
None => f64::NAN,
|
||||||
_ => Ok(f64::NAN.into()),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(f64::NAN.into())
|
f64::NAN
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f64::INFINITY
|
||||||
};
|
};
|
||||||
}
|
Ok(result.into())
|
||||||
Ok(f64::INFINITY.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random<'gc>(
|
pub fn random<'gc>(
|
||||||
|
|
Loading…
Reference in New Issue