avm1: Remove `Value::from_bool`

This commit is contained in:
Toad06 2022-05-19 17:58:54 +02:00 committed by kmeisthax
parent c503f78e13
commit 39e46e5bd3
2 changed files with 10 additions and 40 deletions

View File

@ -604,9 +604,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.as_bool(self.swf_version()) && a.as_bool(self.swf_version());
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -949,8 +947,8 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let name_val = self.context.avm1.pop();
let name = name_val.coerce_to_string(self)?;
//Fun fact: This isn't in the Adobe SWF19 spec, but this opcode returns
//a boolean based on if the delete actually deleted something.
// Fun fact: This isn't in the Adobe SWF19 spec, but this opcode returns
// a boolean based on if the delete actually deleted something.
let success = self.scope_cell().read().delete(self, name);
self.context.avm1.push(success.into());
@ -1024,9 +1022,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop().coerce_to_f64(self)?;
let b = self.context.avm1.pop().coerce_to_f64(self)?;
let result = b == a;
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -1490,9 +1486,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.coerce_to_f64(self)? < a.coerce_to_f64(self)?;
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -1603,9 +1597,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
fn action_not(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
let a = self.context.avm1.pop();
let result = !a.as_bool(self.swf_version());
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -1692,9 +1684,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.as_bool(self.swf_version()) || a.as_bool(self.swf_version());
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -1979,9 +1969,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.coerce_to_string(self)? == a.coerce_to_string(self)?;
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}
@ -2014,9 +2002,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.coerce_to_string(self)?.gt(&a.coerce_to_string(self)?);
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into());
Ok(FrameControl::Continue)
}
@ -2034,9 +2020,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
let a = self.context.avm1.pop();
let b = self.context.avm1.pop();
let result = b.coerce_to_string(self)?.lt(&a.coerce_to_string(self)?);
self.context
.avm1
.push(Value::from_bool(result, self.swf_version()));
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
Ok(FrameControl::Continue)
}

View File

@ -366,20 +366,6 @@ impl<'gc> Value<'gc> {
Ok(result)
}
/// Converts a bool value into the appropriate value for the platform.
/// This should be used when pushing a bool onto the stack.
/// This handles SWFv4 pushing a Number, 0 or 1.
pub fn from_bool(value: bool, swf_version: u8) -> Value<'gc> {
// SWF version 4 did not have true bools and will push bools as 0 or 1.
// e.g. SWF19 p. 72:
// "If the numbers are equal, true is pushed to the stack for SWF 5 and later. For SWF 4, 1 is pushed to the stack."
if swf_version >= 5 {
value.into()
} else {
(value as i32).into()
}
}
pub fn coerce_to_u8(&self, activation: &mut Activation<'_, 'gc, '_>) -> Result<u8, Error<'gc>> {
self.coerce_to_f64(activation).map(f64_to_wrapping_u8)
}