Reviewed by Richard.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Dec 2003 04:05:47 +0000 (04:05 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Dec 2003 04:05:47 +0000 (04:05 +0000)
<rdar://problem/3504049>: XMLSerializer object and serializeToString method needed for XMLHttpRequest testing

Also fixed some lasst-minute mistakes in the DOM serialization
code that was already there.

        * WebCore.pbproj/project.pbxproj:
        * khtml/dom/dom_doc.h:
        * khtml/ecma/Makefile.am:
        * khtml/ecma/kjs_window.cpp:
        (Window::get):
        * khtml/ecma/kjs_window.h:
        (KJS::Window::):
        * khtml/ecma/kjs_window.lut.h:
        (KJS::):
        * khtml/ecma/xmlserializer.cpp: Added.
        (KJS::XMLSerializerConstructorImp::XMLSerializerConstructorImp):
        (KJS::XMLSerializerConstructorImp::implementsConstruct):
        (KJS::XMLSerializerConstructorImp::construct):
        (KJS::):
        (KJS::XMLSerializer::XMLSerializer):
        (KJS::XMLSerializerProtoFunc::tryCall):
        * khtml/ecma/xmlserializer.h: Added.
        (KJS::XMLSerializer::toBoolean):
        (KJS::XMLSerializer::classInfo):
        (KJS::XMLSerializer::):
        * khtml/ecma/xmlserializer.lut.h: Added.
        (KJS::):
        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::toString):
        (DocumentFragmentImpl::toString):
        * khtml/xml/dom_elementimpl.cpp:
        (AttrImpl::toString):
        (ElementImpl::toString):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@5740 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/WebCore.pbproj/project.pbxproj
WebCore/khtml/dom/dom_doc.h
WebCore/khtml/ecma/xmlserializer.cpp [new file with mode: 0644]
WebCore/khtml/ecma/xmlserializer.h [new file with mode: 0644]
WebCore/khtml/ecma/xmlserializer.lut.h [new file with mode: 0644]
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/khtml/xml/dom_elementimpl.cpp

index d794015..9a16884 100644 (file)
@@ -1,3 +1,41 @@
+2003-12-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Richard.
+
+       <rdar://problem/3504049>: XMLSerializer object and serializeToString method needed for XMLHttpRequest testing
+
+       Also fixed some lasst-minute mistakes in the DOM serialization
+       code that was already there.
+       
+        * WebCore.pbproj/project.pbxproj:
+        * khtml/dom/dom_doc.h:
+        * khtml/ecma/Makefile.am:
+        * khtml/ecma/kjs_window.cpp:
+        (Window::get):
+        * khtml/ecma/kjs_window.h:
+        (KJS::Window::):
+        * khtml/ecma/kjs_window.lut.h:
+        (KJS::):
+        * khtml/ecma/xmlserializer.cpp: Added.
+        (KJS::XMLSerializerConstructorImp::XMLSerializerConstructorImp):
+        (KJS::XMLSerializerConstructorImp::implementsConstruct):
+        (KJS::XMLSerializerConstructorImp::construct):
+        (KJS::):
+        (KJS::XMLSerializer::XMLSerializer):
+        (KJS::XMLSerializerProtoFunc::tryCall):
+        * khtml/ecma/xmlserializer.h: Added.
+        (KJS::XMLSerializer::toBoolean):
+        (KJS::XMLSerializer::classInfo):
+        (KJS::XMLSerializer::):
+        * khtml/ecma/xmlserializer.lut.h: Added.
+        (KJS::):
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::toString):
+        (DocumentFragmentImpl::toString):
+        * khtml/xml/dom_elementimpl.cpp:
+        (AttrImpl::toString):
+        (ElementImpl::toString):
+
 2003-12-09  David Hyatt  <hyatt@apple.com>
 
        Implement start() and stop() for marquees.
index ef45d5a..55d7e6f 100644 (file)
                                654E7EE40569FD4600358BD2,
                                654E7EE50569FD4600358BD2,
                                84B2B1F9056BEF3A00D2B771,
