diff --git a/core/src/avm2/globals/Number.as b/core/src/avm2/globals/Number.as index ee7dbfa4a3f6..9f1bd9b3ec04 100644 --- a/core/src/avm2/globals/Number.as +++ b/core/src/avm2/globals/Number.as @@ -36,6 +36,80 @@ package { [API("680")] public static const LOG10E:Number = 0.4342944819032518; + [API("680")] + [Ruffle(FastCall)] + public static native function abs(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function acos(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function asin(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function atan(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function atan2(y:Number, x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function ceil(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function cos(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function exp(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function floor(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function log(x:Number):Number; + + // NOTE: See the the comment in Math.as for why max and min are marked as FastCall + + [API("680")] + [Ruffle(FastCall)] + public static native function max(x:Number = NEGATIVE_INFINITY, y:Number = NEGATIVE_INFINITY, ...rest):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function min(x:Number = POSITIVE_INFINITY, y:Number = POSITIVE_INFINITY, ...rest):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function pow(x:Number, y:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function random():Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function round(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function sin(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function sqrt(x:Number):Number; + + [API("680")] + [Ruffle(FastCall)] + public static native function tan(x:Number):Number; + { prototype.toExponential = function(digits:* = 0):String { var self:Number = this; diff --git a/core/src/avm2/globals/number.rs b/core/src/avm2/globals/number.rs index ec5d509c0bd3..e86aef0a4bd8 100644 --- a/core/src/avm2/globals/number.rs +++ b/core/src/avm2/globals/number.rs @@ -19,6 +19,25 @@ pub fn number_constructor<'gc>( Ok(number_value.into()) } +macro_rules! define_math_functions { + ($($name:ident),* $(,)?) => { + $( + pub fn $name<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Value<'gc>, + args: &[Value<'gc>], + ) -> Result, Error<'gc>> { + crate::avm2::globals::math::$name(activation, this, args) + } + )* + }; +} + +define_math_functions!( + abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, + sqrt, tan +); + pub fn call_handler<'gc>( activation: &mut Activation<'_, 'gc>, _this: Value<'gc>, diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/acos/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/acos/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/acos/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/acos/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/asin/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/asin/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/asin/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/asin/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/atan/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/atan/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/atan/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/atan/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/atan2/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/atan2/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/atan2/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/atan2/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/exp/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/exp/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/exp/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/exp/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/log/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/log/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/log/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/log/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/max/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/max/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/max/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/max/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/min/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/min/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/min/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/min/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/random/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/random/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/random/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/random/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/sin/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/sin/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/sin/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/sin/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/sqrt/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/sqrt/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/sqrt/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/sqrt/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/as3/Types/Number/tan/test.toml b/tests/tests/swfs/from_avmplus/as3/Types/Number/tan/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/as3/Types/Number/tan/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/Types/Number/tan/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true