gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10533: ActionScript / VM correction


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10533: ActionScript / VM corrections, various swfdec and actionscript.all test
Date: Fri, 09 Jan 2009 14:50:44 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10533
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-01-09 14:50:44 +0100
message:
  ActionScript / VM corrections, various swfdec and actionscript.all test
  passes.
modified:
  libcore/MovieClip.cpp
  libcore/as_value.cpp
  libcore/asobj/Math_as.cpp
  libcore/asobj/Mouse_as.cpp
  libcore/vm/ASHandlers.cpp
  testsuite/actionscript.all/ASnative.as
  testsuite/actionscript.all/Date.as
  testsuite/actionscript.all/Math.as
  testsuite/swfdec/PASSING
    ------------------------------------------------------------
    revno: 10524.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 08:29:26 +0100
    message:
      Make Math.min() and Math.max() (without arguments) return the correct 
value.
      
      Math.round() also calls valueOf on an unused second argument, if present,
      so we use a UnaryMathFunc and push it in the template like the rest.
    modified:
      libcore/asobj/Math_as.cpp
    ------------------------------------------------------------
    revno: 10524.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 09:02:09 +0100
    message:
      Prefer conversion to number on ActionNewLessThan, or comparison of
      Date objects fails.
    modified:
      libcore/as_value.cpp
      libcore/vm/ASHandlers.cpp
    ------------------------------------------------------------
    revno: 10524.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 09:37:20 +0100
    message:
      Handle std::pow correctly.
      
      The swfdec math-function test now passes except for std::pow(Infinity, 
0.4)
      and std::pow(-Infinity, 0.4), which are apparently supposed to return NaN.
      The pp LNX 9,0,115,0 returns Infinity, however, which also is what Gnash 
does.
    modified:
      libcore/asobj/Math_as.cpp
      testsuite/actionscript.all/Date.as
      testsuite/actionscript.all/Math.as
    ------------------------------------------------------------
    revno: 10524.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 11:15:30 +0100
    message:
      Retrieve Math args in the correct order (affects valueOf call order), 
always
      convert first two arguments, even when there are 3 or more, and convert
      arguments to Math.random() as well, even though both are unused.
      
      Passes swfdec tests.
    modified:
      libcore/asobj/Math_as.cpp
    ------------------------------------------------------------
    revno: 10524.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 11:32:44 +0100
    message:
      New test passes.
    modified:
      testsuite/actionscript.all/ASnative.as
      testsuite/swfdec/PASSING
    ------------------------------------------------------------
    revno: 10524.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 12:16:14 +0100
    message:
      Queue init event on dynamic MovieClip construction too. Passes tests in
      swfdec testsuite.
    modified:
      libcore/MovieClip.cpp
    ------------------------------------------------------------
    revno: 10524.1.7
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-01-09 12:26:09 +0100
    message:
      Mouse is always initialized as an AsBroadcaster. Prop flags should take 
care
      of access for SWF5 and below.
      
      Correct Mouse prop flags.
    modified:
      libcore/asobj/Mouse_as.cpp
      testsuite/swfdec/PASSING
=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp     2008-12-28 10:01:13 +0000
+++ b/libcore/MovieClip.cpp     2009-01-09 11:16:14 +0000
@@ -2266,7 +2266,10 @@
                 "INITIALIZE and CONSTRUCT events immediately"), getTarget());
 #endif
 
-        on_event(event_id::INITIALIZE);
+        // Tested in testsuite/swfdec/duplicateMovieclip-events.c and
+        // testsuite/swfdec/clone-sprite-events.c not to call on_event
+        // immediately.
+        queueEvent(event_id::INITIALIZE, movie_root::apINIT);
     }
 
 

=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp      2009-01-09 12:55:01 +0000
+++ b/libcore/as_value.cpp      2009-01-09 13:50:44 +0000
@@ -414,13 +414,6 @@
                hint = STRING;
        }
 
-#if 0
-       else if ( m_type == MOVIECLIP && swfVersion > 5 )
-       {
-               throw ActionTypeError();
-       }
-#endif
-
        return to_primitive(hint);
 }
 

=== modified file 'libcore/asobj/Math_as.cpp'
--- a/libcore/asobj/Math_as.cpp 2008-12-22 12:16:50 +0000
+++ b/libcore/asobj/Math_as.cpp 2009-01-09 13:50:44 +0000
@@ -50,10 +50,14 @@
     as_value math_max(const fn_call& fn);
     as_value math_min(const fn_call& fn);
     as_value math_random(const fn_call& fn);
-    as_value math_round(const fn_call& fn);
+
+    // There's no std::round, but Math.round behaves like all the other
+    // unary functions.
+    inline double round(double d);
 
     template<UnaryMathFunc Func> as_value unaryFunction(const fn_call& fn);
     template<BinaryMathFunc Func> as_value binaryFunction(const fn_call& fn);
+    template<> as_value binaryFunction<std::pow>(const fn_call& fn);
 
 }
 
@@ -72,7 +76,7 @@
     vm.registerNative(unaryFunction<std::exp>, 200, 7);
     vm.registerNative(unaryFunction<std::log>, 200, 8);
     vm.registerNative(unaryFunction<std::sqrt>, 200, 9);
-    vm.registerNative(math_round, 200, 10);
+    vm.registerNative(unaryFunction<round>, 200, 10);
     vm.registerNative(math_random, 200, 11);
     vm.registerNative(unaryFunction<std::floor>, 200, 12);
     vm.registerNative(unaryFunction<std::ceil>, 200, 13);
@@ -110,35 +114,58 @@
 unaryFunction(const fn_call& fn)
 {
     if (fn.nargs < 1) return as_value(NaN);
-    if (fn.nargs == 2) fn.arg(1).to_number();
     double arg = fn.arg(0).to_number();        
+    if (fn.nargs > 1) fn.arg(1).to_number();
     return as_value(Func(arg));
 }
 
-// Two-argument functions.
-//
-// In general, two-argument functions called with no or one argument
-// return NaN.
-// This is always true for atan2, but there are the following exceptions:
-// pow(1) == 1, max() == -Infinity and min() == Infinity
-//
-// Flash's pow() is clever cos it copes with negative numbers to an integral
-// power, and can do pow(-2, -1) == -0.5 and pow(-2, -2) == 0.25.
-// Fortunately, pow() in the cmath library works the same way.
+/// Two-argument functions.
+//
+/// As a rule, two-argument functions called with no or one argument
+/// return NaN. However, three of the four functions break this rule in
+/// different ways. Exceptions are described below.
+//
+/// There is no real need for this template at present, as it only handles
+/// Math.atan2. But it might be useful if other Math functions are added.
 template<BinaryMathFunc Func>
 as_value
 binaryFunction(const fn_call& fn)
 {
     if (fn.nargs < 2) return as_value(NaN);
-    double arg1 = fn.arg(1).to_number();
     double arg0 = fn.arg(0).to_number();       
+    double arg1 = fn.arg(1).to_number();
     return as_value(Func(arg0, arg1));
 }
 
-
+/// Math.pow
+//
+/// Math.pow is odd in that Math.pow(1) returns 1. All other single-argument
+/// calls return NaN.
+template<>
+as_value
+binaryFunction<std::pow>(const fn_call& fn)
+{
+    if (!fn.nargs) return as_value(NaN);
+    
+    double arg0 = fn.arg(0).to_number();
+
+    if (fn.nargs < 2) {
+        if (arg0 == 1) return as_value(1);
+        return as_value(NaN);
+    }
+
+    double arg1 = fn.arg(1).to_number();
+    return as_value(std::pow(arg0, arg1));
+}
+
+/// Math.min
+//
+/// Math.min() returns Infinity
 as_value
 math_min(const fn_call& fn)
 {
+    if (!fn.nargs) return as_value(std::numeric_limits<double>::infinity());
+
        if (fn.nargs < 2) return as_value(NaN);
 
        double arg0 = fn.arg(0).to_number();
@@ -153,10 +180,15 @@
 
 }
 
+/// Math.min
+//
+/// Math.max() returns -Infinity
 as_value
 math_max(const fn_call& fn)
 {
-       if (fn.nargs < 2) return as_value(NaN);
+    if (!fn.nargs) return as_value(-std::numeric_limits<double>::infinity());
+       
+    if (fn.nargs < 2) return as_value(NaN);
 
        double arg0 = fn.arg(0).to_number();
        double arg1 = fn.arg(1).to_number();
@@ -169,11 +201,17 @@
        return as_value(std::max(arg0, arg1));
 }
 
-// A couple of oddballs.
+/// Math.random()
+//
+/// The first two arguments are converted to numbers, even though
+/// neither is used.
 as_value
-math_random(const fn_call& /* fn */)
+math_random(const fn_call& fn)
 {
 
+    if (fn.nargs) fn.arg(0).to_number();
+    if (fn.nargs > 1) fn.arg(1).to_number();
+
        VM::RNG& rnd = VM::get().randomNumberGenerator();
 
        // Produces double ( 0 <= n < 1)
@@ -185,19 +223,10 @@
 
 }
 
