Reviewed by John Sullivan.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Aug 2005 17:12:16 +0000 (17:12 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Aug 2005 17:12:16 +0000 (17:12 +0000)
        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4551
          implement exceptions for a few XML-specific Document DOM functions

        * khtml/xml/dom_docimpl.h: Added exception codes to the three functions in question.
        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::createCDATASection): Added exception parameter. Give NOT_SUPPORTED_ERR if the
        document is an HTML document.
        (DocumentImpl::createProcessingInstruction): Added exception parameter. Give INVALID_CHARACTER_ERR
        if target's name is not valid, NOT_SUPPORTED_ERR if the document is an HTML document.
        (DocumentImpl::createEntityReference): Ditto, with entity's name.
        (DocumentImpl::importNode): Pass exception parameter in so we get exceptions in this case too.
        (DocumentImpl::isValidName): Added comment with the specification's rules for valid names.

        * khtml/ecma/kjs_dom.cpp: (KJS::DOMDocumentProtoFunc::callAsFunction): Translate exceptions now
        that the three functions have them.
        * kwq/DOM.mm:
        (-[DOMDocument createCDATASection:]): Ditto.
        (-[DOMDocument createProcessingInstruction::]): Ditto.
        (-[DOMDocument createEntityReference:]): Ditto.

        * khtml/xml/dom_textimpl.cpp: (CDATASectionImpl::cloneNode): Ignore exception. It can never happen
        since name is guaranteed to be valid and document is guaranteed to not be HTML document.

        * khtml/xml/xml_tokenizer.cpp:
        (khtml::XMLTokenizer::processingInstruction): Added code to handle exception.
        (khtml::XMLTokenizer::cdataBlock): Ditto.

        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref-expected.txt: Now succeeds.
        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref1-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi1-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/hc_attrappendchild4-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/hc_attrgetvalue2-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore5-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore7-expected.txt: Ditto.
        * layout-tests/dom/html/level1/core/hc_nodevalue03-expected.txt: Ditto.

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

16 files changed:
LayoutTests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref-expected.txt
LayoutTests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref1-expected.txt
LayoutTests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi-expected.txt
LayoutTests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrappendchild4-expected.txt
LayoutTests/dom/html/level1/core/hc_attrgetvalue2-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore5-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore7-expected.txt
LayoutTests/dom/html/level1/core/hc_nodevalue03-expected.txt
WebCore/ChangeLog-2005-12-19
WebCore/khtml/ecma/kjs_dom.cpp
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/khtml/xml/dom_docimpl.h
WebCore/khtml/xml/dom_textimpl.cpp
WebCore/khtml/xml/xml_tokenizer.cpp
WebCore/kwq/DOM.mm

