[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash server/asobj/xmlnode.h server/asobj/xmlno...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash server/asobj/xmlnode.h server/asobj/xmlno... |
Date: |
Thu, 15 Feb 2007 04:05:42 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 07/02/15 04:05:42
Modified files:
server/asobj : xmlnode.h xmlnode.cpp
testsuite/actionscript.all: XMLNode.as
. : ChangeLog
Log message:
* testsuite/actionscript.all/XMLNode.as: Fix tests for newly
work
XLNode class.
* server/asobj/xmlnode.{cpp,h}: Make nextSibling,
previousSibling,
firstChild, and lastChild work correctly.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlnode.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlnode.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/XMLNode.as?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2362&r2=1.2363
Patches:
Index: server/asobj/xmlnode.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlnode.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- server/asobj/xmlnode.h 13 Feb 2007 19:36:34 -0000 1.6
+++ server/asobj/xmlnode.h 15 Feb 2007 04:05:41 -0000 1.7
@@ -74,24 +74,11 @@
// nodeType XML.nodeType
const char *stringify(XMLNode *xml, std::stringstream *xmlout);
- bool hasChildNodes()
- {
- return ! _children.empty();
- }
-
- XMLNode *firstChild()
- {
- return _children.empty() ? NULL : _children.front();
- }
+ bool hasChildNodes();
+ XMLNode *firstChild();
+ XMLNode *lastChild();
- XMLNode *lastChild()
- {
- return _children.empty() ? NULL : _children.back();
- }
-
- std::vector<XMLNode *>& childNodes() {
- return _children;
- }
+ std::vector<XMLNode *>& childNodes() { return _children; }
XMLNode *operator [] (int x) {
gnash::log_msg("%s: get element %d\n", __PRETTY_FUNCTION__, x);
@@ -117,10 +104,12 @@
return this;
}
- XMLNode* previousSibling(int x);
- XMLNode* nextSibling(int x);
+ XMLNode* previousSibling();
+ XMLNode* nextSibling();
XMLNode &cloneNode(XMLNode &newnode, bool deep);
void appendChild(XMLNode *node);
+ void setParent(XMLNode *node) { _parent = node; };
+ XMLNode *getParent() { return _parent; };
void insertBefore(XMLNode *newnode, XMLNode *node);
void removeNode();
@@ -135,6 +124,7 @@
char *_value;
xmlElementType _type;
+ XMLNode *_parent;
std::vector<XMLNode *> _children;
std::vector<XMLAttr *> _attributes;
Index: server/asobj/xmlnode.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlnode.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- server/asobj/xmlnode.cpp 13 Feb 2007 19:36:34 -0000 1.10
+++ server/asobj/xmlnode.cpp 15 Feb 2007 04:05:41 -0000 1.11
@@ -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: xmlnode.cpp,v 1.10 2007/02/13 19:36:34 rsavoye Exp $ */
+/* $Id: xmlnode.cpp,v 1.11 2007/02/15 04:05:41 rsavoye Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -76,7 +76,8 @@
as_object(getXMLNodeInterface()),
_name(0),
_value(0),
- _type(XML_ELEMENT_NODE)
+ _type(XML_ELEMENT_NODE),
+ _parent(0)
{
//log_msg("%s: %p \n", __PRETTY_FUNCTION__, this);
#ifdef DEBUG_MEMORY_ALLOCATION
@@ -124,6 +125,37 @@
// _value.set_undefined();
}
+bool
+XMLNode::hasChildNodes()
+{
+ GNASH_REPORT_FUNCTION;
+ if (_children.size()) {
+ return true;
+ }
+ return false;
+}
+
+XMLNode *
+XMLNode::firstChild()
+{
+ GNASH_REPORT_FUNCTION;
+ if (_children.size() > 0) {
+ return _children.front();
+ }
+ return NULL;
+}
+
+XMLNode *
+XMLNode::lastChild()
+{
+ GNASH_REPORT_FUNCTION;
+
+ if (_children.size() > 0) {
+ return _children.back();
+ }
+ return NULL;
+}
+
void
XMLNode::nodeNameSet(const char *name)
{
@@ -218,6 +250,7 @@
//
if (node) {
+ node->setParent(this);
_children.push_back(node);
}
@@ -269,25 +302,42 @@
}
XMLNode *
-XMLNode::previousSibling(int x)
+XMLNode::previousSibling()
{
-// GNASH_REPORT_FUNCTION;
- log_msg("%s: partially implemented. " SIZET_FMT " objects\n",
- __PRETTY_FUNCTION__, _children.size());
- if (_children.size() > 0) {
- return _children[x-1];
+ GNASH_REPORT_FUNCTION;
+
+ vector<XMLNode *>::iterator itx;
+ XMLNode *node = 0;
+ if (_parent) {
+ if (_parent->_children.size() > 1) {
+ for (itx = _parent->_children.begin(); itx !=
_parent->_children.end(); itx++) {
+ if ((*itx) == this) {
+ // log_msg("Found the previous XMLNode child !!!! %s
<%p>\n", (*itx)->nodeName(), (void*)*itx);
+ return node;
+ }
+ XMLNode *node = *itx;
+ }
+ }
}
return NULL;
}
XMLNode *
-XMLNode::nextSibling(int x)
+XMLNode::nextSibling()
{
GNASH_REPORT_FUNCTION;
- log_msg("%s: unimplemented \n", __PRETTY_FUNCTION__);
- if (x < (int) _children.size()) {
- return _children[x];
+ vector<XMLNode *>::iterator itx;
+ if (_parent) {
+ if (_parent->_children.size() > 1) {
+ for (itx = _parent->_children.begin(); itx !=
_parent->_children.end(); itx++) {
+ if (((*itx++) == this) && (itx != _parent->_children.end())) {
+ XMLNode *node = *itx;
+ // log_msg("Found the previous XMLNode child !!!! %s
<%p>\n", (*itx)->nodeName(), (void*)*itx);
+ return node;
+ }
+ }
+ }
}
return NULL;
}
@@ -456,7 +506,7 @@
// log_msg("%s: %p \n", __PRETTY_FUNCTION__, xml_obj);
int length = ptr->length();
if (length > 0) {
- XMLNode *ass = xml_obj->previousSibling(length); // or is it 'ptr'
??
+ XMLNode *ass = xml_obj->previousSibling(); // or is it 'ptr' ??
// FIXME: This shouldn't always be NULL
// log_msg("%s: ASS is %p, length is %d\n", __PRETTY_FUNCTION__,
// ass, length);
@@ -527,6 +577,7 @@
static void
xmlnode_haschildnodes(const fn_call& fn)
{
+// GNASH_REPORT_FUNCTION;
XMLNode *ptr = (XMLNode*)fn.this_ptr;
assert(ptr);
fn.result->set_bool(ptr->hasChildNodes());
@@ -560,6 +611,7 @@
static void
xmlnode_nodename(const fn_call& fn)
{
+// GNASH_REPORT_FUNCTION;
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
@@ -579,31 +631,26 @@
static void
xmlnode_nodetype(const fn_call& fn)
{
+// GNASH_REPORT_FUNCTION;
+
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
- if ( fn.nargs == 0 ) {
- fn.result->set_double(ptr->nodeType());
- } else {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("Tried to set read-only property XMLNode.nodeType");
- );
- }
+ fn.result->set_int(ptr->nodeType());
}
// Both a getter and a (do-nothing) setter for firstChild
static void
xmlnode_firstchild(const fn_call& fn)
{
+// GNASH_REPORT_FUNCTION;
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
-
- if ( fn.nargs == 0 ) {
- fn.result->set_as_object(ptr->firstChild());
+ XMLNode *node = ptr->firstChild();
+ if (node == NULL) {
+ fn.result->set_null();
} else {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("Tried to set read-only property XMLNode.firstChild");
- );
+ fn.result->set_as_object(node);
}
}
@@ -611,15 +658,14 @@
static void
xmlnode_lastchild(const fn_call& fn)
{
+// GNASH_REPORT_FUNCTION;
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
-
- if ( fn.nargs == 0 ) {
- fn.result->set_as_object(ptr->lastChild());
+ XMLNode *node = ptr->lastChild();
+ if (node == NULL) {
+ fn.result->set_null();
} else {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("Tried to set read-only property XMLNode.lastChild");
- );
+ fn.result->set_as_object(node);
}
}
@@ -627,17 +673,15 @@
static void
xmlnode_nextsibling(const fn_call& fn)
{
+ GNASH_REPORT_FUNCTION;
+
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
-
- if ( fn.nargs == 0 ) {
- log_error("FIXME: XMLNode.nextSibling unimplemented");
- //fn.result->set_as_object(ptr->nextSibling());
+ XMLNode *node = ptr->nextSibling();
+ if (node == NULL) {
fn.result->set_null();
} else {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("Tried to set read-only property XMLNode.nextSibling");
- );
+ fn.result->set_as_object(node);
}
}
@@ -645,23 +689,21 @@
static void
xmlnode_previoussibling(const fn_call& fn)
{
+ GNASH_REPORT_FUNCTION;
assert(dynamic_cast<XMLNode*>(fn.this_ptr));
XMLNode *ptr = static_cast<XMLNode*>(fn.this_ptr);
-
- if ( fn.nargs == 0 ) {
- log_error("FIXME: XMLNode.previousSibling unimplemented");
- //fn.result->set_as_object(ptr->previousSibling());
+ XMLNode *node = ptr->previousSibling();
+ if (node == NULL) {
fn.result->set_null();
} else {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror("Tried to set read-only property
XMLNode.previousSibling");
- );
+ fn.result->set_as_object(node);
}
}
// extern (used by Global.cpp)
void xmlnode_class_init(as_object& global)
{
+// GNASH_REPORT_FUNCTION;
// This is going to be the global XMLNode "class"/"function"
static boost::intrusive_ptr<builtin_function> cl;
Index: testsuite/actionscript.all/XMLNode.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/XMLNode.as,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- testsuite/actionscript.all/XMLNode.as 18 Jan 2007 15:30:53 -0000
1.8
+++ testsuite/actionscript.all/XMLNode.as 15 Feb 2007 04:05:41 -0000
1.9
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -16,26 +16,29 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
-
// Test case for XML ActionScript class
// compile this test case with Ming makeswf, and then
// execute it like this gnash -1 -r 0 -v out.swf
-rcsid="$Id: XMLNode.as,v 1.8 2007/01/18 15:30:53 strk Exp $";
+rcsid="$Id: XMLNode.as,v 1.9 2007/02/15 04:05:41 rsavoye Exp $";
#include "dejagnu.as"
-check(XMLNode);
-var textnode = new XMLNode(3, "text content");
+var doc = new XML();
-check(textnode);
+check(doc);
+var textnode = doc.createTextNode("text content");
+check_equals(typeOf(textnode), 'object');
// test the XMLNode constuctor
//dejagnu(node, "XMLNode::XMLNode()");
//note("Test the existance of all the methods");
+//check_equals(typeOf(myXML.createElement), 'function');
+
+
+
check(textnode.appendChild);
check(textnode.cloneNode);
check(textnode.hasChildNodes);
@@ -63,30 +66,47 @@
//note("Now test the functionality of the methods");
-var childnode1 = new XMLNode(3, "first child");
-check_equals(childnode1.nodeType, 3);
-textnode.appendChild(childnode1);
-
-check_equals(textnode.hasChildNodes(), true);
-check_equals(textnode.firstChild, childnode1);
-check_equals(textnode.lastChild, childnode1);
-check_equals(childnode1.nextSibling, undefined);
-check_equals(childnode1.previousSibling, undefined);
-
-var nextnode = new XMLNode(3, "second child");
-check_equals(nextnode.nodeType, 3);
-textnode.appendChild(nextnode);
-
-check_equals(textnode.hasChildNodes(), true);
-check_equals(textnode.firstChild, childnode1);
-check_equals(textnode.lastChild, nextnode);
-xcheck_equals(childnode1.nextSibling, nextnode);
-check_equals(childnode1.previousSibling, undefined);
-xcheck_equals(nextnode.previousSibling, childnode1);
-//var out = textnode.toString();
-//trace(out);
+var node1 = doc.createElement("node1");
+var node2 = doc.createElement("node2");
+var textnode1 = doc.createTextNode("first text node");
+var textnode2 = doc.createTextNode("second text node");
+check_equals(textnode1.nodeType, 3);
+node1.appendChild(textnode1);
+node2.appendChild(textnode2);
+node1.appendChild(node2);
+check_equals(node1.hasChildNodes(), true);
+
+check_equals(node1.firstChild.nodeValue, "second text node");
+check_equals(node1.lastChild.nodeValue, "second text node");
+xcheck_equals(node2.lastChild, "null"); // FIXME
+
+var node3 = doc.createElement("node3");
+var textnode3 = doc.createTextNode("third text node");
+node3.appendChild(textnode3);
+node1.appendChild(node3);
+
+// trace(node1.toString());
+trace("===========================================");
+
+// trace(node1.firstChild.nodeValue);
+// trace(node1.lastChild.nodeValue);
+check_equals(node1.firstChild.nodeValue, "second text node");
+check_equals(node1.lastChild.nodeValue, "third text node");
+
+trace(node1.lastChild.previousSibling);
+trace(node1.firstChild.nextSibling);
+
+check_equals(node1.firstChild.nodeName, "node2");
+check_equals(node1.lastChild.nodeName, "node3");
+
+xcheck_equals(node2.previousSibling.nodeValue, "second text node");
// TODO: test removeNode, insertNode
+// for (var aNode = node1.firstChild; node1 != null; aNode =
node1.nextSibling) {
+// trace(aNode);
+// }
+
+
totals();
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2362
retrieving revision 1.2363
diff -u -b -r1.2362 -r1.2363
--- ChangeLog 14 Feb 2007 22:48:55 -0000 1.2362
+++ ChangeLog 15 Feb 2007 04:05:42 -0000 1.2363
@@ -1,3 +1,10 @@
+2007-02-14 Rob Savoye <address@hidden>
+
+ * testsuite/actionscript.all/XMLNode.as: Fix tests for newly work
+ XLNode class.
+ * server/asobj/xmlnode.{cpp,h}: Make nextSibling, previousSibling,
+ firstChild, and lastChild work correctly.
+
2007-02-14 Sandro Santilli <address@hidden>
* server/swf/tag_loaders.{cpp,h}: implement serialnumber_loader.
@@ -79,6 +86,10 @@
2007-02-13 Rob Savoye <address@hidden>
+ * configure.ac: Disable dmalloc check for now. Configure
+ extension/fileio directory.
+ * extensions/Makefile.am: Build in the fileio directory.
+
* server/asobj/xmlnode.cpp: Implement toString(). Make appendChild
actually work.
* server/asobj/xml.cpp: Re-implement toString(). Make
- [Gnash-commit] gnash server/asobj/xmlnode.h server/asobj/xmlno...,
Rob Savoye <=