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: Fri, 16 Mar 2007 10:12:58 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/03/16 10:12:58

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

Log message:
                * server/as_value.{cpp,h}: deprecate operator+=, implement 
valueOf
                  calling.
                * server/vm/ASHandlers.cpp (ActionNewAdd): pass environment over
                  calls to as_value::to_number, for properly calling valueOf.
                * testsuite/actionscript.all/Number.as: more tests for valueOf

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2608&r2=1.2609
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.h?cvsroot=gnash&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.61&r2=1.62
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Number.as?cvsroot=gnash&r1=1.12&r2=1.13

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2608
retrieving revision 1.2609
diff -u -b -r1.2608 -r1.2609
--- ChangeLog   16 Mar 2007 08:23:19 -0000      1.2608
+++ ChangeLog   16 Mar 2007 10:12:57 -0000      1.2609
@@ -1,5 +1,11 @@
 2007-03-16 Sandro Santilli <address@hidden>
 
+
+       * server/as_value.{cpp,h}: deprecate operator+=, implement valueOf
+         calling.
+       * server/vm/ASHandlers.cpp (ActionNewAdd): pass environment over
+         calls to as_value::to_number, for properly calling valueOf.
+       * testsuite/actionscript.all/Number.as: more tests for valueOf
        * testsuite/misc-ming.all/: .cvsignore, Makefile.am:
          Automate run of the new testcases.
 

Index: server/as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- server/as_value.cpp 15 Mar 2007 22:39:53 -0000      1.25
+++ server/as_value.cpp 16 Mar 2007 10:12:58 -0000      1.26
@@ -45,7 +45,7 @@
 #ifndef NAN
 //     If this makes your compiler die with div by zero,
 //     use "static double zzzero = 0.0;" and "(zzzero/zzzero)"
-#      define NAN (0.0/0.0)
+#      define NAN std::numeric_limits<double>::quiet_NaN();
 #endif
 
 //
@@ -172,7 +172,7 @@
                        // text representation for that object is used
                        // instead.
                        //
