gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10423: Add an isStrict() method to


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10423: Add an isStrict() method to Array_as; add an allowStrictArray method to
Date: Sun, 14 Dec 2008 13:48:17 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10423
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Sun 2008-12-14 13:48:17 +0100
message:
  Add an isStrict() method to Array_as; add an allowStrictArray method to
  as_value::writeAMF0; Have SharedObject encoding disallow encoding of 
STRICT_ARRAY
  and NetConnection allow it. Fixes writing lines with potlatch.
modified:
  libcore/PropertyList.h
  libcore/array.cpp
  libcore/array.h
  libcore/as_object.h
  libcore/as_value.cpp
  libcore/as_value.h
  libcore/asobj/NetConnection_as.cpp
  libcore/asobj/SharedObject.cpp
=== modified file 'libcore/PropertyList.h'
--- a/libcore/PropertyList.h    2008-12-13 22:59:25 +0000
+++ b/libcore/PropertyList.h    2008-12-14 12:48:17 +0000
@@ -153,6 +153,18 @@
                }
        }
 
+    /// Is any non-hidden property in this list ?
+    bool hasNonHiddenProperties() const
+    {
+        typedef container::nth_index<1>::type ContainerByOrder;
+        for (ContainerByOrder::const_reverse_iterator 
it=_props.get<1>().rbegin(),
+            ie=_props.get<1>().rend(); it != ie; ++it)
+               {
+               if (! it->getFlags().get_dont_enum()) return true;
+        }
+        return false;
+    }
+
 
        /// Get the as_value value of a named property
        //

=== modified file 'libcore/array.cpp'
--- a/libcore/array.cpp 2008-12-14 01:10:00 +0000
+++ b/libcore/array.cpp 2008-12-14 12:48:17 +0000
@@ -1702,6 +1702,13 @@
     as_object::visitNonHiddenPropertyValues(visitor);
 }
 
+bool
+Array_as::isStrict() const
+{
+    if ( hasNonHiddenProperties() ) return false;
+    return true;
+}
+
 } // end of gnash namespace
 
 

=== modified file 'libcore/array.h'
--- a/libcore/array.h   2008-11-15 19:49:41 +0000
+++ b/libcore/array.h   2008-12-14 12:48:17 +0000
@@ -122,6 +122,15 @@
 
        ~Array_as();
 
+    /// Return true if this is a strict array
+    //
+    /// Strict arrays are those whose enumerable
+    /// properties are only valid positive integer.
+    /// Telling strict apart from non-strict is needed
+    /// for AMF encoding in remoting.
+    ///
+    bool isStrict() const;
+
        std::deque<indexed_as_value> get_indexed_elements();
 
        Array_as::const_iterator begin();

=== modified file 'libcore/as_object.h'
--- a/libcore/as_object.h       2008-12-08 15:58:46 +0000
+++ b/libcore/as_object.h       2008-12-14 12:48:17 +0000
@@ -157,6 +157,11 @@
 
 public:
 
+    /// Is any non-hidden property in this object ?
+    bool hasNonHiddenProperties() const {
+        return _members.hasNonHiddenProperties();
+    }
+
        /// Find a property scanning the inheritance chain
        ///
        /// @param name

=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp      2008-12-13 16:37:27 +0000
+++ b/libcore/as_value.cpp      2008-12-14 12:48:17 +0000
@@ -180,14 +180,15 @@
 
 public:
     PropsBufSerializer(SimpleBuffer& buf, VM& vm,
-            PropertyOffsets& offsetTable)
+            PropertyOffsets& offsetTable, bool allowStrict)
         :
+        _allowStrict(allowStrict),
         _buf(buf),
         _vm(vm),
         _st(vm.getStringTable()),
         _offsetTable(offsetTable),
         _error(false)
-       {};
+       {}
     
     bool success() const { return !_error; }
 
@@ -226,7 +227,7 @@
         boost::uint16_t namelen = name.size();
         _buf.appendNetworkShort(namelen);
         _buf.append(name.c_str(), namelen);