-
-as_value
-math_round(const fn_call& fn)
+inline double
+round(double d)
 {
-       // round argument to nearest int. 0.5 goes to 1 and -0.5 goes to 0
-       double result;
-
-       if (fn.nargs < 1) result = NaN;
-       else {
-               double arg0 = fn.arg(0).to_number();
-               result = std::floor(arg0 + 0.5);
-       }
-       return as_value(result);
+    return std::floor(d + 0.5);
 }
 
 void

=== modified file 'libcore/asobj/Mouse_as.cpp'
--- a/libcore/asobj/Mouse_as.cpp        2008-12-19 08:23:56 +0000
+++ b/libcore/asobj/Mouse_as.cpp        2009-01-09 11:26:09 +0000
@@ -72,12 +72,16 @@
 {
     VM& vm = o.getVM();
 
-    o.init_member("show", vm.getNative(5, 0));
-    o.init_member("hide", vm.getNative(5, 1));
-    
-    if (vm.getSWFVersion() > 5) {
-        AsBroadcaster::initialize(o);
-    }
+    const int flags = as_prop_flags::dontEnum |
+                      as_prop_flags::dontDelete |
+                      as_prop_flags::readOnly;
+
+    o.init_member("show", vm.getNative(5, 0), flags);
+    o.init_member("hide", vm.getNative(5, 1), flags);
+ 
+    // Mouse is always initialized as an AsBroadcaster, even for
+    // SWF5.   
+    AsBroadcaster::initialize(o);
 }
 
 /// Returns whether the mouse was visible before the call.

=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2009-01-09 01:03:55 +0000
+++ b/libcore/vm/ASHandlers.cpp 2009-01-09 13:50:44 +0000
@@ -3104,7 +3104,7 @@
     as_value operand1 = env.top(1);
     as_value operand2 = env.top(0);
 
