gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash server/asobj/xml.cpp server/asobj/xml.h t...


From: Sandro Santilli
Subject: [Gnash-commit] gnash server/asobj/xml.cpp server/asobj/xml.h t...
Date: Tue, 03 Apr 2007 08:04:46 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/03 08:04:46

Modified files:
        server/asobj   : xml.cpp xml.h 
        testsuite/actionscript.all: XML.as 

Log message:
        Some more cleanups, and a few more tests

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.h?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/XML.as?cvsroot=gnash&r1=1.17&r2=1.18

Patches:
Index: server/asobj/xml.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- server/asobj/xml.cpp        3 Apr 2007 07:30:17 -0000       1.25
+++ server/asobj/xml.cpp        3 Apr 2007 08:04:46 -0000       1.26
@@ -14,7 +14,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-/* $Id: xml.cpp,v 1.25 2007/04/03 07:30:17 strk Exp $ */
+/* $Id: xml.cpp,v 1.26 2007/04/03 08:04:46 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -35,6 +35,7 @@
 #include "URLAccessManager.h"
 #include "tu_file.h"
 #include "URL.h"
+#include "VM.h"
 
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
@@ -47,6 +48,7 @@
 #include <sstream>
 #include <vector>
 #include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/case_conv.hpp>
 #include <memory>
 
 using namespace std;
@@ -209,46 +211,57 @@
     printf("%s: XML _nodes at %p\n", __PRETTY_FUNCTION__, (void*)_nodes);
 }
 
-// Dispatch event handler(s), if any.
-bool
-XML::on_event(const event_id& /* id */)
+void
+XML::onLoadEvent(bool success)
 {
-    GNASH_REPORT_FUNCTION;
-    
-    // Keep m_as_environment alive during any method calls!
-    //  boost::intrusive_ptr<as_object_interface>      this_ptr(this);
-  
-#if 0
-    // First, check for built-in event handler.
-    as_value   method;
-    if (get_event_handler(event_id(id), &method)) {
-        call_method0(method, &m_as_environment, this);
-        return true;
-    }
+    // Do the events that (appear to) happen as the movie
+    // loads.  frame1 tags and actions are executed (even
+    // before advance() is called).  Then the onLoad event
+    // is triggered.
   
-    // Check for member function.
     // In ActionScript 2.0, event method names are CASE SENSITIVE.
     // In ActionScript 1.0, event method names are CASE INSENSITIVE.
-    const tu_string&   method_name = id.get_function_name();
-    if (method_name.length() > 0) {
+    // TODO: move to get_function_name directly ?
+    std::string method_name = "onLoad";
+    if ( _vm.getSWFVersion() < 7 )
+        boost::to_lower(method_name, _vm.getLocale());
+
+    if ( method_name.empty() ) return;
+
         as_value       method;
-        if (get_member(method_name, &method)) {
-            call_method0(method, &m_as_environment, this);
-            return true;
-        }
-    }
-#endif
-    return false;
+    if ( ! get_member(method_name, &method) ) return;
+    if ( method.is_undefined() ) return;
+    if ( ! method.is_function() ) return;
+
+    as_environment env; // how to set target here ??
+    env.push(as_value(success));
+    call_method(method, &env, this, 1, env.stack_size()-1);
 }
 
 void
-XML::on_event_load()
+XML::onCloseEvent()
 {
     // Do the events that (appear to) happen as the movie
     // loads.  frame1 tags and actions are executed (even
     // before advance() is called).  Then the onLoad event
     // is triggered.
-    on_event(event_id::LOAD);
+
+    // In ActionScript 2.0, event method names are CASE SENSITIVE.
+    // In ActionScript 1.0, event method names are CASE INSENSITIVE.
+    // TODO: move to get_function_name directly ?
+    std::string method_name = "onClose";
+    if ( _vm.getSWFVersion() < 7 )
+        boost::to_lower(method_name, _vm.getLocale());
+
+    if ( method_name.empty() ) return;
+
+    as_value   method;
+    if ( ! get_member(method_name, &method) ) return;
+    if ( method.is_undefined() ) return;
+    if ( ! method.is_function() ) return;
+
+    as_environment env; // how to set target here ??
+    call_method(method, &env, this, 0, 0);
 }
 
 XMLNode*