-        if ( ! val.writeAMF0(_buf, _offsetTable, _vm) )
+        if ( ! val.writeAMF0(_buf, _offsetTable, _vm, _allowStrict) )
         {
             log_error("Problems serializing an object's member");
             _error=true;
@@ -235,6 +236,7 @@
 
 private:
 
+    bool _allowStrict;
     SimpleBuffer& _buf;
     VM& _vm;
     string_table& _st;
@@ -2369,7 +2371,8 @@
 
 bool
 as_value::writeAMF0(SimpleBuffer& buf, 
-        std::map<as_object*, size_t>& offsetTable, VM& vm) const
+        std::map<as_object*, size_t>& offsetTable, VM& vm,
+        bool allowStrict) const
 {
     typedef std::map<as_object*, size_t> OffsetTable;
 
@@ -2399,13 +2402,38 @@
                 if ( ary )
                 {
                     size_t len = ary->size();
-#ifdef GNASH_DEBUG_AMF_SERIALIZE
-                    log_debug(_("writeAMF0: serializing array of %d "
-                                "elements as ECMA_ARRAY (index %d)"),
-                                len, idx);
-#endif
-                    buf.appendByte(amf::Element::ECMA_ARRAY_AMF0);
-                    buf.appendNetworkLong(len);
+                    if ( allowStrict && ary->isStrict() )
+                    {
+#ifdef GNASH_DEBUG_AMF_SERIALIZE
+                        log_debug(_("writeAMF0: serializing array of %d "
+                                    "elements as STRICT_ARRAY (index %d)"),
+                                    len, idx);
+#endif
+                        buf.appendByte(amf::Element::STRICT_ARRAY_AMF0);
+                        buf.appendNetworkLong(len);
+
+                        as_value elem;
+                        for (size_t i=0; i<len; ++i)
+                        {
+                            elem = ary->at(i);
+                            if ( ! elem.writeAMF0(buf, offsetTable, vm, 
allowStrict) )
+                            {
+                                log_error("Problems serializing strict array 
member %d=%s", i, elem);
+                                return false;
+                            }
+                        }
+                        return true;
+                    }
+                    else 
+                    {
+#ifdef GNASH_DEBUG_AMF_SERIALIZE
+                        log_debug(_("writeAMF0: serializing array of %d "
+                                    "elements as ECMA_ARRAY (index %d) 
[allowStrict:%d, isStrict:%d]"),
+                                    len, idx, allowStrict, ary->isStrict());
+#endif
+                        buf.appendByte(amf::Element::ECMA_ARRAY_AMF0);
+                        buf.appendNetworkLong(len);
+                    }
                 }
                 else
                 {
@@ -2416,7 +2444,7 @@
                     buf.appendByte(amf::Element::OBJECT_AMF0);
                 }
 
-                PropsBufSerializer props(buf, vm, offsetTable);
+                PropsBufSerializer props(buf, vm, offsetTable, allowStrict);
                 obj->visitNonHiddenPropertyValues(props);
                 if ( ! props.success() ) 
                 {

=== modified file 'libcore/as_value.h'
--- a/libcore/as_value.h        2008-11-15 19:49:41 +0000
+++ b/libcore/as_value.h        2008-12-14 12:48:17 +0000
@@ -240,7 +240,11 @@
     ///     Virtual machine to use for serialization of property names
     ///     (string_table)
     ///
-    bool writeAMF0(SimpleBuffer& buf, std::map<as_object*, size_t>& 
offsetTable, VM& vm) const;
+       /// @param allowStrictArray
+    ///     If true strict arrays will be encoded a STRICT_ARRAY types.
+    ///
+    bool writeAMF0(SimpleBuffer& buf, std::map<as_object*, size_t>& 
offsetTable,
+                   VM& vm, bool allowStrictArray) const;
 
        /// Convert numeric value to string value, following ECMA-262 
specification
        //

=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp        2008-12-14 00:00:05 +0000
+++ b/libcore/asobj/NetConnection_as.cpp        2008-12-14 12:48:17 +0000
@@ -848,7 +848,8 @@
         for (unsigned int i = 2; i < fn.nargs; ++i)
         {
             const as_value& arg = fn.arg(i);
-            if ( ! arg.writeAMF0(*buf, offsetTable, vm) )
+            // STRICT_ARRAY encoding is allowed for remoting
+            if ( ! arg.writeAMF0(*buf, offsetTable, vm, true) )
             {
                 log_error("Could not serialize NetConnection.call argument %d",
                         i);

=== modified file 'libcore/asobj/SharedObject.cpp'
--- a/libcore/asobj/SharedObject.cpp    2008-12-11 08:18:23 +0000
+++ b/libcore/asobj/SharedObject.cpp    2008-12-14 12:48:17 +0000
@@ -194,7 +194,8 @@
         boost::uint16_t namelen = name.size();
         _buf.appendNetworkShort(namelen);
         _buf.append(name.c_str(), namelen);
-        if ( ! val.writeAMF0(_buf, _offsetTable, _vm) )
+        // Strict array are never encoded in SharedObject
+        if ( ! val.writeAMF0(_buf, _offsetTable, _vm, false) )
         {
             log_error("Problems serializing an object's member %s=%s",
                     name, val);


reply via email to

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