CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/10/20 10:47:14
Modified files: . : ChangeLog server/asobj : xml.cpp xml.h testsuite/actionscript.all: XML.as Log message: * server/asobj/xml.{cpp,h}: rework the way XML is loaded: read all input and call onData, providing a default one. Still misses a background thread, but is a bit more correct now, in that allows overriding onData. * testsuite/actionscript.all/XML.as: succeeds in finding onData in XML.prototype. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4659&r2=1.4660 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.50&r2=1.51 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.h?cvsroot=gnash&r1=1.20&r2=1.21 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/XML.as?cvsroot=gnash&r1=1.42&r2=1.43 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4659 retrieving revision 1.4660 diff -u -b -r1.4659 -r1.4660 --- ChangeLog 20 Oct 2007 10:19:51 -0000 1.4659 +++ ChangeLog 20 Oct 2007 10:47:13 -0000 1.4660 @@ -1,5 +1,14 @@ 2007-10-20 Sandro Santilli <[EMAIL PROTECTED]> + * server/asobj/xml.{cpp,h}: rework the way XML is loaded: + read all input and call onData, providing a default one. + Still misses a background thread, but is a bit more correct + now, in that allows overriding onData. + * testsuite/actionscript.all/XML.as: succeeds in finding + onData in XML.prototype. + +2007-10-20 Sandro Santilli <[EMAIL PROTECTED]> + * testsuite/Makefile.am: fix MEDIADIR path (for gnashrc) * testsuite/actionscript.all/Makefile.am: use testsuite/gnashrc for running tests (so loads from MEDIADIR are allowed). Index: server/asobj/xml.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -b -r1.50 -r1.51 --- server/asobj/xml.cpp 18 Oct 2007 11:47:55 -0000 1.50 +++ server/asobj/xml.cpp 20 Oct 2007 10:47:14 -0000 1.51 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: xml.cpp,v 1.50 2007/10/18 11:47:55 cmusick Exp $ */ +/* $Id: xml.cpp,v 1.51 2007/10/20 10:47:14 strk Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -79,6 +79,7 @@ static as_value xml_parsexml(const fn_call& fn); static as_value xml_send(const fn_call& fn); static as_value xml_sendandload(const fn_call& fn); +static as_value xml_ondata(const fn_call& fn); static LogFile& dbglogfile = gnash::LogFile::getDefaultInstance(); #ifdef USE_DEBUGGER @@ -395,6 +396,40 @@ } +void +XML::queueLoad(std::auto_ptr<tu_file> str, as_environment& env) +{ + GNASH_REPORT_FUNCTION; + + // Set the "loaded" parameter to false + VM& vm = _vm; + string_table& st = vm.getStringTable(); + string_table::key loadedKey = st.find("loaded"); + string_table::key onDataKey = st.find(PROPNAME("onData")); + set_member(loadedKey, as_value(false)); + + // TODO: + // 1. interrupt any pre-existing loading thread (send onLoad event in that case?) + // 2. start new loading thread + // + // Using LoadThread should do. Most likely we should do something + // similar for LoadVars or ::loadVariables, so might consider generalizing + // a load-in-a-separate-thread-calling-onLoad-when-done class + // + // The class would use a separate thread, provide cancelling and + // will call a specified function (or functor) when all data arrived, + // passing it the full data buffer. + // + std::string src; + char buf[256]; + while ( 1 ) + { + size_t bytes = str->read_bytes(buf, 255); + src.append(buf, bytes); + if ( bytes < 255 ) break; // end of buffer + } + callMethod(onDataKey, env, as_value(src)); +} // This reads in an XML file from disk and parses into into a memory resident // tree which can be walked through later. @@ -405,57 +440,19 @@ //log_msg(_("%s: mem is %d"), __FUNCTION__, mem); - // Clear current data - clear(); - std::auto_ptr<tu_file> str ( StreamProvider::getDefaultInstance().getStream(url) ); if ( ! str.get() ) { log_error(_("Can't load XML file: %s (security?)"), url.str().c_str()); - onLoadEvent(false, env); + as_value nullValue; nullValue.set_null(); + callMethod(VM::get().getStringTable().find("onData"), env, nullValue); return false; } log_msg(_("Loading XML file from url: '%s'"), url.str().c_str()); + queueLoad(str, env); - initParser(); - - int options = getXMLOptions(); - - _doc = xmlReadIO(readFromTuFile, closeTuFile, str.get(), url.str().c_str(), NULL, options); - if ( str->get_error() ) - { - xmlFreeDoc(_doc); - _doc = 0; - log_error(_("Can't read XML file %s (stream error %d)"), url.str().c_str(), str->get_error()); - _loaded = 0; - onLoadEvent(false, env); - return false; - } - - _bytes_total = str->get_size(); - - if (_doc == 0) - { - xmlErrorPtr err = xmlGetLastError(); - log_error(_("Can't read XML file %s (%s)"), url.str().c_str(), err->message); - _loaded = 0; - onLoadEvent(false, env); - return false; - } - - _bytes_loaded = _bytes_total; - - bool ret = parseDoc(_doc, false); - - xmlCleanupParser(); - xmlFreeDoc(_doc); - xmlMemoryDump(); - _loaded = ret ? 1 : 0; - - onLoadEvent(ret, env); - - return ret; + return true; } @@ -568,6 +565,7 @@ o.init_member("parseXML", new builtin_function(xml_parsexml)); o.init_member("send", new builtin_function(xml_send)); o.init_member("sendAndLoad", new builtin_function(xml_sendandload)); + o.init_member("onData", new builtin_function(xml_ondata)); } @@ -659,10 +657,8 @@ if (fn.nargs > 0) { const std::string& text = fn.arg(0).to_string(&(fn.env())); XMLNode *xml_obj = new XMLNode(); -// cerr << "create new child XMLNode is at " << (void *)xml_obj << endl; xml_obj->nodeNameSet(text); xml_obj->nodeTypeSet(XMLNode::tText); -// ptr->set_member(text, xml_obj); // FIXME: use a getter/setter ! // no return code from this method return as_value(xml_obj); @@ -772,6 +768,43 @@ return as_value(); } +static as_value +xml_ondata(const fn_call& fn) +{ + GNASH_REPORT_FUNCTION; + + VM& vm = VM::get(); + string_table& st = vm.getStringTable(); + string_table::key onLoadKey = st.find(PROPNAME("onLoad")); + string_table::key loadedKey = st.find("loaded"); + as_environment& env = fn.env(); + + as_object* thisPtr = fn.this_ptr.get(); + assert(thisPtr); + + // See http://gitweb.freedesktop.org/?p=swfdec/swfdec.git;a=blob;f=libswfdec/swfdec_initialize.as + + as_value src; src.set_null(); + if ( fn.nargs ) src = fn.arg(0); + + if ( ! src.is_null() ) + { + string_table::key parseXMLKey = st.find(PROPNAME("parseXML")); + as_value tmp(true); + thisPtr->set_member(loadedKey, tmp); + thisPtr->callMethod(parseXMLKey, env, src); + thisPtr->callMethod(onLoadKey, env, tmp); + } + else + { + as_value tmp(true); + thisPtr->set_member(loadedKey, tmp); + thisPtr->callMethod(onLoadKey, env, tmp); + } + + return as_value(); +} + int memadjust(int x) { Index: server/asobj/xml.h =================================================================== RCS file: /sources/gnash/gnash/server/asobj/xml.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -b -r1.20 -r1.21 --- server/asobj/xml.h 18 Oct 2007 11:47:55 -0000 1.20 +++ server/asobj/xml.h 20 Oct 2007 10:47:14 -0000 1.21 @@ -223,11 +223,12 @@ void setupFrame(gnash::as_object *xml, XMLNode *data, bool src); -private: - /// Initialize the libxml2 parser void initParser(); + /// Queue a load request from the given stream + void queueLoad(std::auto_ptr<tu_file> str, as_environment& env); + //static void _xmlErrorHandler(void *ctx, const char* fmt, ...); }; Index: testsuite/actionscript.all/XML.as =================================================================== RCS file: /sources/gnash/gnash/testsuite/actionscript.all/XML.as,v retrieving revision 1.42 retrieving revision 1.43 diff -u -b -r1.42 -r1.43 --- testsuite/actionscript.all/XML.as 20 Oct 2007 09:34:45 -0000 1.42 +++ testsuite/actionscript.all/XML.as 20 Oct 2007 10:47:14 -0000 1.43 @@ -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.42 2007/10/20 09:34:45 strk Exp $"; +rcsid="$Id: XML.as,v 1.43 2007/10/20 10:47:14 strk Exp $"; #include "check.as" //#include "dejagnu.as" @@ -619,7 +619,7 @@ myxml = new XML; -xcheck_equals(typeof(myxml.onData), 'function'); +check_equals(typeof(myxml.onData), 'function'); #if OUTPUT_VERSION > 5 check(myxml.onData != XML.prototype.parseXML); #endif _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit