Skip to content

Commit b221485

Browse files
Toad06Herschel
authored andcommitted
avm1: Fix Action::Divide in SWFv4
1 parent 91346f5 commit b221485

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/src/avm1/activation.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,18 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
966966
}
967967

968968
fn action_divide(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
969-
// AS1 divide
970969
let a = self.context.avm1.pop().coerce_to_f64(self)?;
971970
let b = self.context.avm1.pop().coerce_to_f64(self)?;
972971

973-
// TODO(Herschel): SWF19: "If A is zero, the result NaN, Infinity, or -Infinity is pushed to the in SWF 5 and later.
974-
// In SWF 4, the result is the string #ERROR#.""
975-
// Seems to be untrue for SWF v4, I get 1.#INF.
976-
let result = b / a;
972+
// SWF19: "If A is zero, the result NaN, Infinity, or -Infinity is pushed to the stack in SWF 5 and later.
973+
// In SWF 4, the result is the string #ERROR#."
974+
let result: Value<'gc> = if a == 0.0 && self.swf_version() < 5 {
975+
"#ERROR#".into()
976+
} else {
977+
(b / a).into()
978+
};
977979

978-
self.context.avm1.push(result.into());
980+
self.context.avm1.push(result);
979981
Ok(FrameControl::Continue)
980982
}
981983

0 commit comments

Comments
 (0)