gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10105: Enumerate in creation order,


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10105: Enumerate in creation order, not lexicographically. Don't use a map to
Date: Sat, 25 Oct 2008 20:51:18 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10105
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2008-10-25 20:51:18 +0200
message:
  Enumerate in creation order, not lexicographically. Don't use a map to
  enumerate into, as that will sort it again. Use SortedPropertyList, which
  does not change the order of enumeration.
  
  Implement LoadVars.toString(), which relies on this order.
  
  Gets passes in actionscript.all/enumerate.as and actionscript.all/LoadVars.as.
modified:
  libcore/PropertyList.cpp
  libcore/PropertyList.h
  libcore/as_object.cpp
  libcore/as_object.h
  libcore/asobj/LoadVars_as.cpp
  testsuite/actionscript.all/LoadVars.as
  testsuite/actionscript.all/enumerate.as
  testsuite/libcore.all/PropertyListTest.cpp
=== modified file 'libcore/PropertyList.cpp'
--- a/libcore/PropertyList.cpp  2008-09-24 10:32:01 +0000
+++ b/libcore/PropertyList.cpp  2008-10-25 18:51:18 +0000
@@ -305,7 +305,12 @@
 PropertyList::enumerateKeys(as_environment& env, propNameSet& donelist) const
 {
        string_table& st = env.getVM().getStringTable();
-       for (container::const_iterator i=_props.begin(), ie=_props.end(); i != 
ie; ++i)
+
+    // We should enumerate in order of creation, not lexicographically.
+    typedef container::nth_index<1>::type ContainerByOrder;
+
+       for (ContainerByOrder::const_reverse_iterator 
i=_props.get<1>().rbegin(),
+            ie=_props.get<1>().rend(); i != ie; ++i)
        {
                if (i->getFlags().get_dont_enum())
                        continue;
@@ -321,26 +326,38 @@
 }
 
 void
-PropertyList::enumerateKeyValue(const as_object& this_ptr, 
std::map<std::string, std::string>& to) const
+PropertyList::enumerateKeyValue(const as_object& this_ptr,
+        SortedPropertyList& to) const
 {
-       string_table& st = this_ptr.getVM().getStringTable();
-       for (container::const_iterator i=_props.begin(), ie=_props.end(); i != 
ie; ++i)
+    VM& vm = this_ptr.getVM();
+       string_table& st = vm.getStringTable();
+    typedef container::nth_index<1>::type ContainerByOrder;
+
+       for (ContainerByOrder::const_iterator i=_props.get<1>().begin(),
+            ie=_props.get<1>().end(); i != ie; ++i)
        {
-               if (i->getFlags().get_dont_enum())
-                       continue;
+               if (i->getFlags().get_dont_enum()) continue;
 
-               to.insert(make_pair(st.value(i->mName),
-                               i->getValue(this_ptr).to_string()));
+        // Undefined values should be "undefined" for SWF7 and
+        // empty for SWF6.
+        const int version = vm.getSWFVersion();
+               to.push_back(std::make_pair(st.value(i->mName),
+                               
i->getValue(this_ptr).to_string_versioned(version)));
        }
 }
 
+/// This does not reflect the normal enumeration order. It is sorted
+/// lexicographically by property.
 void
 PropertyList::dump(as_object& this_ptr, std::map<std::string, as_value>& to) 
 {
        string_table& st = VM::get().getStringTable();
-       for (container::const_iterator i=_props.begin(), ie=_props.end(); i != 
ie; ++i)
+
+       for (container::const_iterator i=_props.begin(), ie=_props.end();
+            i != ie; ++i)
        {
-               to.insert(make_pair(st.value(i->mName), i->getValue(this_ptr)));
+               to.insert(std::make_pair(st.value(i->mName),
+                    i->getValue(this_ptr)));
        }
 }
 

=== modified file 'libcore/PropertyList.h'
--- a/libcore/PropertyList.h    2008-09-24 10:32:01 +0000
+++ b/libcore/PropertyList.h    2008-10-25 18:51:18 +0000
@@ -53,7 +53,12 @@
 class PropertyList
 {
 public:
-       /// A tag type for multi-index
+
+    typedef std::pair<std::string, std::string> KeyValuePair;
+    typedef std::vector<KeyValuePair> SortedPropertyList;
+    
+
+    /// A tag type for multi-index
        struct oType {/**/};
 
        /// The actual container
@@ -461,14 +466,14 @@
 
        /// \brief
        /// Enumerate all non-hidden properties inserting
-       /// their name/value pair to the given map
+       /// their name/value pair to the given SortedPropertyList.
        ///
        /// @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.
-       void enumerateKeyValue(const as_object& this_ptr, std::map<std::string, 
std::string>& to) const;
+       void enumerateKeyValue(const as_object& this_ptr, SortedPropertyList& 
to) const;
 
        /// Remove all entries in the container
        void clear();

=== modified file 'libcore/as_object.cpp'
--- a/libcore/as_object.cpp     2008-09-24 10:32:01 +0000
+++ b/libcore/as_object.cpp     2008-10-25 18:51:18 +0000
@@ -1121,7 +1121,7 @@
 }
 
 void
-as_object::enumerateProperties(std::map<std::string, std::string>& to) const
+as_object::enumerateProperties(SortedPropertyList& to) const
 {
 
        // this set will keep track of visited objects,
@@ -1403,14 +1403,14 @@
 void
 as_object::getURLEncodedVars(std::string& data)
 {
-    typedef std::map<std::string, std::string> PropMap;
-    PropMap props;
+    SortedPropertyList props;
     enumerateProperties(props);
 
     std::string del;
     data.clear();
     
-    for (PropMap::const_iterator i=props.begin(), e=props.end(); i!=e; ++i)
+    for (SortedPropertyList::const_iterator i=props.begin(),
+            e=props.end(); i!=e; ++i)
     {
       std::string name = i->first;
       std::string value = i->second;

=== modified file 'libcore/as_object.h'
--- a/libcore/as_object.h       2008-10-25 10:38:32 +0000
+++ b/libcore/as_object.h       2008-10-25 18:51:18 +0000
@@ -129,7 +129,11 @@
        friend class asClass;
        friend class Machine;
 
-       typedef std::set<std::pair<string_table::key, string_table::key> > 
propNameSet;
+       typedef std::set<std::pair<string_table::key, string_table::key> >
+        propNameSet;
+
+    typedef PropertyList::SortedPropertyList SortedPropertyList;
+
 private:
        /// Properties of this objects 
        PropertyList _members;
@@ -188,7 +192,7 @@
        ///
        void dump_members();
 
-       /// Dump all properties into the given map
+       /// Dump all properties into the given container
        //
        /// Note that this method is non-const
        /// as some properties might be getter/setter
@@ -911,7 +915,7 @@
        /// 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) const;
+       void enumerateProperties(SortedPropertyList& to) const;
 
        /// Get url-encoded variables
        //

=== modified file 'libcore/asobj/LoadVars_as.cpp'
--- a/libcore/asobj/LoadVars_as.cpp     2008-10-25 15:44:08 +0000
+++ b/libcore/asobj/LoadVars_as.cpp     2008-10-25 18:51:18 +0000
@@ -63,8 +63,6 @@
 
        static void attachLoadVarsInterface(as_object& o);
 
-protected:
-
     /// Convert the LoadVars Object to a string.
     //
     /// @param o        The ostream to write the string to.
@@ -73,6 +71,8 @@
     ///                 URL encoded.
     void toString(std::ostream& o, bool encode) const;
 
+protected:
+
 #ifdef GNASH_USE_GC
        /// Mark all reachable resources, for the GC
        //
@@ -110,15 +110,15 @@
 LoadVars_as::toString(std::ostream& o, bool /*post*/) const
 {
 
-       typedef std::map<std::string, std::string> VarMap;
+       typedef PropertyList::SortedPropertyList VarMap;
        VarMap vars;
 
        enumerateProperties(vars);
 
-       for (VarMap::iterator it=vars.begin(), itEnd=vars.end();
+       for (VarMap::const_iterator it=vars.begin(), itEnd=vars.end();
                        it != itEnd; ++it)
        {
-           if (it != vars.begin()) o << "&";
+        if (it != vars.begin()) o << "&";
         const std::string& val = it->second;
         o << URL::encode(it->first) << "="
                     << URL::encode(val);
@@ -251,10 +251,12 @@
 static as_value
 loadvars_tostring(const fn_call& fn)
 {
-       boost::intrusive_ptr<LoadVars_as> ptr = 
ensureType<LoadVars_as>(fn.this_ptr);
-       UNUSED(ptr);
-       log_unimpl (__FUNCTION__);
-       return as_value(); 
+       boost::intrusive_ptr<LoadVars_as> ptr =
+        ensureType<LoadVars_as>(fn.this_ptr);
+
+    std::ostringstream data;
+    ptr->toString(data, true);
+    return as_value(data.str()); 
 }
 
 static as_value

=== modified file 'testsuite/actionscript.all/LoadVars.as'
--- a/testsuite/actionscript.all/LoadVars.as    2008-10-25 15:44:08 +0000
+++ b/testsuite/actionscript.all/LoadVars.as    2008-10-25 18:51:18 +0000
@@ -197,36 +197,36 @@
 
 lv = new LoadVars();
 lv.a = 3;
-xcheck_equals(lv.toString(), "a=3");
+check_equals(lv.toString(), "a=3");
 
 lv.b = "string";
-xcheck_equals(lv.toString(), "b=string&a=3");
+check_equals(lv.toString(), "b=string&a=3");
 
 lv.c = Mouse.hide;
-xcheck_equals(lv.toString(), "c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), "c=%5Btype%20Function%5D&b=string&a=3");
 
 lv["3"] = 6;
-xcheck_equals(lv.toString(), "3=6&c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), "3=6&c=%5Btype%20Function%5D&b=string&a=3");
 
 o = { a:5, b:6 };
 lv["f"] = o;
-xcheck_equals(lv.toString(), 
"f=%5Bobject%20Object%5D&3=6&c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), 
"f=%5Bobject%20Object%5D&3=6&c=%5Btype%20Function%5D&b=string&a=3");
 
 lv[4] = "string";
-xcheck_equals(lv.toString(), 
"4=string&f=%5Bobject%20Object%5D&3=6&c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), 
"4=string&f=%5Bobject%20Object%5D&3=6&c=%5Btype%20Function%5D&b=string&a=3");
 
 delete lv[3];
 delete lv["f"];
-xcheck_equals(lv.toString(), "4=string&c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), "4=string&c=%5Btype%20Function%5D&b=string&a=3");
 
 lv[o] = o;
-xcheck_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=string&a=3");
+check_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=string&a=3");
 
 lv.b = undefined;
 #if OUTPUT_VERSION > 6
-xcheck_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=undefined&a=3");
+check_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=undefined&a=3");
 #else
-xcheck_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=&a=3");
+check_equals(lv.toString(), 
"%5Bobject%20Object%5D=%5Bobject%20Object%5D&4=string&c=%5Btype%20Function%5D&b=&a=3");
 #endif
 
 tsc = 0;
@@ -242,14 +242,15 @@
 check_equals(tsc, 0);
 check_equals(voc, 0);
 
-xcheck_equals(lv2.toString(), "a=fake%20toString");
-xcheck_equals(tsc, 1);
+check_equals(lv2.toString(), "a=fake%20toString");
+check_equals(tsc, 1);
 check_equals(voc, 0);
 
+// This should *not* call valueOf.
 o.toString = undefined;
 xcheck_equals(lv2.toString(), "a=%5Btype%20Object%5D");
-xcheck_equals(tsc, 1);
-check_equals(voc, 0);
+check_equals(tsc, 1);
+xcheck_equals(voc, 0);
 
 
 //--------------------------------------------------------------------------

=== modified file 'testsuite/actionscript.all/enumerate.as'
--- a/testsuite/actionscript.all/enumerate.as   2008-10-25 16:13:26 +0000
+++ b/testsuite/actionscript.all/enumerate.as   2008-10-25 18:51:18 +0000
@@ -130,24 +130,29 @@
     check_equals(enumerateObj(o), "8,el,a,");
 
     o.b = "string again";
-    xcheck_equals(enumerateObj(o), "b,8,el,a,");
+    check_equals(enumerateObj(o), "b,8,el,a,");
 
     r = o.u;
-    xcheck_equals(enumerateObj(o), "b,8,el,a,");
+    check_equals(enumerateObj(o), "b,8,el,a,");
 
     t = {};
     o[t] = 9;
-    xcheck_equals(enumerateObj(o), "[object Object],b,8,el,a,");
+    check_equals(enumerateObj(o), "[object Object],b,8,el,a,");
 
     delete o["8"];
-    xcheck_equals(enumerateObj(o), "[object Object],b,el,a,");
+    check_equals(enumerateObj(o), "[object Object],b,el,a,");
 
     o.c = Object.prototype.toString;
-    xcheck_equals(enumerateObj(o), "c,[object Object],b,el,a,");
+    check_equals(enumerateObj(o), "c,[object Object],b,el,a,");
+
+    o[9] = 7;
+    check_equals(enumerateObj(o), "9,c,[object Object],b,el,a,");
     
+    o["6"] = 8;
+    check_equals(enumerateObj(o), "6,9,c,[object Object],b,el,a,");
 
 }
-totals(29);
+totals(31);
 #else
 totals(0);
 #endif  // OUTPUT_VERSION > 5

=== modified file 'testsuite/libcore.all/PropertyListTest.cpp'
--- a/testsuite/libcore.all/PropertyListTest.cpp        2008-04-07 08:01:05 
+0000
+++ b/testsuite/libcore.all/PropertyListTest.cpp        2008-10-25 18:51:18 
+0000
@@ -123,12 +123,15 @@
                check_equals(delpair.second, false); // property was NOT deleted
                check_equals(props.size(), 4);
 
-               std::map<std::string, std::string> vals;
+        PropertyList::SortedPropertyList 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" );
+               check_equals( vals[0].first, "var0");
+               check_equals( vals[0].second, "value3");
+               check_equals( vals[1].first, "Var0");
+               check_equals( vals[1].second, "value2");
+               check_equals( vals[2].first, "var1");
+               check_equals( vals[2].second, "value");
 
        }
        else
@@ -184,12 +187,16 @@
                check_equals(delpair.second, false); // property was NOT deleted
                check_equals(props.size(), 3);
 
-               std::map<std::string, std::string> vals;
+        PropertyList::SortedPropertyList vals;
                props.enumerateKeyValue(obj, vals);
                check_equals( vals.size(), 3 );
-               check_equals( vals["Var0"], "value3" );
-               check_equals( vals["var1"], "value" );
-               check_equals( vals["var2"], "value" );
+               check_equals( vals[0].first, "var2");
+               check_equals( vals[0].second, "value");
+               check_equals( vals[1].first, "var1");
+               check_equals( vals[1].second, "value");
+               check_equals( vals[2].first, "Var0");
+               check_equals( vals[2].second, "value3");
+
        }
 }
 


reply via email to

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