gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...
Date: Sat, 25 Aug 2007 14:15:52 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/08/25 14:15:51

Modified files:
        .              : ChangeLog 
        server         : as_value.cpp as_value.h 
        server/vm      : ASHandlers.cpp 
        testsuite/actionscript.all: Number.as ops.as toString_valueOf.as 

Log message:
                * server/vm/ASHandlers.cpp (ActionNewAdd): convert operands to
                  primitive value before proceeding.
                * server/as_value.h: make to_primitive() public
                * server/as_value.cpp (to_number): if valueOf returned a string 
value
                  call to_number() again on it; (equals): if one operand is a 
string
                  and the other is a number, don't compare unless the string 
converts
                  to a non-infinite number.
                * testsuite/actionscript.all/Number.as: add test for 'string'
                  convertion to number returning NaN
                * testsuite/actionscript.all/ops.as: xcheck => check
                * testsuite/actionscript.all/toString_valueOf.as xcheck => check

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4099&r2=1.4100
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.66&r2=1.67
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.h?cvsroot=gnash&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.125&r2=1.126
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Number.as?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/ops.as?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/toString_valueOf.as?cvsroot=gnash&r1=1.5&r2=1.6

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4099
retrieving revision 1.4100
diff -u -b -r1.4099 -r1.4100
--- ChangeLog   24 Aug 2007 16:07:26 -0000      1.4099
+++ ChangeLog   25 Aug 2007 14:15:49 -0000      1.4100
@@ -1,3 +1,17 @@
+2007-08-25 Sandro Santilli <address@hidden>
+
+       * server/vm/ASHandlers.cpp (ActionNewAdd): convert operands to
+         primitive value before proceeding.
+       * server/as_value.h: make to_primitive() public
+       * server/as_value.cpp (to_number): if valueOf returned a string value
+         call to_number() again on it; (equals): if one operand is a string
+         and the other is a number, don't compare unless the string converts
+         to a non-infinite number.
+       * testsuite/actionscript.all/Number.as: add test for 'string'
+         convertion to number returning NaN
+       * testsuite/actionscript.all/ops.as: xcheck => check
+       * testsuite/actionscript.all/toString_valueOf.as xcheck => check
+
 2007-08-24 Sandro Santilli <address@hidden>
 
        * server/dlist.{h,cpp} (replace_character): call unload() on replaced

Index: server/as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- server/as_value.cpp 24 Aug 2007 16:07:27 -0000      1.66
+++ server/as_value.cpp 25 Aug 2007 14:15:50 -0000      1.67
@@ -299,6 +299,10 @@
                                        {
                                                return ret.m_number_value;
                                        }