-    try { operand1 = operand1.to_primitive(); }
+    try { operand1 = operand1.to_primitive(as_value::NUMBER); }
     catch (ActionTypeError& e)
     {
         log_debug(_("%s.to_primitive() threw an error during "
@@ -3118,7 +3118,7 @@
         return;
     }
 
-    try { operand2 = operand2.to_primitive(); }
+    try { operand2 = operand2.to_primitive(as_value::NUMBER); }
     catch (ActionTypeError& e)
     {
         log_debug(_("%s.to_primitive() threw an error during "

=== modified file 'testsuite/actionscript.all/ASnative.as'
--- a/testsuite/actionscript.all/ASnative.as    2008-12-09 13:58:38 +0000
+++ b/testsuite/actionscript.all/ASnative.as    2009-01-09 10:32:44 +0000
@@ -186,7 +186,7 @@
 a = ASnative(200, 19);
 check_equals(a(func), true); // isFinite
 
-xcheck_equals (countVO, 25); // calls to valueOf.
+check_equals (countVO, 25); // calls to valueOf.
 check_equals (countTS, 0); // calls to toString.
 
 // String functions (call toString)
@@ -260,7 +260,7 @@
 check_equals (countTS, 2);
 #endif
 
-xcheck_equals (countVO, 25);
+check_equals (countVO, 25);
 
 /// SharedObject undocumented functions.
 

=== modified file 'testsuite/actionscript.all/Date.as'
--- a/testsuite/actionscript.all/Date.as        2008-10-04 10:29:04 +0000
+++ b/testsuite/actionscript.all/Date.as        2009-01-09 08:37:20 +0000
@@ -648,6 +648,23 @@
 check_equals ((Date.UTC(-1, 12).valueOf() < -2208988799999.5 &&
                Date.UTC(-1, 12).valueOf() > -2208988800000.5), true);
 
+pd = new Date();
+ret = (pd < 67);
+check_equals(typeof(ret), "boolean");
+
+ret = (pd > 67);
+check_equals(typeof(ret), "boolean");
+check_equals(ret, true);
+
+ret = (pd < "a string");
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+
+ret = (pd > "a string");
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+
+
 // Check if Date, concatenated to a string, is in human readable form
 d = new Date(2000, 1, 15, 0, 0, 0); 
 var foo = "foo "+d;   
@@ -670,7 +687,7 @@
 #endif
 
 #if OUTPUT_VERSION == 5
-totals(285);
+totals(292);
 #else
-totals (327);
+totals (334);
 #endif

=== modified file 'testsuite/actionscript.all/Math.as'
--- a/testsuite/actionscript.all/Math.as        2008-04-15 06:51:19 +0000
+++ b/testsuite/actionscript.all/Math.as        2009-01-09 08:37:20 +0000
@@ -468,7 +468,7 @@
 // Test Math.max
 //-----------------------------------------------------------------
 
-xcheck_equals (Math.max().toString(), "-Infinity");  // Heaven knows why!
+check_equals (Math.max().toString(), "-Infinity");  // Heaven knows why!
 check_equals (Math.max(1).toString(), "NaN");
 check_equals (Math.max(1,2), 2);
 check_equals (Math.max(2,1), 2);
@@ -489,7 +489,7 @@
 // Test Math.min
 //-----------------------------------------------------------------
 
-xcheck_equals (Math.min().toString(), "Infinity");  // Heaven knows why!
+check_equals (Math.min().toString(), "Infinity");  // Heaven knows why!
 check_equals (Math.min(1).toString(), "NaN");
 check_equals (Math.min(1,2), 1);
 check_equals (Math.min(2,1), 1);
@@ -513,7 +513,7 @@
 
 check_equals (Math.pow().toString(), "NaN");
 check_equals (Math.pow(0).toString(), "NaN");
-xcheck_equals (Math.pow(1), 1);                        // !!
+check_equals (Math.pow(1), 1);                 // !!
 check_equals (Math.pow(2).toString(), "NaN");
 check_equals (Math.pow(plusinf).toString(), "NaN");
 check_equals (Math.pow(minusinf).toString(), "NaN");

=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING  2009-01-09 12:55:01 +0000
+++ b/testsuite/swfdec/PASSING  2009-01-09 13:50:44 +0000
@@ -146,6 +146,10 @@
 clonesprite-depths-6.swf:6f33073bf356c451df4934aa95e49646
 clonesprite-depths-7.swf:c70968c65e52392d9c61470d0d698394
 clonesprite-depths-8.swf:af472e7f31b31e886ca86430fb71106f
+clonesprite-events-5.swf:b74aa4aef7a138d4db304f5ebfac7b84
+clonesprite-events-6.swf:b1eaf9b89c10cd08ca77d1ca8aa55b80
+clonesprite-events-7.swf:d8392b091bb1c4dfc2110732492346d2
+clonesprite-events-8.swf:5dd5d80a8e9c91d193ffdde63fa281a3
 color1.swf:3cc52a41193d342cfdfaeffe56edc3db
 color-getters.swf:4cee4418f75171e7bf423759a468b36b
 color-matrix-filter-properties-5.swf:2349ffbd77298b0dea59d6ed618c382b
@@ -347,6 +351,10 @@
 double.swf:8b18d5d6a4168afe60c583c27e704b7d
 drop-shadow-filter-properties-5.swf:68ec26c24ecb04174a484d810dab523f
 drop-shadow-filter-properties-5.swf:827a880fc55b1afb96515f0d64a064b6
+duplicateMovieClip-events-5.swf:503662305ff666f692c310f307947134
+duplicateMovieClip-events-6.swf:2f262bee780053fc72e8a8440bb38d6e
+duplicateMovieClip-events-7.swf:69aee6d163d81eb06dc13f1c4c527c3a
+duplicateMovieClip-events-8.swf:3f0ef8ba4bb8f65ac6bda38b280626bf
 duplicate-names-5.swf:d73096f662cf35b34c15e3f59fb88258
 duplicate-names-6.swf:2f1c48973f13cb831bca9a4b7bbccde0
 duplicate-names-7.swf:4bb8cb852ea9688c3964d8b5e2d3cf80
@@ -551,6 +559,10 @@
 math-constants-5.swf:ca9d0fc66667d7c7863e699367176573
 math-constants-6.swf:cc4a6b92d473f57cb5479c97ba77c2e0
 math-constants-7.swf:53df046dd67c331c79c0c939215ac770
+math-function-valueOf-5.swf:2acbb856f065de5fb649c10e7f2dccc6
+math-function-valueOf-6.swf:1ca49a394181b4645a033e90b231e8be
+math-function-valueOf-7.swf:f8229fa4a2409b13dfba252d00773a74
+math-function-valueOf-8.swf:a460031e38bf76f310846f670677eaff
 matrix-construct-5.swf:bfc2176f4495b5f7465afd1a6f489ead
 matrix-properties-5.swf:a80d726dfde5b460add76a7532e7ee01
 matrix-properties-6.swf:a7934cc5476219b199a40c4feb627dfe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]