gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9707: SharedObject cleanups and tes


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9707: SharedObject cleanups and test improvement
Date: Tue, 09 Sep 2008 19:40:11 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9707
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Tue 2008-09-09 19:40:11 +0200
message:
  SharedObject cleanups and test improvement
modified:
  libamf/sol.h
  libcore/PropertyList.h
  libcore/asobj/SharedObject.cpp
  testsuite/actionscript.all/SharedObject.as
    ------------------------------------------------------------
    revno: 9706.1.1
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Tue 2008-09-09 11:59:05 +0200
    message:
      fix comment for visitValues
    modified:
      libcore/PropertyList.h
    ------------------------------------------------------------
    revno: 9706.1.2
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Tue 2008-09-09 12:38:10 +0200
    message:
      Test that SharedObject.flush() doesn't invoke getter-setter assigned
      to the 'data' member.
    modified:
      testsuite/actionscript.all/SharedObject.as
    ------------------------------------------------------------
    revno: 9706.1.3
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Tue 2008-09-09 12:59:03 +0200
    message:
      some const-correctness
    modified:
      libamf/sol.h
    ------------------------------------------------------------
    revno: 9706.1.4
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Tue 2008-09-09 12:59:07 +0200
    message:
      Have SharedObject *hold* (not be) a SOL instance.
    modified:
      libcore/asobj/SharedObject.cpp
=== modified file 'libamf/sol.h'
--- a/libamf/sol.h      2008-09-04 10:48:29 +0000
+++ b/libamf/sol.h      2008-09-09 10:59:03 +0000
@@ -99,11 +99,11 @@
 
 //protected:
 
-    void setFilespec(std::string &x) { _filespec = x; };
-    std::string &getFilespec() { return _filespec; };
+    void setFilespec(const std::string &x) { _filespec = x; };
+    const std::string &getFilespec() const { return _filespec; };
 
-    void setObjectName(std::string &x) { _objname = x; };
-    std::string &getObjectName() { return _objname; };
+    void setObjectName(const std::string &x) { _objname = x; };
+    const std::string &getObjectName() const { return _objname; };
         
  private:
     std::vector<gnash::Network::byte_t> _header;

=== modified file 'libcore/PropertyList.h'
--- a/libcore/PropertyList.h    2008-05-05 13:39:04 +0000
+++ b/libcore/PropertyList.h    2008-09-09 09:59:05 +0000
@@ -101,7 +101,7 @@
        /// value of it.
        ///
        /// @param visitor
-       ///     The visitor function. Must take a const std::string
+       ///     The visitor function. Must take a string_table::key 
        ///     reference as first argument and a const as_value reference
        ///     as second argument.
        ///

=== modified file 'libcore/asobj/SharedObject.cpp'
--- a/libcore/asobj/SharedObject.cpp    2008-08-19 15:42:34 +0000
+++ b/libcore/asobj/SharedObject.cpp    2008-09-09 10:59:07 +0000
@@ -162,76 +162,121 @@
 }
 
 
-class SharedObject: public as_object, public amf::SOL
+class SharedObject: public as_object 
 {
 public:
+
     SharedObject()
         :
         as_object(getSharedObjectInterface())
     { 
                attachProperties(*this);
     }
+
+    bool flush() const;
+
+    const std::string& getFilespec() const {
+        return _sol.getFilespec();
+    }
+
+    void setFilespec(const std::string& s) {
+        _sol.setFilespec(s);
+    }
+
+    const std::string& getObjectName() const {
+        return _sol.getObjectName();
+    }
+
+    void setObjectName(const std::string& s) {
+        _sol.setObjectName(s);
+    }
+
+    size_t size() const { 
+        return _sol.size(); // TODO: fix this, is bogus
+    }
+
+private:
+
+    SOL _sol;
 };
 