+                                       else if ( ret.is_string() )
+                                       {
+                                               return ret.to_number();
+                                       }
                                        else
                                        {
                                                log_msg(_("[object %p].%s() did 
not return a number: %s"),
@@ -687,14 +691,18 @@
     //    return the result of the comparison x == ToNumber(y).
     else if (m_type == NUMBER && v.m_type == STRING)
     {
-        return equalsSameType(v.to_number(&env)); 
+       double n = v.to_number(&env); // no need for the env actually
+       if ( ! isfinite(n) ) return false;
+        return equalsSameType(n);
     }
 
     // 17. If Type(x) is String and Type(y) is Number,
     //     return the result of the comparison ToNumber(x) == y.
     else if (v.m_type == NUMBER && m_type == STRING)
     {
-        return v.equalsSameType(to_number(&env)); 
+       double n = to_number(&env); // no need for the env actually
+       if ( ! isfinite(n) ) return false;
+        return v.equalsSameType(n); 
     }
 
     // 18. If Type(x) is Boolean, return the result of the comparison 
ToNumber(x) == y.

Index: server/as_value.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.h,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- server/as_value.h   13 Aug 2007 02:47:58 -0000      1.63
+++ server/as_value.h   25 Aug 2007 14:15:51 -0000      1.64
@@ -15,7 +15,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-/* $Id: as_value.h,v 1.63 2007/08/13 02:47:58 strk Exp $ */
+/* $Id: as_value.h,v 1.64 2007/08/25 14:15:51 strk Exp $ */
 
 #ifndef GNASH_AS_VALUE_H
 #define GNASH_AS_VALUE_H
@@ -424,6 +424,16 @@
        /// or NULL if it is not an ActionScript function.
        as_function*    to_as_function() const;
 
+       /// Return value as a primitive type
+       //
+       /// Primitive types are: undefined, null, boolean, string, number.
+       /// See ECMA-2.6.2 (section 4.3.2).
+       ///
+       /// @param env
+       ///     The environment to use for calling the valueOf method.
+       ///
+       as_value to_primitive(as_environment& env) const;
+
        /// Force type to number.
        //
        /// @param env
@@ -573,16 +583,6 @@
        void    set_sprite(const std::string& path);
 
 
-       /// Return value as a primitive type
-       //
-       /// Primitive types are: undefined, null, boolean, string, number.
-       /// See ECMA-2.6.2 (section 4.3.2).
-       ///
-       /// @param env
-       ///     The environment to use for calling the valueOf method.
-       ///
-       as_value to_primitive(as_environment& env) const;
-
        /// Compare values of the same type
        //
        /// NOTE: will abort if values are not of the same type!

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -b -r1.125 -r1.126
--- server/vm/ASHandlers.cpp    23 Aug 2007 16:50:56 -0000      1.125
+++ server/vm/ASHandlers.cpp    25 Aug 2007 14:15:51 -0000      1.126
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: ASHandlers.cpp,v 1.125 2007/08/23 16:50:56 strk Exp $ */
+/* $Id: ASHandlers.cpp,v 1.126 2007/08/25 14:15:51 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -2765,18 +2765,21 @@
 
     thread.ensureStack(2);
 
-    as_value& v1 = env.top(0);
-    as_value& v2 = env.top(1);
+    as_value& v1_in = env.top(0);
+    as_value& v2_in = env.top(1);
 
-    //log_msg(_("ActionNewAdd(%s, %s) called"), v1.to_debug_string().c_str(), 
v2.to_debug_string().c_str());
+    as_value v1 = v1_in.to_primitive(env);
+    as_value v2 = v2_in.to_primitive(env);
+
+    //log_msg(_("ActionNewAdd(%s, %s) [prim %s, %s] called"), 
v1_in.to_debug_string().c_str(), v2_in.to_debug_string().c_str(), 
v1.to_debug_string().c_str(), v2.to_debug_string().c_str());
 
 
     if (v1.is_string() || v2.is_string() )
     {
        int version = env.get_version();
-        // modify env.top(1)
         v2.convert_to_string_versioned(version, &env);
         v2.string_concat(v1.to_string_versioned(version, &env));
+       v2_in = v2; // modify env.top(1)
     }
     else
     {
@@ -2786,7 +2789,9 @@
        double v1num = v1.to_number(&env);
        //log_msg(_("v1 num = %g"), v1num);
 
-        v2.set_double(v2num + v1num); // modify env.top(1)
+        v2.set_double(v2num + v1num); 
+
+       v2_in = v2; // modify env.top(1)
     }
     env.drop(1);
 }

Index: testsuite/actionscript.all/Number.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Number.as,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- testsuite/actionscript.all/Number.as        26 Jul 2007 03:41:19 -0000      
1.27
+++ testsuite/actionscript.all/Number.as        25 Aug 2007 14:15:51 -0000      
1.28
@@ -27,7 +27,7 @@
 // TODO: test with SWF target != 6 (the only one tested so far)
 //     
 
-rcsid="$Id: Number.as,v 1.27 2007/07/26 03:41:19 strk Exp $";
+rcsid="$Id: Number.as,v 1.28 2007/08/25 14:15:51 strk Exp $";
 
 #include "check.as"
 
@@ -346,6 +346,9 @@
 asm { push 'val','2p' tonumber setvariable };
 check(isNaN(val));
 
+asm { push 'val','string' tonumber setvariable };
+check(isNaN(val));
+
 asm { push 'val','NaN' tonumber setvariable };
 check(isNaN(val));
 

Index: testsuite/actionscript.all/ops.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/ops.as,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- testsuite/actionscript.all/ops.as   19 Aug 2007 23:34:55 -0000      1.17
+++ testsuite/actionscript.all/ops.as   25 Aug 2007 14:15:51 -0000      1.18
@@ -20,7 +20,7 @@
  *  Test binary predicates (equal, less_then, greater_then, logical and 
bitwise ops)
  */
 
-rcsid="$Id: ops.as,v 1.17 2007/08/19 23:34:55 strk Exp $";
+rcsid="$Id: ops.as,v 1.18 2007/08/25 14:15:51 strk Exp $";
 
 #include "check.as"
 
@@ -42,8 +42,12 @@
 check(! (0 == NaN) );
 check(! ('string' == 0) );
 check(! (0 == 'string') );
-xcheck(! ('string' == NaN) );
-xcheck(! (NaN == 'string') );
+check(! ('string' == NaN) );
+check(! (NaN == 'string') );
+check(! (Infinite == 'Infinite') );
+check(! ('Infinite' == Infinite) );
+check(! (-Infinite == '-Infinite') );
+check(! ('-Infinite' == -Infinite) );
 check(1==true);
 check(true==1);
 check(2!=true);
@@ -76,7 +80,7 @@
 check_equals( str3.toString(), 3.0 ); // str3 (primitive string) is 
automatically converted to a number 
 
 check( ! (str1 == 0) ); // str1 (object) is NOT converted to a number (due to 
NaN?)
-xcheck( ! (str1 == NaN) ); // str1 (object) is NOT converted to a number (due 
to NaN?)
+check( ! (str1 == NaN) ); // str1 (object) is NOT converted to a number (due 
to NaN?)
 
 #if OUTPUT_VERSION > 5
   check( ! (str1 == str2) ); // they are not the same object
@@ -102,7 +106,7 @@
 
 x=String("0.999");
 y=String("1.0");
-xcheck(x<y);
+check(x<y);
 
 x=String("A");
 y=String("a");
@@ -114,11 +118,11 @@
 
 x=0.999;
 y=String("1.000");