index e379f7b12d7d0224ef325b88181eff311a6f40ed..12a8e466124b18ff4c5b647eabfa7701544d81d7 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref 
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref
+Status:        Success
index bbf95dc44eb0a888eb4be522abdca6f1559a95fc..49aebe404478d8b025b51c6ae3c3665d5a370391 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref1        
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreateentref1
+Status:        Success
index 6627d8f83569e03bff196fca76552c775961be23..b8a92eb209454cdd273ac918a18528254867193b 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi     
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi
+Status:        Success
index 5d052e9ec12f780e5651245562d9121d1847d8bc..d23ea1c255cf6b85d381a84bc4c9cd748eb92548 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi1    
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi1
+Status:        Success
index 88c224cfa0108c6a5d219c77243df2a5511a2652..629c052426c0d4177e793249da84d3a042c1a7c0 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild4   
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild4
+Status:        Success
index 3a0d1085838a26a375747639d751efeafa6dd391..c1082cbeae4f6d88dfd064edb4c2d9aab9615c3d 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrgetvalue2      
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrgetvalue2
+Status:        Success
index a5c1982bb6807e23a92841237421dacd8d011432..87b5b69437fb5f34073d044e4a6feb033cf502d3 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore5  
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore5
+Status:        Success
index 482b1fe795d42bc0664e196504be005b7fa64ffc..880ed5c603e6314b12dd7fbf3590b641cea16e8f 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore7  
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore7
+Status:        Success
index 3e6651a4651b6374035659a2fe608ac970c17131..c70c7c3db1dfe78d87a51c4bad116d29838f1c0e 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodevalue03        
-Status:        failure
-Detail:        throw_NOT_SUPPORTED_ERR: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodevalue03
+Status:        Success
index 3a3db7165159f8f3446749f1c37911210e817394..3b48490a2e5968846cb380027134b1a315b878e9 100644 (file)
@@ -1,3 +1,44 @@
+2005-08-25  Darin Adler  <darin@apple.com>
+
+        Reviewed by John Sullivan.
+
+        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4551
+          implement exceptions for a few XML-specific Document DOM functions
+
+        * khtml/xml/dom_docimpl.h: Added exception codes to the three functions in question.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::createCDATASection): Added exception parameter. Give NOT_SUPPORTED_ERR if the
+        document is an HTML document.
+        (DocumentImpl::createProcessingInstruction): Added exception parameter. Give INVALID_CHARACTER_ERR
+        if target's name is not valid, NOT_SUPPORTED_ERR if the document is an HTML document.
+        (DocumentImpl::createEntityReference): Ditto, with entity's name.
+        (DocumentImpl::importNode): Pass exception parameter in so we get exceptions in this case too.
+        (DocumentImpl::isValidName): Added comment with the specification's rules for valid names.
+
+        * khtml/ecma/kjs_dom.cpp: (KJS::DOMDocumentProtoFunc::callAsFunction): Translate exceptions now
+        that the three functions have them.
+        * kwq/DOM.mm:
+        (-[DOMDocument createCDATASection:]): Ditto.
+        (-[DOMDocument createProcessingInstruction::]): Ditto.
+        (-[DOMDocument createEntityReference:]): Ditto.
+
+        * khtml/xml/dom_textimpl.cpp: (CDATASectionImpl::cloneNode): Ignore exception. It can never happen
+        since name is guaranteed to be valid and document is guaranteed to not be HTML document.
+
+        * khtml/xml/xml_tokenizer.cpp:
+        (khtml::XMLTokenizer::processingInstruction): Added code to handle exception.
+        (khtml::XMLTokenizer::cdataBlock): Ditto.
+
+        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref-expected.txt: Now succeeds.
+        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreateentref1-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/documentinvalidcharacterexceptioncreatepi1-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/hc_attrappendchild4-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/hc_attrgetvalue2-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore5-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore7-expected.txt: Ditto.
+        * layout-tests/dom/html/level1/core/hc_nodevalue03-expected.txt: Ditto.
+
 2005-08-25  Eric Seidel  <eseidel@apple.com>
 
         No review, buildfix affecting SVG only.
index 8f0594d8e611f5aa77ad904023ace83f39160b3d..64ccc02f04ef0606824fc82563faf4b1c5edb12f 100644 (file)
@@ -1015,14 +1015,14 @@ ValueImp *DOMDocumentProtoFunc::callAsFunction(ExecState *exec, ObjectImp *thisO
   case DOMDocument::CreateComment:
     return getDOMNode(exec,doc.createComment(s));
   case DOMDocument::CreateCDATASection:
-    return getDOMNode(exec,doc.createCDATASection(s));  /* TODO: okay ? */
+    return getDOMNode(exec, doc.createCDATASection(s, exception));
   case DOMDocument::CreateProcessingInstruction:
-    return getDOMNode(exec,doc.createProcessingInstruction(args[0]->toString(exec).string(),
-                                                                 args[1]->toString(exec).string()));
+    return getDOMNode(exec, doc.createProcessingInstruction(args[0]->toString(exec).string(),
+        args[1]->toString(exec).string(), exception));
   case DOMDocument::CreateAttribute:
     return getDOMNode(exec,doc.createAttribute(s, exception));
   case DOMDocument::CreateEntityReference:
-    return getDOMNode(exec,doc.createEntityReference(s));
+    return getDOMNode(exec, doc.createEntityReference(s, exception));
   case DOMDocument::ElementFromPoint:
     return getDOMNode(exec,doc.elementFromPoint((int)args[0]->toNumber(exec), (int)args[1]->toNumber(exec)));
   case DOMDocument::GetElementsByTagName:
index 32a80aa0d0daccb555c8d7ec248fa7033e7590e7..da3117979b1cfafa565e57913c79214f4779385b 100644 (file)
@@ -519,18 +519,38 @@ CommentImpl *DocumentImpl::createComment ( const DOMString &data )
     return new CommentImpl( docPtr(), data );
 }
 
-CDATASectionImpl *DocumentImpl::createCDATASection ( const DOMString &data )
+CDATASectionImpl *DocumentImpl::createCDATASection(const DOMString &data, int &exception)
 {
-    return new CDATASectionImpl( docPtr(), data );
+    if (isHTMLDocument()) {
+        exception = DOMException::NOT_SUPPORTED_ERR;
+        return NULL;
+    }
+    return new CDATASectionImpl(docPtr(), data);
 }
 
