[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/as_object.cpp server/as_...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/as_object.cpp server/as_... |
Date: |
Wed, 25 Oct 2006 08:59:28 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/10/25 08:59:28
Modified files:
. : ChangeLog
server : as_object.cpp as_object.h sprite_instance.cpp
server/swf : ASHandlers.cpp
Log message:
* server/as_object.{h,cpp}: added enumProperties() and
copyProperties() public methods, m_members member made
private (toward getter/setter properties).
* server/sprite_instance.cpp (sprite_duplicate_movieclip):
use the as_object::copyProperties() to avoid direct access
to object members (lacks a testcase for validation)
* server/swf/ASHandlers.cpp (enumerateOjbect): call the
as_object::enumerateProperties() to avoid direct access
to object members (validated with existing testcase);
dropped the not-more-needed enumerateObjectRecursive
function (the one provided by as_object uses a stack
rather then recurs, btw).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1388&r2=1.1389
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.cpp?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.cpp?cvsroot=gnash&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/ASHandlers.cpp?cvsroot=gnash&r1=1.83&r2=1.84
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1388
retrieving revision 1.1389
diff -u -b -r1.1388 -r1.1389
--- ChangeLog 24 Oct 2006 21:36:19 -0000 1.1388
+++ ChangeLog 25 Oct 2006 08:59:28 -0000 1.1389
@@ -1,3 +1,18 @@
+2006-10-25 Sandro Santilli <address@hidden>
+
+ * server/as_object.{h,cpp}: added enumProperties() and
+ copyProperties() public methods, m_members member made
+ private (toward getter/setter properties).
+ * server/sprite_instance.cpp (sprite_duplicate_movieclip):
+ use the as_object::copyProperties() to avoid direct access
+ to object members (lacks a testcase for validation)
+ * server/swf/ASHandlers.cpp (enumerateOjbect): call the
+ as_object::enumerateProperties() to avoid direct access
+ to object members (validated with existing testcase);
+ dropped the not-more-needed enumerateObjectRecursive
+ function (the one provided by as_object uses a stack
+ rather then recurs, btw).
+
2006-10-24 Sandro Santilli <address@hidden>
* server/asobj/Object.cpp: hide Object.addProperty member.
Index: server/as_object.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- server/as_object.cpp 5 Oct 2006 16:05:02 -0000 1.11
+++ server/as_object.cpp 25 Oct 2006 08:59:28 -0000 1.12
@@ -44,6 +44,9 @@
#include "as_object.h"
#include "as_function.h"
+#include "as_environment.h" // for enumerateProperties
+
+#include <set>
namespace gnash {
@@ -314,5 +317,60 @@
}
}
+void
+as_object::copyProperties(const as_object& o)
+{
+ typedef stringi_hash<as_member>::const_iterator members_iterator;
+ for (members_iterator it = o.m_members.begin(),
+ itEnd = o.m_members.end();
+ it != itEnd;
+ ++it )
+ {
+ const tu_stringi name = it->first;
+ const as_member member = it->second;
+ // TODO: don't call get_member_value, we
+ // must copy also 'getset' members ...
+ set_member(name, member.get_member_value());
+ }
+}
+
+void
+as_object::enumerateProperties(as_environment& env) const
+{
+ assert( env.top(0).get_type() == as_value::NULLTYPE );
+
+
+ // this set will keep track of visited objects,
+ // to avoid infinite loops
+ std::set<const as_object*> visited;
+
+ typedef stringi_hash<as_member>::const_iterator members_iterator;
+
+ const as_object* obj = this;
+ while ( obj && visited.insert(obj).second )
+ {
+ for ( members_iterator
+ it=obj->m_members.begin(), itEnd=obj->m_members.end();
+ it!=itEnd;
+ ++it )
+ {
+ const as_member& member = it->second;
+
+ if (! member.get_member_flags().get_dont_enum())
+ {
+ // shouldn't this be a tu_string instead ?
+ // we need to support UTF8 too I guess
+ const char* val = it->first.c_str();
+
+ env.push(as_value(val));
+ }
+ }
+
+ obj = obj->m_prototype;
+ }
+
+ if ( obj ) log_warning("prototype loop during Enumeration");
+}
+
} // end of gnash namespace
Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- server/as_object.h 23 Oct 2006 10:32:08 -0000 1.11
+++ server/as_object.h 25 Oct 2006 08:59:28 -0000 1.12
@@ -46,7 +46,6 @@
#include <cmath>
#include "container.h"
-//#include "resource.h" // for inheritance
#include "ref_counted.h" // for inheritance
#include "as_member.h"
@@ -56,6 +55,7 @@
class as_function;
class movie;
class as_value;
+class as_environment;
/// \brief
/// A generic bag of attributes. Base class for all ActionScript-able objects.
@@ -66,15 +66,22 @@
//class as_object : public resource
class DSOEXPORT as_object : public ref_counted
{
-
-public:
-
/// Members of this objects in an hash
//
/// TODO: make this private or protected and provide
/// visitor pattern interface
+ ///
+ /// TODO: change this to a <boost/ptr_container/ptr_map.hpp>
+ /// so we can store as_member by pointer allowing polymorphism
+ /// of it (planning to add a getset_as_member) w/out much
+ /// overhead and with manager ownerhips. See:
+ /// http://www.boost.org/libs/ptr_container/doc/ptr_container.html
+ ///
stringi_hash<as_member> m_members;
+
+public:
+
void dump_members() const;
/// Reference to this object's '__proto__'
@@ -153,6 +160,20 @@
///
void setPropFlags(as_value& props, int set_false, int set_true);
+ /// Copy properties from the given object
+ void copyProperties(const as_object& o);
+
+ /// \brief
+ /// Enumerate all non-hidden properties pushing
+ /// their value to the given as_environment.
+ //
+ /// The enumeration recurse in prototype.
+ /// This implementation will keep track of visited object
+ /// to avoid loops in prototype chain.
+ /// NOTE: the MM player just chokes in this case (loop)
+ ///
+ void enumerateProperties(as_environment& env) const;
+
protected:
/// Get a member as_value by name
Index: server/sprite_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.cpp,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- server/sprite_instance.cpp 18 Oct 2006 18:16:01 -0000 1.67
+++ server/sprite_instance.cpp 25 Oct 2006 08:59:28 -0000 1.68
@@ -284,16 +284,7 @@
if (fn.nargs == 3 && ch)
{
as_object* initObject = fn.arg(2).to_object();
- typedef stringi_hash<as_member>::const_iterator
members_iterator;
- for (members_iterator it =
initObject->m_members.begin(),
- itEnd =
initObject->m_members.end();
- it != itEnd;
- ++it )
- {
- const tu_stringi name = it->first;
- const as_member member = it->second;
- ch->set_member(name, member.get_member_value());
- }
+ if ( initObject ) ch->copyProperties(*initObject);
}
}
Index: server/swf/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/ASHandlers.cpp,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -b -r1.83 -r1.84
--- server/swf/ASHandlers.cpp 24 Oct 2006 15:20:52 -0000 1.83
+++ server/swf/ASHandlers.cpp 25 Oct 2006 08:59:28 -0000 1.84
@@ -34,7 +34,7 @@
// forward this exception.
//
-/* $Id: ASHandlers.cpp,v 1.83 2006/10/24 15:20:52 strk Exp $ */
+/* $Id: ASHandlers.cpp,v 1.84 2006/10/25 08:59:28 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -2204,49 +2204,6 @@
dbglogfile << __PRETTY_FUNCTION__ << ": unimplemented!" << endl;
}
-/// Recursive enumerator. Will keep track of visited object
-/// to avoid loops in prototype chain.
-/// NOTE: the MM player just chokes in this case.
-/// TODO: avoid recursion and use a visited stack
-static void
-enumerateObjectRecursive(as_environment& env, const as_object& obj,
- std::set<const as_object*>& visited)
-{
- if ( ! visited.insert(&obj).second )
- {
- log_warning("prototype loop during Enumeration");
- return;
- }
-
- typedef stringi_hash<as_member>::const_iterator members_iterator;
- for ( members_iterator
- it=obj.m_members.begin(), itEnd=obj.m_members.end();
- it!=itEnd;
- ++it )
- {
- const as_member member = it->second;
-
- if (! member.get_member_flags().get_dont_enum())
- {
- // shouldn't this be a tu_string instead ?
- // we need to support UTF8 too I guess
- const char* val = it->first.c_str();
-
- env.push(as_value(val));
- IF_VERBOSE_ACTION (
- log_action("---enumerate - push: %s", val);
- );
- }
- }
-
- const as_object *prototype = obj.m_prototype;
- if ( prototype )
- {
- enumerateObjectRecursive(env, *prototype, visited);
- }
-
-}
-
// Push a each object's member value on the stack
// This is an utility function for use by ActionEnumerate
// and ActionEnum2. The caller is expected to have
@@ -2256,10 +2213,7 @@
{
assert( env.top(0).get_type() == as_value::NULLTYPE );
- std::set<const as_object*> visited;
-
- enumerateObjectRecursive(env, obj, visited);
-
+ obj.enumerateProperties(env);
}
void