-                       as_object* obj = to_object();
+                       as_object* obj = m_type == OBJECT ? m_object_value : 
m_as_function_value;
                        bool gotValidToStringResult = false;
                        if ( env )
                        {
@@ -270,11 +270,13 @@
 as_value::to_number(as_environment* env) const
 {
     // TODO:  split in to_number_# (version based)
-    // TODO:  call valueOf when needed  (this is why we take an 
as_environment!)
 
     int swfversion = VM::get().getSWFVersion();
 
-    if (m_type == STRING) {
+       switch (m_type)
+       {
+               case STRING:
+               {
        // @@ Moock says the rule here is: if the
        // string is a valid float literal, then it
        // gets converted; otherwise it is set to NaN.
@@ -289,36 +291,74 @@
                m_number_value = NAN;
        }
        return m_number_value;
-    } else if (m_type == NULLTYPE || m_type == UNDEFINED) {
+               }
+
+               case NULLTYPE:
+               case UNDEFINED:
        // Evan: from my tests
        // Martin: I tried var foo = new Number(null) and got NaN
        if ( swfversion >= 7 ) return std::numeric_limits<double>::quiet_NaN();
        else return 0;
-    } else if (m_type == BOOLEAN) {
+
+               case BOOLEAN:
        // Evan: from my tests
        // Martin: confirmed
        return (this->m_boolean_value) ? 1 : 0;
-    } else if (m_type == NUMBER) {
+
+               case NUMBER:
        return m_number_value;
-    } else if (m_type == OBJECT && m_object_value != NULL) {
+
+               case OBJECT:
+               case AS_FUNCTION:
+               {
        // @@ Moock says the result here should be
        // "the return value of the object's valueOf()
        // method".
        //
        // Arrays and Movieclips should return NaN.
        
-       // Text characters with var names could get in
-       // here.
-       const char* textval = m_object_value->get_text_value();
-       if (textval) {
-           return atof(textval);
+                       //log_msg("OBJECT to number conversion, env is %p", 
env);
+
+                       as_object* obj = m_type == OBJECT ? m_object_value : 
m_as_function_value;
+                       bool gotValidValueOfResult = false;
+                       if ( env )
+                       {
+                               std::string methodname = "valueOf";
+                               lowercase_if_needed(methodname);
+                               as_value method;
+                               if ( obj->get_member(methodname, &method) )
+                               {
+                                       as_value ret = call_method0(method, 
env, obj);
+                                       if ( ret.is_number() )
+                                       {
+                                               gotValidValueOfResult=true;
+                                               return ret.m_number_value;
+                                       }
+                                       else
+                                       {
+                                               log_msg("call_method0(%s) did 
not return a number", methodname.c_str());
+                                       }
+                               }
+                               else
+                               {
+                                       log_msg("get_member(%s) returned 
false", methodname.c_str());
+                               }
+                       }
+                       if ( ! gotValidValueOfResult )
+                       {
+                               return obj->get_numeric_value(); 
+                       }
        }
        
-       return 0.0;
-    } else {
+               case MOVIECLIP:
+                       // This is tested, no valueOf is going
+                       // to be invoked for movieclips.
+                       return NAN; 
+
+               default:
        // Other object types should return NaN, but if we implement that,
        // every GUI's movie canvas shrinks to size 0x0. No idea why.
-       return 0.0;
+                       return NAN; // 0.0;
     }
 }
 

Index: server/as_value.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- server/as_value.h   15 Mar 2007 22:39:53 -0000      1.30
+++ server/as_value.h   16 Mar 2007 10:12:58 -0000      1.31
@@ -14,7 +14,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.30 2007/03/15 22:39:53 strk Exp $ */
+/* $Id: as_value.h,v 1.31 2007/03/16 10:12:58 strk Exp $ */
 
 #ifndef GNASH_AS_VALUE_H
 #define GNASH_AS_VALUE_H
@@ -536,7 +536,10 @@
 
        bool    operator!=(const as_value& v) const;
        bool    operator<(const as_value& v) const { return to_number() < 
v.to_number(); }
+
+       /// @deprecated, use v.set_double(v.to_number(env) + v.to_number(env)) 
instead !
        void    operator+=(const as_value& v) { set_double(to_number() + 
v.to_number()); }
+
        void    operator-=(const as_value& v) { set_double(to_number() - 
v.to_number()); }
        void    operator*=(const as_value& v) { set_double(to_number() * 
v.to_number()); }
        void    operator/=(const as_value& v) { set_double(to_number() / 
v.to_number()); }  // @@ check for div/0

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -b -r1.61 -r1.62
--- server/vm/ASHandlers.cpp    15 Mar 2007 22:39:54 -0000      1.61
+++ server/vm/ASHandlers.cpp    16 Mar 2007 10:12:58 -0000      1.62
@@ -14,7 +14,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: ASHandlers.cpp,v 1.61 2007/03/15 22:39:54 strk Exp $ */
+/* $Id: ASHandlers.cpp,v 1.62 2007/03/16 10:12:58 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -822,7 +822,7 @@
     as_value& op1 = env.top(0);
     as_value& op2 = env.top(1);
 
-    env.top(1).set_bool(op1.to_number() == op2.to_number());
+    env.top(1).set_bool(op1.to_number(&env) == op2.to_number(&env));
 
     // Flash4 used 1 and 0 as return from this tag
     if ( env.get_version() < 5 ) {
@@ -2451,7 +2451,7 @@
     as_value& v1 = env.top(0);
     as_value& v2 = env.top(1);
 
-    //log_msg("ActionNewAdd(%s[%s],%s[%s]) called", v1.typeOf(), 
v1.to_string(), v2.typeOf(), v2.to_string(env));
+    //log_msg("ActionNewAdd(%s[%s],%s[%s]) called", v1.typeOf(), 
v1.to_string(), v2.typeOf(), v2.to_string());
 
 
     if (v1.is_string() || v2.is_string() )
@@ -2463,7 +2463,13 @@
     }
     else
     {
-        v2 += v1;  // modifies env.top(1) uses numeric semantic
+       // use numeric semantic
+       double v2num = v2.to_number(&env);
+       //log_msg("v2 num = %g", v2num);
+       double v1num = v1.to_number(&env);
+       //log_msg("v1 num = %g", v1num);
+
+        v2.set_double(v2num + v1num); // 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.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- testsuite/actionscript.all/Number.as        15 Mar 2007 22:39:54 -0000      
1.12
+++ testsuite/actionscript.all/Number.as        16 Mar 2007 10:12:58 -0000      
1.13
@@ -26,7 +26,7 @@
 // TODO: test with SWF target != 6 (the only one tested so far)
 //     
 
-rcsid="$Id: Number.as,v 1.12 2007/03/15 22:39:54 strk Exp $";
+rcsid="$Id: Number.as,v 1.13 2007/03/16 10:12:58 strk Exp $";
 
 #include "check.as"
 
@@ -47,6 +47,7 @@
 check_equals(typeof(n1.toString), "function");
 check_equals(typeof(n1.toString()), "string"); 
 check_equals(n1.toString(), "268");
+
 var backup = Object.prototype.toString;
 Object.prototype.toString = function() { return "fake_string"; };
 check_equals(n1.toString(), "268"); // doesn't inherit from Object
@@ -56,11 +57,22 @@
 check_equals(typeof(n1.valueOf), "function");
 check_equals(typeof(n1.valueOf()), "number");
 check_equals(n1.valueOf(), 268);
+
+#if OUTPUT_VERSION >= 6
+check(Number.prototype.hasOwnProperty('valueOf'));
+check(Object.prototype.hasOwnProperty('valueOf'));
+#endif
+
 var backup = Object.prototype.valueOf;
 Object.prototype.valueOf = function() { return "fake_value"; };
 check_equals(n1.valueOf(), 268); // doesn't inherit from Object
 Object.prototype.valueOf = backup;
 
+backup = Number.prototype.valueOf;
+Number.prototype.valueOf = function() { return "fake_value"; };
+check_equals(n1.valueOf(), "fake_value"); // does inherit from Number
+Number.prototype.valueOf = backup;
+
 // Check unary minus operator
 n1 = -n1;
 check_equals (-268 , n1);
@@ -146,11 +158,19 @@
 // Test automatic conversion to number 
 //--------------------------------------------------------
 
-xcheck(isNaN(0+this));
-xcheck(isNaN(this));
+check(isNaN(0+this));
+check(isNaN(this));
+this.valueOf = function() { return 5; };
+check(isNaN(this));
 o = new Object;
 xcheck(isNaN(o));
 xcheck(isNaN(0+o));
 o.valueOf = function() { return 3; };
-xcheck_equals(0+o, 3);
+check_equals(0+o, 3);
 check_equals(0+"string", "0string");
+
+#if OUTPUT_VERSION < 6
+check(!isNaN(2+Number));
+#else
+xcheck(isNaN(2+Number));
+#endif




reply via email to

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