-ProcessingInstructionImpl *DocumentImpl::createProcessingInstruction ( const DOMString &target, const DOMString &data )
+ProcessingInstructionImpl *DocumentImpl::createProcessingInstruction(const DOMString &target, const DOMString &data, int &exception)
 {
-    return new ProcessingInstructionImpl( docPtr(),target,data);
+    if (!isValidName(target)) {
+        exception = DOMException::INVALID_CHARACTER_ERR;
+        return NULL;
+    }
+    if (isHTMLDocument()) {
+        exception = DOMException::NOT_SUPPORTED_ERR;
+        return NULL;
+    }
+    return new ProcessingInstructionImpl(docPtr(),target,data);
 }
 
-EntityReferenceImpl *DocumentImpl::createEntityReference ( const DOMString &name )
+EntityReferenceImpl *DocumentImpl::createEntityReference(const DOMString &name, int &exception)
 {
+    if (!isValidName(name)) {
+        exception = DOMException::INVALID_CHARACTER_ERR;
+        return NULL;
+    }
+    if (isHTMLDocument()) {
+        exception = DOMException::NOT_SUPPORTED_ERR;
+        return NULL;
+    }
     return new EntityReferenceImpl(docPtr(), name.implementation());
 }
 
@@ -552,11 +572,11 @@ NodeImpl *DocumentImpl::importNode(NodeImpl *importedNode, bool deep, int &excep
         case Node::TEXT_NODE:
             return createTextNode(importedNode->nodeValue());
         case Node::CDATA_SECTION_NODE:
-            return createCDATASection(importedNode->nodeValue());
+            return createCDATASection(importedNode->nodeValue(), exceptioncode);
         case Node::ENTITY_REFERENCE_NODE:
-            return createEntityReference(importedNode->nodeName());
+            return createEntityReference(importedNode->nodeName(), exceptioncode);
         case Node::PROCESSING_INSTRUCTION_NODE:
-            return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue());
+            return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), exceptioncode);
         case Node::COMMENT_NODE:
             return createComment(importedNode->nodeValue());
         case Node::ELEMENT_NODE: {
@@ -2552,6 +2572,21 @@ void DocumentImpl::setDomain(const DOMString &newDomain, bool force /*=false*/)
 
 bool DocumentImpl::isValidName(const DOMString &name)
 {
+    // DOM Level 2 says:
+    //
+    // Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.
+    // Name characters other than Name-start characters must have one of the categories Mc, Me, Mn, Lm, or Nd.
+    // Characters in the compatibility area (i.e. with character code greater than #xF900 and less than #xFFFE) are not allowed in XML names.
+    // Characters which have a font or compatibility decomposition (i.e. those with a "compatibility formatting tag" in field 5 of the database -- marked by field 5 beginning with a "<") are not allowed.
+    // The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6.
+    // Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14).
+    // Character #x00B7 is classified as an extender, because the property list so identifies it.
+    // Character #x0387 is added as a name character, because #x00B7 is its canonical equivalent.
+    // Characters ':' and '_' are allowed as name-start characters.
+    // Characters '-' and '.' are allowed as name characters.
+    //
+    // FIXME: Implement the above!
+
     static const char validFirstCharacter[] = "ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz";
     static const char validSubsequentCharacter[] = "ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz0123456789-_:.";
     const unsigned length = name.length();
index be7295053ef900194b1ff70756c78db899c71a48..0569cc958b8035542703794649cc55d6e89c4577 100644 (file)
@@ -181,11 +181,11 @@ public:
     DocumentFragmentImpl *createDocumentFragment ();
     TextImpl *createTextNode ( const DOMString &data );
     CommentImpl *createComment ( const DOMString &data );
-    CDATASectionImpl *createCDATASection ( const DOMString &data );
-    ProcessingInstructionImpl *createProcessingInstruction ( const DOMString &target, const DOMString &data );
+    CDATASectionImpl *createCDATASection(const DOMString &data, int &exception);
+    ProcessingInstructionImpl *createProcessingInstruction(const DOMString &target, const DOMString &data, int &exception);
     AttrImpl *createAttribute(const DOMString &name, int &exception) { return createAttributeNS(DOMString(), name, exception); }
     AttrImpl *createAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, int &exception);
-    EntityReferenceImpl *createEntityReference ( const DOMString &name );
+    EntityReferenceImpl *createEntityReference(const DOMString &name, int &exceptionCode);
     NodeImpl *importNode( NodeImpl *importedNode, bool deep, int &exceptioncode );
     virtual ElementImpl *createElementNS(const DOMString &_namespaceURI, const DOMString &_qualifiedName, int &exceptioncode);
     ElementImpl *getElementById ( const DOMString &elementId ) const;
index c40b14119c387c49012c49c695182023650ab178..aa6688e8df37f31bd8a15b709ea1f759951324a9 100644 (file)
@@ -545,7 +545,8 @@ unsigned short CDATASectionImpl::nodeType() const
 
 NodeImpl *CDATASectionImpl::cloneNode(bool /*deep*/)
 {
-    return getDocument()->createCDATASection(str);
+    int ignoreException = 0;
+    return getDocument()->createCDATASection(str, ignoreException);
 }
 
 // DOM Section 1.1.1
index 405cfc6f97c9dd549ab5315582f8423baaa4f231..472c9a04787a249fad04f7d97a5519a1983f4f7f 100644 (file)
@@ -480,10 +480,16 @@ void XMLTokenizer::processingInstruction(const xmlChar *target, const xmlChar *d
 
     if (m_currentNode->nodeType() == Node::TEXT_NODE)
         exitText();
+    
     // ### handle exceptions
+    int exception = 0;
     ProcessingInstructionImpl *pi = m_doc->document()->createProcessingInstruction(
         QString::fromUtf8(reinterpret_cast<const char *>(target)),
-        QString::fromUtf8(reinterpret_cast<const char *>(data)));
+        QString::fromUtf8(reinterpret_cast<const char *>(data)),
+        exception);
+    if (exception)
+        return;
+
     m_currentNode->addChild(pi);
     // don't load stylesheets for standalone documents
     if (m_doc->document()->part()) {
@@ -503,7 +509,8 @@ void XMLTokenizer::cdataBlock(const xmlChar *s, int len)
     if (m_currentNode->nodeType() == Node::TEXT_NODE)
         exitText();
 
-    NodeImpl *newNode = m_doc->document()->createCDATASection("");
+    int ignoreException = 0;
+    NodeImpl *newNode = m_doc->document()->createCDATASection("", ignoreException);
     if (m_currentNode->addChild(newNode)) {
         if (m_view && !newNode->attached())
             newNode->attach();
index 2a77e9c54039a5b16bb39d9331b52af5560cf0c8..2980e6bc42447cd146421c5f53c73c71b88d38b8 100644 (file)
@@ -953,26 +953,25 @@ using khtml::SharedPtr;
 - (DOMCDATASection *)createCDATASection:(NSString *)data
 {
     ASSERT(data);
-
-    // Documentation says we can raise a NOT_SUPPORTED_ERR.
-    // However, the lower layer does not report that error up to us.
-    return static_cast<DOMCDATASection *>([DOMNode _nodeWithImpl:[self _documentImpl]->createCDATASection(data)]);
+    int exception = 0;
+    DOMCDATASection *result = static_cast<DOMCDATASection *>([DOMNode _nodeWithImpl:[self _documentImpl]->createCDATASection(data, exception)]);
+    raiseOnDOMError(exception);
+    return result;
 }
 
 - (DOMProcessingInstruction *)createProcessingInstruction:(NSString *)target :(NSString *)data
 {
     ASSERT(target);
     ASSERT(data);
-
-    // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
-    // However, the lower layer does not report these errors up to us.
-    return static_cast<DOMProcessingInstruction *>([DOMNode _nodeWithImpl:[self _documentImpl]->createProcessingInstruction(target, data)]);
+    int exception = 0;
+    DOMProcessingInstruction *result = static_cast<DOMProcessingInstruction *>([DOMNode _nodeWithImpl:[self _documentImpl]->createProcessingInstruction(target, data, exception)]);
+    raiseOnDOMError(exception);
+    return result;
 }
 
 - (DOMAttr *)createAttribute:(NSString *)name
 {
     ASSERT(name);
-
     int exception = 0;
     DOMAttr *result = [DOMAttr _attrWithImpl:[self _documentImpl]->createAttribute(name, exception)];
     raiseOnDOMError(exception);
@@ -982,10 +981,10 @@ using khtml::SharedPtr;
 - (DOMEntityReference *)createEntityReference:(NSString *)name
 {
     ASSERT(name);
-
-    // Documentation says we can raise a INVALID_CHARACTER_ERR or a NOT_SUPPORTED_ERR.
-    // However, the lower layer does not report these errors up to us.
-    return static_cast<DOMEntityReference *>([DOMNode _nodeWithImpl:[self _documentImpl]->createEntityReference(name)]);
+    int exception = 0;
+    DOMEntityReference *result = static_cast<DOMEntityReference *>([DOMNode _nodeWithImpl:[self _documentImpl]->createEntityReference(name, exception)]);
+    raiseOnDOMError(exception);
+    return result;
 }
 
 - (DOMNodeList *)getElementsByTagName:(NSString *)tagname