+                               65912B110586921000123A69,
+                               65912B120586921000123A69,
                        );
                        isa = PBXHeadersBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                                654E7EE30569FD4600358BD2,
                                84B2B1FA056BEF3A00D2B771,
                                84B2B250056BF15F00D2B771,
+                               65912B100586921000123A69,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        settings = {
                        };
                };
+               65912B0D0586921000123A69 = {
+                       expectedFileType = sourcecode.cpp.cpp;
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       path = xmlserializer.cpp;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               65912B0E0586921000123A69 = {
+                       expectedFileType = sourcecode.c.h;
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       path = xmlserializer.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               65912B0F0586921000123A69 = {
+                       expectedFileType = sourcecode.c.h;
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       path = xmlserializer.lut.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               65912B100586921000123A69 = {
+                       fileRef = 65912B0D0586921000123A69;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               65912B110586921000123A69 = {
+                       fileRef = 65912B0E0586921000123A69;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               65912B120586921000123A69 = {
+                       fileRef = 65912B0F0586921000123A69;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                65A640F00533BB1F0085E777 = {
                        expectedFileType = sourcecode.c.h;
                        fileEncoding = 30;
                                654E7EE00569FD4600358BD2,
                                654E7EE10569FD4600358BD2,
                                654E7EE20569FD4600358BD2,
+                               65912B0D0586921000123A69,
+                               65912B0E0586921000123A69,
+                               65912B0F0586921000123A69,
                        );
                        isa = PBXGroup;
                        path = ecma;
index e1dbc22..b8b333e 100644 (file)
@@ -790,9 +790,10 @@ public:
     DOMString completeURL(const DOMString& url);
 
     DOMString toString() const;
-protected:
+
     Document( DocumentImpl *i);
 
+protected:
     friend class Node;
 };
 
diff --git a/WebCore/khtml/ecma/xmlserializer.cpp b/WebCore/khtml/ecma/xmlserializer.cpp
new file mode 100644 (file)
index 0000000..e096f91
--- /dev/null
@@ -0,0 +1,115 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ *  This file is part of the KDE libraries
+ *  Copyright (C) 2003 Apple Computer, Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "xmlserializer.h"
+#include "xmlserializer.lut.h"
+
+#include "dom/dom_exception.h"
+#include "dom/dom_doc.h"
+#include "xml/dom_docimpl.h"
+
+#include <kdebug.h>
+
+using namespace KJS;
+
+////////////////////// XMLSerializer Object ////////////////////////
+
+/* Source for XMLSerializerProtoTable.
+@begin XMLSerializerProtoTable 1
+  serializeToString XMLSerializer::SerializeToString DontDelete|Function 1
+@end
+*/
+DEFINE_PROTOTYPE("XMLSerializer",XMLSerializerProto)
+IMPLEMENT_PROTOFUNC(XMLSerializerProtoFunc)
+IMPLEMENT_PROTOTYPE(XMLSerializerProto,XMLSerializerProtoFunc)
+
+namespace KJS {
+
+XMLSerializerConstructorImp::XMLSerializerConstructorImp(ExecState *)
+    : ObjectImp()
+{
+}
+
+bool XMLSerializerConstructorImp::implementsConstruct() const
+{
+  return true;
+}
+
+Object XMLSerializerConstructorImp::construct(ExecState *exec, const List &)
+{
+  return Object(new XMLSerializer(exec));
+}
+
+const ClassInfo XMLSerializer::info = { "XMLSerializer", 0, &XMLSerializerTable, 0 };
+
+/* Source for XMLSerializerTable.
+@begin XMLSerializerTable 0
+@end
+*/
+
+XMLSerializer::XMLSerializer(ExecState *exec)
+  : DOMObject(XMLSerializerProto::self(exec))
+{
+}
+
+Value XMLSerializerProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
+{
+  if (!thisObj.inherits(&XMLSerializer::info)) {
+    Object err = Error::create(exec,TypeError);
+    exec->setException(err);
+    return err;
+  }
+
+  switch (id) {
+  case XMLSerializer::SerializeToString:
+    {
+      if (args.size() != 1) {
+       return Undefined();
+      }
+
+      if (!args[0].toObject(exec).inherits(&DOMDocument::info)) {
+       return Undefined();
+      }
+
+      DOM::Node docNode = static_cast<KJS::DOMDocument *>(args[0].toObject(exec).imp())->toNode();
+      DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(docNode.handle());
+
+      if (!doc) {
+       return Undefined();
+      }
+         
+      QString body;
+
+      try {
+         body = doc->toString().string();
+      } catch(DOM::DOMException& e) {
+         Object err = Error::create(exec, GeneralError, "Exception serializing document");
+         exec->setException(err);
+         return err;
+      }
+    
+      return getStringOrNull(body);
+    }
+  }
+
+  return Undefined();
+}
+
+}; // end namespace
diff --git a/WebCore/khtml/ecma/xmlserializer.h b/WebCore/khtml/ecma/xmlserializer.h
new file mode 100644 (file)
index 0000000..5217251
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ *  This file is part of the KDE libraries
+ *  Copyright (C) 2003 Apple Computer, Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _XMLSERIALIZER_H_
+#define _XMLSERIALIZER_H_
+
+#include "ecma/kjs_binding.h"
+#include "ecma/kjs_dom.h"
+#include "misc/decoder.h"
+#include "kio/jobclasses.h"
+
+namespace KJS {
+
+  class JSEventListener;
+
+  class XMLSerializerConstructorImp : public ObjectImp {
+  public:
+    XMLSerializerConstructorImp(ExecState *);
+    virtual bool implementsConstruct() const;
+    virtual Object construct(ExecState *exec, const List &args);
+  };
+
+  class XMLSerializer : public DOMObject {
+  public:
+    XMLSerializer(ExecState *);
+    virtual bool toBoolean(ExecState *) const { return true; }
+    virtual const ClassInfo* classInfo() const { return &info; }
+    static const ClassInfo info;
+    enum { SerializeToString };
+
+  private:
+    friend class XMLSerializerProtoFunc;
+  };
+
+}; // namespace
+
+#endif
diff --git a/WebCore/khtml/ecma/xmlserializer.lut.h b/WebCore/khtml/ecma/xmlserializer.lut.h
new file mode 100644 (file)
index 0000000..c80b36e
--- /dev/null
@@ -0,0 +1,20 @@
+/* Automatically generated from xmlserializer.cpp using ../../../JavaScriptCore/kjs/create_hash_table. DO NOT EDIT ! */
+
+namespace KJS {
+
+const struct HashEntry XMLSerializerProtoTableEntries[] = {
+   { "serializeToString", XMLSerializer::SerializeToString, DontDelete|Function, 1, 0 }
+};
+
+const struct HashTable XMLSerializerProtoTable = { 2, 1, XMLSerializerProtoTableEntries, 1 };
+
+} // namespace
+
+namespace KJS {
+
+const struct HashEntry XMLSerializerTableEntries[] = {
+};
+
+const struct HashTable XMLSerializerTable = { 2, 0, XMLSerializerTableEntries, 0 };
+
+} // namespace
index 9c6a65e..757d680 100644 (file)
@@ -2594,7 +2594,7 @@ DOMString DocumentImpl::toString() const
     DOMString result;
 
     for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
-       child = child->nextSibling();
+       result += child->toString();
     }
 
     return result;
@@ -2645,7 +2645,7 @@ DOMString DocumentFragmentImpl::toString() const
     DOMString result;
 
     for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
-       child = child->nextSibling();
+       result += child->toString();
     }
 
     return result;
index 2118834..33c8cd5 100644 (file)
@@ -168,7 +168,7 @@ DOMString AttrImpl::toString() const
        result += "=\"";
 
        for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
-           child = child->nextSibling();
+           result += child->toString();
        }
        
        result += "\"";
@@ -557,7 +557,7 @@ DOMString ElementImpl::toString() const
        result += ">";
 
        for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
-           child = child->nextSibling();
+           result += child->toString();
        }
 
        result += "</";