From 39e46e5bd3461d6c8e6b573c05141ea2820be451 Mon Sep 17 00:00:00 2001 From: Toad06 Date: Thu, 19 May 2022 17:58:54 +0200 Subject: [PATCH] avm1: Remove `Value::from_bool` --- core/src/avm1/activation.rs | 36 ++++++++++-------------------------- core/src/avm1/value.rs | 14 -------------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index ac62b64e0..83bf6f4f5 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -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, 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) } diff --git a/core/src/avm1/value.rs b/core/src/avm1/value.rs index 5d1d16358..a63305e1b 100644 --- a/core/src/avm1/value.rs +++ b/core/src/avm1/value.rs @@ -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> { self.coerce_to_f64(activation).map(f64_to_wrapping_u8) }