Skip to content

Commit 39e46e5

Browse files
Toad06kmeisthax
authored andcommitted
avm1: Remove Value::from_bool
1 parent c503f78 commit 39e46e5

File tree

2 files changed

+10
-40
lines changed

2 files changed

+10
-40
lines changed

core/src/avm1/activation.rs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
604604
let a = self.context.avm1.pop();
605605
let b = self.context.avm1.pop();
606606
let result = b.as_bool(self.swf_version()) && a.as_bool(self.swf_version());
607-
self.context
608-
.avm1
609-
.push(Value::from_bool(result, self.swf_version()));
607+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
610608
Ok(FrameControl::Continue)
611609
}
612610

@@ -949,8 +947,8 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
949947
let name_val = self.context.avm1.pop();
950948
let name = name_val.coerce_to_string(self)?;
951949

952-
//Fun fact: This isn't in the Adobe SWF19 spec, but this opcode returns
953-
//a boolean based on if the delete actually deleted something.
950+
// Fun fact: This isn't in the Adobe SWF19 spec, but this opcode returns
951+
// a boolean based on if the delete actually deleted something.
954952
let success = self.scope_cell().read().delete(self, name);
955953
self.context.avm1.push(success.into());
956954

@@ -1024,9 +1022,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
10241022
let a = self.context.avm1.pop().coerce_to_f64(self)?;
10251023
let b = self.context.avm1.pop().coerce_to_f64(self)?;
10261024
let result = b == a;
1027-
self.context
1028-
.avm1
1029-
.push(Value::from_bool(result, self.swf_version()));
1025+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
10301026
Ok(FrameControl::Continue)
10311027
}
10321028

@@ -1490,9 +1486,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
14901486
let a = self.context.avm1.pop();
14911487
let b = self.context.avm1.pop();
14921488
let result = b.coerce_to_f64(self)? < a.coerce_to_f64(self)?;
1493-
self.context
1494-
.avm1
1495-
.push(Value::from_bool(result, self.swf_version()));
1489+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
14961490
Ok(FrameControl::Continue)
14971491
}
14981492

@@ -1603,9 +1597,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
16031597
fn action_not(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
16041598
let a = self.context.avm1.pop();
16051599
let result = !a.as_bool(self.swf_version());
1606-
self.context
1607-
.avm1
1608-
.push(Value::from_bool(result, self.swf_version()));
1600+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
16091601
Ok(FrameControl::Continue)
16101602
}
16111603

@@ -1692,9 +1684,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
16921684
let a = self.context.avm1.pop();
16931685
let b = self.context.avm1.pop();
16941686
let result = b.as_bool(self.swf_version()) || a.as_bool(self.swf_version());
1695-
self.context
1696-
.avm1
1697-
.push(Value::from_bool(result, self.swf_version()));
1687+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
16981688
Ok(FrameControl::Continue)
16991689
}
17001690

@@ -1979,9 +1969,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
19791969
let a = self.context.avm1.pop();
19801970
let b = self.context.avm1.pop();
19811971
let result = b.coerce_to_string(self)? == a.coerce_to_string(self)?;
1982-
self.context
1983-
.avm1
1984-
.push(Value::from_bool(result, self.swf_version()));
1972+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
19851973
Ok(FrameControl::Continue)
19861974
}
19871975

@@ -2014,9 +2002,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
20142002
let a = self.context.avm1.pop();
20152003
let b = self.context.avm1.pop();
20162004
let result = b.coerce_to_string(self)?.gt(&a.coerce_to_string(self)?);
2017-
self.context
2018-
.avm1
2019-
.push(Value::from_bool(result, self.swf_version()));
2005+
self.context.avm1.push(result.into());
20202006
Ok(FrameControl::Continue)
20212007
}
20222008

@@ -2034,9 +2020,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
20342020
let a = self.context.avm1.pop();
20352021
let b = self.context.avm1.pop();
20362022
let result = b.coerce_to_string(self)?.lt(&a.coerce_to_string(self)?);
2037-
self.context
2038-
.avm1
2039-
.push(Value::from_bool(result, self.swf_version()));
2023+
self.context.avm1.push(result.into()); // Diverges from spec: returns a boolean even in SWF 4
20402024
Ok(FrameControl::Continue)
20412025
}
20422026

core/src/avm1/value.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,6 @@ impl<'gc> Value<'gc> {
366366
Ok(result)
367367
}
368368

369-
/// Converts a bool value into the appropriate value for the platform.
370-
/// This should be used when pushing a bool onto the stack.
371-
/// This handles SWFv4 pushing a Number, 0 or 1.
372-
pub fn from_bool(value: bool, swf_version: u8) -> Value<'gc> {
373-
// SWF version 4 did not have true bools and will push bools as 0 or 1.
374-
// e.g. SWF19 p. 72:
375-
// "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."
376-
if swf_version >= 5 {
377-
value.into()
378-
} else {
379-
(value as i32).into()
380-
}
381-
}
382-
383369
pub fn coerce_to_u8(&self, activation: &mut Activation<'_, 'gc, '_>) -> Result<u8, Error<'gc>> {
384370
self.coerce_to_f64(activation).map(f64_to_wrapping_u8)
385371
}

0 commit comments

Comments
 (0)