@@ -409,6 +422,7 @@
     if ( ! str.get() ) 
     {
         log_error("Can't load XML file: %s (security?)", url.str().c_str());
+        onLoadEvent(false);
         return false;
     }
 
@@ -421,6 +435,7 @@
 
     if (_doc == 0) {
         log_error("Can't read XML file (IO): %s!", url.str().c_str());
+        onLoadEvent(false);
         return false;
     }
 
@@ -430,6 +445,9 @@
     xmlCleanupParser();
     xmlFreeDoc(_doc);
     xmlMemoryDump();
+
+    onLoadEvent(true);
+
     return true;
 }
 
@@ -797,106 +815,10 @@
         return rv;
     }
     
-    //env->bottom(first_arg) = ret;
-    //  struct node *first_node = ptr->firstChildGet();
-  
-    //const char *name = ptr->nodeNameGet();
-
-    if (xml_obj->hasChildNodes() == false) {
-        log_error("%s: No child nodes!\n", __FUNCTION__);
-    }  
-    xml_obj->setupFrame(xml_obj.get(), xml_obj->firstChild(), false);
-  
-    if (fn.this_ptr->get_member("onLoad", &method))
-    {
-        //    log_msg("FIXME: Found onLoad!\n");
-        fn.env().set_variable("success", true);
-        fn.arg(0) = true;
-           if (as_function* as_func = method.to_as_function())
-        {
-               // It's an ActionScript function.  Call it.
-               log_msg("Calling ActionScript function for XML.onLoad");
-               // XXX other than being assigned into, val appears to be unused.
-               val = (*as_func)(fn_call(xml_obj, &fn.env(), fn.nargs, 
fn.offset())); // was this_ptr instead of node
-           }
-        else
-        {
-               log_error("error in call_method(): method is not a function\n");
-           }
-    }
-    else
-    {
-        //log_msg("Couldn't find onLoad event handler, setting up callback");
-        // ptr->set_event_handler(event_id::XML_LOAD, 
(as_c_function_ptr)&xml_onload);
-    }
-
     rv = true;
     return rv;
 }
 
-// This executes the event handler for XML::XML_LOAD if it's been defined,
-// and the XML file has loaded sucessfully.
-as_value
-xml_onload(const fn_call& fn)
-{
-    //log_msg("%s:\n", __FUNCTION__);
-    
-    as_value   method;
-    as_value      val;
-    static bool first = true;     // This event handler should only be 
executed once.
-    boost::intrusive_ptr<XML> ptr = ensureType<XML>(fn.this_ptr);
-  
-    if ((ptr->loaded()) && (first)) {
-        // env->set_variable("success", true, 0);
-        //as_value bo(true);
-        //env->push_val(bo);
-
-        first = false;
-        log_msg("The XML file has been loaded successfully!\n");
-        // ptr->on_event(event_id::XML_LOAD);
-        //env->set_variable("success", true, 0);
-        //env->bottom(0) = true;
-    
-        if (fn.this_ptr->get_member("onLoad", &method)) {
-            // log_msg("FIXME: Found onLoad!\n");
-           val = call_method(method, &fn.env(), fn.this_ptr.get(), 0, 0);
-        } else {
-            log_msg("FIXME: Couldn't find onLoad!\n");
-        }
-    }
-      
-    return as_value(val.to_bool());
-}
-
-// This is the default event handler, and is usually redefined in the SWF 
script
-#if 0 // UNUSED, it seems
-as_value
-xml_ondata(const fn_call& fn)
-{
-    log_msg("%s:\n", __FUNCTION__);
-    
-    as_value   method;
-    as_value   val;
-    static bool first = true;     // FIXME: ugly hack!
-  
-    boost::intrusive_ptr<XML> ptr = ensureType<XML>(fn.this_ptr);
-  
-    if ((ptr->loaded()) && (first)) {
-        if (fn.this_ptr->get_member("onData", &method)) {
-            log_msg("FIXME: Found onData!\n");
-           // TODO: this is suspicious (set_variable for what??)
-            fn.env().set_variable("success", true);
-           val = call_method(method, fn.env(), fn.this_ptr, 0, 0);
-        } else {
-            log_msg("FIXME: Couldn't find onData!\n");
-        }
-    }
-
-    //fn.result->set(&val);
-    return as_value(val.to_bool());
-}
-#endif // UNUSED
-
 void
 attachXMLInterface(as_object& o)
 {
@@ -1175,21 +1097,7 @@
        }
     }
     
-#if 1
-    if (fn.this_ptr->get_member("onLoad", &method)) {
-        log_msg("FIXME: Found onLoad!\n");
-        fn.env().set_variable("success", true); // what is this for ?
-       fn.arg(0) = true; // what is this for ?
-       val = call_method(method, &fn.env(), fn.this_ptr.get(), 0, 0);
-    } else {
-        log_msg("Couldn't find onLoad event handler, setting up callback\n");
-        // ptr->set_event_handler(event_id::XML_LOAD, 
(as_c_function_ptr)&xml_onload);
-    }
-#else
-    
-#endif
     return as_value();
-//    return as_value(ptr->getAllocated());
 }
 
 /// \brief removes the specified XML object from its parent. Also

Index: server/asobj/xml.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- server/asobj/xml.h  3 Apr 2007 07:30:17 -0000       1.9
+++ server/asobj/xml.h  3 Apr 2007 08:04:46 -0000       1.10
@@ -80,8 +80,6 @@
     // Appends a node to the end of the specified object's child list.
     void appendChild(XMLNode *node);
     
-    virtual bool on_event(const gnash::event_id& id);
-    virtual void       on_event_load();
     bool loaded()    { return _loaded; }
     
     XMLNode *firstChild() {
@@ -138,17 +136,6 @@
     int getBytesLoaded()         { return _bytes_loaded; };
     int getBytesTotal()          { return _bytes_total; };
 
-    virtual void       on_xml_event(const gnash::event_id& id)
-    {
-       on_event(id);
-    }
-  
-    // Special event handler; 
-    void       on_event_close()
-    {
-       on_event(gnash::event_id::SOCK_CLOSE);
-    }
-  
     XMLNode *operator [] (int x);
 #if 0
     XMLNode *operator = (XMLNode &node) {
@@ -188,6 +175,12 @@
     bool        _status;       // TODO Should be Number
     bool        _previousSibling;
 
+    /// Trigger the onLoad event, if any
+    void onLoadEvent(bool success);
+
+    /// Trigger the onClose event, if any
+    void onCloseEvent();
+  
 };
 
 

Index: testsuite/actionscript.all/XML.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/XML.as,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- testsuite/actionscript.all/XML.as   13 Feb 2007 19:36:34 -0000      1.17
+++ testsuite/actionscript.all/XML.as   3 Apr 2007 08:04:46 -0000       1.18
@@ -20,7 +20,7 @@
 // compile this test case with Ming makeswf, and then
 // execute it like this gnash -1 -r 0 -v out.swf
 
-rcsid="$Id: XML.as,v 1.17 2007/02/13 19:36:34 rsavoye Exp $";
+rcsid="$Id: XML.as,v 1.18 2007/04/03 08:04:46 strk Exp $";
 
 #include "dejagnu.as"
 #include "utils.as"
@@ -257,10 +257,12 @@
 
 // place the new nodes into the XML tree
 element2.appendChild(textNode1);
-check(element2.nodeValue == "textNode1 String value");
+xcheck_equals(element2.nodeValue, null);
+xcheck_equals(element2.lastChild.nodeValue, "textNode1 String value");
 
 element3.appendChild(textNode2);
-check(element3.nodeValue == "textNode2 String value");
+xcheck_equals(element3.nodeValue, null); 
+xcheck_equals(element3.lastChild.nodeValue, "textNode2 String value");
 
 // place the new nodes into the XML tree
 doc.appendChild(element1);
@@ -301,5 +303,28 @@
 // }
 // #endif
 
+
+//--------------------------------------------------------------------
+// Test loading an XML locally
+//--------------------------------------------------------------------
+
+myxml = new XML;
+myxml.onLoad = function(success)
+{
+       note("myxml.onLoad("+success+") called");
+       if ( ! success )
+       {
+               note("No success loading gnash.xml");
+               return;
+       }
+       note("gnash.xml successfully loaded");
+       note("myxml status is "+myxml.status);
+       note("myxml.toString(): "+myxml.toString());
+       xcheck_equals(typeof(myxml.attributes), 'object');
+       check(myxml.hasChildNodes());
+       xcheck_equals(myxml.nodeName, null);
+};
+myxml.load( MEDIA(gnash.xml) );
+
 // We're done
-totals();
+//totals();




reply via email to

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