-xcheck(x<y);
+check(x<y);
 
 x=String("0.999");
 y=1.0;
-xcheck(x<y);
+check(x<y);
 
 check(! (NaN < NaN) );
 check(! (undefined < undefined) );
@@ -307,19 +311,19 @@
 
 x = new String("1");
 y = new String("3");
-xcheck_equals(x&y, 1); 
+check_equals(x&y, 1); 
 
 x = new String("1.0");
 y = new String("3.0");
-xcheck_equals(x&y, 1); 
+check_equals(x&y, 1); 
 
 x = new String("1.999");
 y = new String("3.999");
-xcheck_equals(x&y, 1); 
+check_equals(x&y, 1); 
 
 x = new String("3.999");
 y = 7;
-xcheck_equals(x&y, 3); 
+check_equals(x&y, 3); 
 
 x = Number("7.999");
 y = 3;
@@ -351,11 +355,11 @@
 
 x = new String("1.999");
 y = 8.999;
-xcheck_equals(x|y, 9); 
+check_equals(x|y, 9); 
 
 x = String("1.999");
 y = String("8.999");
-xcheck_equals(x|y, 9); 
+check_equals(x|y, 9); 
 
 x = 9;
 y = String("1.5");
@@ -399,15 +403,15 @@
 
 x = new String("1.999");
 y = new String("2.999");
-xcheck_equals(x^y, 3);
+check_equals(x^y, 3);
 
 x = new String("1.999");
 y = 2.999;
-xcheck_equals(x^y, 3);
+check_equals(x^y, 3);
 
 x = 1.999;
 y = new String("2.999");
-xcheck_equals(x^y, 3);
+check_equals(x^y, 3);
 
 
 //------------------------------------------------
@@ -463,11 +467,11 @@
 
 x = String("3");
 y = x << 1;
-xcheck_equals(y, 6);
+check_equals(y, 6);
 
 x = new String("3");
 y = x << 1;
-xcheck_equals(y, 6); 
+check_equals(y, 6); 
 
 //------------------------------------------------
 // Shift right operator (ACTION_SHIFTRIGHT : 0x64)
@@ -503,11 +507,11 @@
 
 x = String("7");
 y = x >> 1;
-xcheck_equals(y, 3);
+check_equals(y, 3);
 
 x = new String("7");
 y = x >> 1;
-xcheck_equals(y, 3);
+check_equals(y, 3);
 
 //-------------------------------------------------
 // Shift right2 operator (ACTION_SHIFTRIGHT2 : 0x65)
@@ -537,12 +541,12 @@
 x = new String("1.9");
 y = --x;
 //xcheck_equals(y, 0.9);
-xcheck( (y-0.9) < 0.001 );
+check( (y-0.9) < 0.001 );
 
 x = new String("0.0");
 y = --x;
 //xcheck_equals(y, -1.0);
-xcheck( (y+1.0) < 0.001 );
+check( (y+1.0) < 0.001 );
 
 x = new String("a");
 y = --x;
@@ -564,11 +568,11 @@
 x = new String("1.9");
 y = ++x;
 //xcheck_equals(y, 2.9);
-xcheck( (y-2.9) < 0.001 );
+check( (y-2.9) < 0.001 );
 
 x = new String("0.0");
 y = ++x;
-xcheck_equals(y, 1);
+check_equals(y, 1);
 
 x = new String("a");
 y = ++x;

Index: testsuite/actionscript.all/toString_valueOf.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/toString_valueOf.as,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- testsuite/actionscript.all/toString_valueOf.as      16 Aug 2007 06:09:14 
-0000      1.5
+++ testsuite/actionscript.all/toString_valueOf.as      25 Aug 2007 14:15:51 
-0000      1.6
@@ -99,7 +99,7 @@
 num2 = new Number(2);
 num3 = num1 + num2;
 //valueOf called;
-check(num3 == "TO_VALUETO_VALUE");
+check_equals(num3, "TO_VALUETO_VALUE");
 
 x = num1.toString();
 y = num1.valueOf();
@@ -138,8 +138,8 @@
 
 str2 = new String("2");
 str3 = str1+str2;
-xcheck(str3 == "102"); 
-xcheck(str3 == 102); 
+check(str3 == "102"); 
+check(str3 == 102); 
 
 String.prototype.toString = function () {return "TO_STRING";};
 String.prototype.valueOf = function () {return "TO_VALUE";};
@@ -147,9 +147,9 @@
 xcheck(parseInt(str1) == 10); 
 xcheck(parseInt(str2) == 2);  
 str3 =  str1 + str2;
-xcheck(typeof(str3) == "string");
+check(typeof(str3) == "string");
 //valueOf called
-check(str3 == "TO_VALUETO_VALUE"); 
+check_equals(str3, "TO_VALUETO_VALUE"); 
 // trace a string Object won't invoke the toString method.
 // I don't think it's a bug.
 //trace(str1); //output 10 !
@@ -313,7 +313,7 @@
 b2 = new Boolean(true);
 b3 = b1 + b2;
 check(typeof(b3) == 'number');
-xcheck(b3 == 1);
+check_equals(b3, 1);
 
 
 //




reply via email to

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