swf4 doesn't have NaN or Infinity

This commit is contained in:
Nathan Adams 2019-11-22 23:32:57 +01:00 committed by David Wendt
parent 581d0940b2
commit 638231e7fb
1 changed files with 31 additions and 3 deletions

View File

@ -6,6 +6,7 @@ use crate::backend::navigator::NavigationMethod;
use enumset::EnumSet; use enumset::EnumSet;
use gc_arena::MutationContext; use gc_arena::MutationContext;
use rand::Rng; use rand::Rng;
use std::f64;
mod function; mod function;
mod math; mod math;
@ -92,6 +93,32 @@ pub fn is_nan<'gc>(
} }
} }
pub fn get_infinity<'gc>(
avm: &mut Avm1<'gc>,
_action_context: &mut UpdateContext<'_, 'gc, '_>,
_this: ObjectCell<'gc>,
_args: &[Value<'gc>],
) -> Result<ReturnValue<'gc>, Error> {
if avm.current_swf_version() > 4 {
Ok(f64::INFINITY.into())
} else {
Ok(Value::Undefined.into())
}
}
pub fn get_nan<'gc>(
avm: &mut Avm1<'gc>,
_action_context: &mut UpdateContext<'_, 'gc, '_>,
_this: ObjectCell<'gc>,
_args: &[Value<'gc>],
) -> Result<ReturnValue<'gc>, Error> {
if avm.current_swf_version() > 4 {
Ok(f64::NAN.into())
} else {
Ok(Value::Undefined.into())
}
}
/// This structure represents all system builtins that are used regardless of /// This structure represents all system builtins that are used regardless of
/// whatever the hell happens to `_global`. These are, of course, /// whatever the hell happens to `_global`. These are, of course,
/// user-modifiable. /// user-modifiable.
@ -192,10 +219,11 @@ pub fn create_globals<'gc>(
EnumSet::empty(), EnumSet::empty(),
Some(function_proto), Some(function_proto),
); );
globals.define_value("NaN", Value::Number(std::f64::NAN), EnumSet::empty()); globals.add_property("NaN", Executable::Native(get_nan), None, EnumSet::empty());
globals.define_value( globals.add_property(
"Infinity", "Infinity",
Value::Number(std::f64::INFINITY), Executable::Native(get_infinity),
None,
EnumSet::empty(), EnumSet::empty(),
); );