-
-as_value
-sharedobject_clear(const fn_call& fn)
-{
-//    GNASH_REPORT_FUNCTION;
-    boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
-    UNUSED(obj);
-    
-    LOG_ONCE(log_unimpl (__FUNCTION__));
-
-    return as_value();
-}
-
-as_value
-sharedobject_flush(const fn_call& fn)
-{
-//    GNASH_REPORT_FUNCTION;
-    
-    boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
-
-//    log_debug("Flushing to file %s", obj->getFilespec());        
-    VM& vm = obj->getVM();
-
-#ifndef USE_SOL_READONLY
+bool
+SharedObject::flush() const
+{
+    const std::string& filespec = _sol.getFilespec();
+
+#ifdef USE_SOL_READONLY
+    log_debug(_("SharedObject %s not flushed (compiled as read-only mode)"), 
filespec);
+    return false;
+#endif
+
+//    log_debug("Flushing to file %s", filespec);
+
+    VM& vm = getVM();
+
     if (rcfile.getSOLReadOnly() ) {
         log_security("Attempting to write object %s when it's SOL Read Only is 
set! Refusing...",
-                     obj->getFilespec());
-        return as_value(false);
+                     filespec);
+        return false;
     }
     
     // TODO: cache the dataKey in SharedObject prototype on first use ?
     //       a SharedObject::getDataKey() might do...
     string_table::key dataKey = vm.getStringTable().find("data");
     
-    as_value as = obj->getMember(dataKey);
+    as_value as = const_cast<SharedObject*>(this)->getMember(dataKey);
     boost::intrusive_ptr<as_object> ptr = as.to_object();
     if ( ! ptr ) {
-        log_error("'data' member of SharedObject is not an object (%s)",
+        log_aserror("'data' member of SharedObject is not an object (%s)",
                   as);
-        return as_value();
+        return true;
     }
-    
+
     SOL sol;
     PropsSerializer props(sol, vm);
     ptr->visitPropertyValues(props);
     // We only want to access files in this directory
-    std::string newspec; 
-    newspec += obj->getFilespec();
-    bool ret = sol.writeFile(newspec, obj->getObjectName().c_str());
+    bool ret = sol.writeFile(filespec, getObjectName().c_str());
     if ( ! ret )
     {
-        log_error("writing SharedObject file to %s", newspec);
-        return as_value(false);
-    }
-    log_security("SharedObject '%s' written to filesystem.", newspec);
-    return as_value(true); // TODO: check expected return type from 
SharedObject.flush
-#else
-    return as_value(false);
-#endif
+        log_error("writing SharedObject file to %s", filespec);
+        return false;
+    }
+
+    log_security("SharedObject '%s' written to filesystem.", filespec);
+    return true;
+}
+
+
+as_value
+sharedobject_clear(const fn_call& fn)
+{
+//    GNASH_REPORT_FUNCTION;
+    boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
+    UNUSED(obj);
+    
+    LOG_ONCE(log_unimpl (__FUNCTION__));
+
+    return as_value();
+}
+
+as_value
+sharedobject_flush(const fn_call& fn)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+    boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
+
+    IF_VERBOSE_ASCODING_ERRORS(
+    if ( fn.nargs )
+    {
+        std::stringstream ss;
+        fn.dump_args(ss);
+        log_aserror(_("Arguments to SharedObject.flush(%s) will be ignored"), 
ss.str());
+    }
+    )
+
+    return as_value(obj->flush());
 }
 
 // Set the file name

=== modified file 'testsuite/actionscript.all/SharedObject.as'
--- a/testsuite/actionscript.all/SharedObject.as        2008-03-11 19:31:46 
+0000
+++ b/testsuite/actionscript.all/SharedObject.as        2008-09-09 10:38:10 
+0000
@@ -139,6 +139,27 @@
 ret = so4.flush();
 xcheck_equals(typeof(ret), 'undefined');
 
-check_totals(38);
+//------------------------------------------
+// Test that if 'data' is a getter-setter,
+// it isn't called on .flush()
+//------------------------------------------
+
+so5 = SharedObject.getLocal("getset");
+check(so5 instanceof SharedObject);
+dataGet = function() { getCalls++; return new Object(); };
+getCalls=0;
+so5.addProperty('data', dataGet, dataGet);
+junk=so5.data;
+check_equals(getCalls, 1); // the getter works
+getCalls=0;
+ret=so5.flush();
+check_equals(ret, true);
+xcheck_equals(getCalls, 0); // flush didn't cal the getter
+
+//------------------------------------------
+// END OF TESTS
+//------------------------------------------
+
+check_totals(42);
 
 #endif // OUTPUT_VERSION >= 6


reply via email to

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