avm1: Correct ToInteger

* Coerce objects as well.
* Wrap numbers around i32.
This commit is contained in:
Callum Thomson 2021-07-09 00:39:07 +00:00 committed by GitHub
parent bdf693c9c4
commit 939d467897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View File

@ -2194,14 +2194,8 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
}
fn action_to_integer(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
let val = self.context.avm1.pop();
let value = match val {
Value::Undefined | Value::Null | Value::Object(_) => 0.0,
_ => val.coerce_to_f64(self)?,
};
self.context.avm1.push(value.trunc());
let val = self.context.avm1.pop().coerce_to_i32(self)?;
self.context.avm1.push(val);
Ok(FrameControl::Continue)
}

View File

@ -12,3 +12,17 @@
-2147483648
// int({})
0
// int(hello)
0
// int(ten)
10
// int(float)
10
// int(negative)
-10
// int(NaN)
0
// int(valof)
42
// int(0xffffffff)
-2147483648