[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash server/PropertyList.cpp server/PropertyLi...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash server/PropertyList.cpp server/PropertyLi... |
Date: |
Sun, 25 Feb 2007 16:38:12 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/02/25 16:38:12
Modified files:
server : PropertyList.cpp PropertyList.h as_object.cpp
as_object.h
testsuite/server: PropertyListTest.cpp
Log message:
* server/PropertyList.{cpp,h}: add
enumerateKeyValue() method; renamed
enumerateValues to enumerateKeys (makes more sense).
* server/as_object.{cpp,h}:
add enumerateProperty() overloaded function to
write properties to a std::map
* testsuite/server/PropertyListTest.cpp: add
test for enumerateKeyValue().
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/PropertyList.cpp?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/server/PropertyList.h?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.cpp?cvsroot=gnash&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/PropertyListTest.cpp?cvsroot=gnash&r1=1.10&r2=1.11
Patches:
Index: server/PropertyList.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/PropertyList.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- server/PropertyList.cpp 5 Feb 2007 11:49:24 -0000 1.9
+++ server/PropertyList.cpp 25 Feb 2007 16:38:12 -0000 1.10
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#include "log.h"
#include "as_function.h"
-#include "as_environment.h" // for enumerateValues
+#include "as_environment.h" // for enumerateKeys
#include "as_value.h" // for enumerateValues
#include <utility> // for std::make_pair
@@ -175,7 +175,7 @@
}
void
-PropertyList::enumerateValues(as_environment& env) const
+PropertyList::enumerateKeys(as_environment& env) const
{
for ( const_iterator i=begin(), ie=end(); i != ie; ++i)
{
@@ -188,6 +188,20 @@
}
void
+PropertyList::enumerateKeyValue(as_object& this_ptr, std::map<std::string,
std::string>& to)
+{
+ for ( const_iterator i=begin(), ie=end(); i != ie; ++i)
+ {
+ const Property* prop = i->second;
+
+ if ( prop->getFlags().get_dont_enum() ) continue;
+
+ to.insert(make_pair(i->first,
+ prop->getValue(this_ptr).to_string()));
+ }
+}
+
+void
PropertyList::dump(as_object& this_ptr)
{
for ( const_iterator it=begin(), itEnd=end(); it != itEnd; ++it )
Index: server/PropertyList.h
===================================================================
RCS file: /sources/gnash/gnash/server/PropertyList.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/PropertyList.h 9 Feb 2007 05:52:49 -0000 1.12
+++ server/PropertyList.h 25 Feb 2007 16:38:12 -0000 1.13
@@ -308,8 +308,26 @@
/// \brief
/// Enumerate all non-hidden properties pushing
- /// their value to the given as_environment.
- void enumerateValues(as_environment& env) const;
+ /// their keys to the given as_environment.
+ void enumerateKeys(as_environment& env) const;
+
+ /// \brief
+ /// Enumerate all non-hidden properties inserting
+ /// their name/value pair to the given map
+ ///
+ /// @param this_ptr
+ /// The as_object used to set the 'this' pointer
+ /// for calling getter/setter function (GetterSetterProperty);
+ /// it will be unused when getting or setting SimpleProperty
+ /// properties.
+ /// This parameter is non-const as nothing prevents an
+ /// eventual "Getter" function from actually modifying it,
+ /// so we can't promise constness.
+ /// Note that the PropertyList itself might be changed
+ /// from this call, accessed trough the 'this' pointer,
+ /// so this method too is non-const (this is crazy, should cut it
out)
+ ///
+ void enumerateKeyValue(as_object& this_ptr, std::map<std::string,
std::string>& to);
/// Remove all entries in the container
void clear();
Index: server/as_object.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- server/as_object.cpp 9 Feb 2007 05:52:49 -0000 1.36
+++ server/as_object.cpp 25 Feb 2007 16:38:12 -0000 1.37
@@ -429,7 +429,7 @@
const as_object* obj = this;
while ( obj && visited.insert(obj).second )
{
- obj->_members.enumerateValues(env);
+ obj->_members.enumerateKeys(env);
obj = obj->get_prototype();
}
@@ -438,6 +438,23 @@
//if ( obj ) log_warning("prototype loop during Enumeration");
}
+void
+as_object::enumerateProperties(std::map<std::string, std::string>& to)
+{
+
+ // this set will keep track of visited objects,
+ // to avoid infinite loops
+ std::set<const as_object*> visited;
+
+ as_object* obj = this;
+ while ( obj && visited.insert(obj).second )
+ {
+ obj->_members.enumerateKeyValue(*obj, to);
+ obj = obj->get_prototype();
+ }
+
+}
+
as_object::as_object()
:
_members(),
Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- server/as_object.h 9 Feb 2007 05:52:49 -0000 1.38
+++ server/as_object.h 25 Feb 2007 16:38:12 -0000 1.39
@@ -301,6 +301,17 @@
void enumerateProperties(as_environment& env) const;
/// \brief
+ /// Enumerate all non-hidden properties inserting
+ /// their name/value pair to the given map.
+ //
+ /// 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(std::map<std::string, std::string>& to);
+
+ /// \brief
/// Add a getter/setter property, if no member already has
/// that name (or should we allow override ? TODO: check this)
//
Index: testsuite/server/PropertyListTest.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/server/PropertyListTest.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- testsuite/server/PropertyListTest.cpp 10 Dec 2006 18:39:22 -0000
1.10
+++ testsuite/server/PropertyListTest.cpp 25 Feb 2007 16:38:12 -0000
1.11
@@ -105,5 +105,12 @@
check_equals(delpair.second, false); // property was NOT deleted
check_equals(props.size(), 4);
+ std::map<std::string, std::string> vals;
+ props.enumerateKeyValue(obj, vals);
+ check_equals( vals.size(), 4 );
+ check_equals( vals["var0"], "value3" );
+ check_equals( vals["Var0"], "value2" );
+ check_equals( vals["var1"], "value" );
+
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash server/PropertyList.cpp server/PropertyLi...,
Sandro Santilli <=