gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/as_object.h server/asobj...


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog server/as_object.h server/asobj...
Date: Tue, 20 Mar 2007 09:45:28 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     07/03/20 09:45:28

Modified files:
        .              : ChangeLog 
        server         : as_object.h 
        server/asobj   : Boolean.cpp 

Log message:
                * server/as_object.h: Add ensureType<classname>, which is 
intended to
                replace the class-specific ensureClass functions. Suggested by 
Ann.
                * server/asobj/Boolean.cpp: Switch ensureClass to ensureType.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2633&r2=1.2634
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Boolean.cpp?cvsroot=gnash&r1=1.8&r2=1.9

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2633
retrieving revision 1.2634
diff -u -b -r1.2633 -r1.2634
--- ChangeLog   20 Mar 2007 09:19:32 -0000      1.2633
+++ ChangeLog   20 Mar 2007 09:45:28 -0000      1.2634
@@ -1,3 +1,9 @@
+2007-03-20 Bastiaan Jacques <address@hidden>
+
+       * server/as_object.h: Add ensureType<classname>, which is intended to
+       replace the class-specific ensureClass functions. Suggested by Ann.
+       * server/asobj/Boolean.cpp: Switch ensureClass to ensureType.
+
 2007-03-19 Sandro Santilli <address@hidden>
 
        * server/as_value.{cpp,h}: simplify union by using

Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- server/as_object.h  19 Mar 2007 17:45:10 -0000      1.45
+++ server/as_object.h  20 Mar 2007 09:45:28 -0000      1.46
@@ -29,6 +29,8 @@
 #include "as_value.h" // for return of get_primitive_value
 #include "smart_ptr.h"
 #include "as_prop_flags.h" // for enum
+#include "GnashException.h"
+#include <sstream>
 
 #include <cmath>
 #include <utility> // for std::pair
@@ -455,6 +457,32 @@
 
 };
 
+/// Template which does a dynamic cast for as_object pointers. It throws an
+/// error if the dynamic cast fails.
+/// @param T the class to which the obj pointer should be cast.
+/// @param obj the pointer to be cast.
+/// @return If the cast succeeds, the pointer cast to the requested type.
+///         Otherwise, NULL.
+template <typename T>
+T*
+ensureType (as_object* obj)
+{
+       T* ret = dynamic_cast<T*>(obj);
+
+       // This path is fairly unlikely, so it's a potential  __builtin_expect.
+       if (!ret) {
+               std::ostringstream stream;
+               stream  << "builtin method or gettersetter for " 
+                       << typeid(T).name() << " called from "
+                       << typeid(obj).name() << " instance.";
+
+               throw ActionException(stream.str());
+        }
+        return ret;
+}
+
+
+
 } // namespace gnash
 
 #endif // GNASH_AS_OBJECT_H

Index: server/asobj/Boolean.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Boolean.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- server/asobj/Boolean.cpp    19 Mar 2007 17:11:14 -0000      1.8
+++ server/asobj/Boolean.cpp    20 Mar 2007 09:45:28 -0000      1.9
@@ -80,25 +80,14 @@
        
 };
 
-static boolean_as_object *
-ensureBoolean(as_object* obj)
-{
-        boolean_as_object* ret = dynamic_cast<boolean_as_object*>(obj);
-        if ( ! ret )
-        {
-                throw ActionException("builtin method or gettersetter for " \
-                                     " Boolean objects called against " \
-                                     " non-Boolean instance");
-        }
-        return ret;
-}
-
-as_value boolean_tostring(const fn_call& fn) {
 
+as_value boolean_tostring(const fn_call& fn)
+{
        static char* strtrue = "true";
        static char* strfalse = "false";
 
-       boolean_as_object* boolobj = ensureBoolean(fn.this_ptr);
+       boolean_as_object* boolobj = ensureType<boolean_as_object>(fn.this_ptr);
+
        
        if (boolobj->val) 
                return as_value(strtrue);
@@ -106,8 +95,10 @@
                return as_value(strfalse);
 }
 
-as_value boolean_valueof(const fn_call& fn) {
-    boolean_as_object* boolobj = ensureBoolean(fn.this_ptr);
+
+as_value boolean_valueof(const fn_call& fn) 
+{
+       boolean_as_object* boolobj = ensureType<boolean_as_object>(fn.this_ptr);
     
     return as_value(boolobj->val);
 }




reply via email to

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