Reviewed by Darin.
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2007 04:26:11 +0000 (04:26 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2007 04:26:11 +0000 (04:26 +0000)
        Fix a bunch of cases where the exception code is checked by the function but is not zeroed first.

        * bindings/js/kjs_binding.cpp:
        (KJS::setDOMException):
        * dom/Attr.cpp:
        (WebCore::Attr::setPrefix):
        * dom/Document.cpp:
        (WebCore::Document::createElement):
        * dom/Element.cpp:
        (WebCore::Element::setPrefix):
        * dom/Range.cpp:
        (WebCore::Range::setStart):
        (WebCore::Range::setEnd):
        (WebCore::Range::isPointInRange):
        (WebCore::Range::comparePoint):
        (WebCore::Range::compareBoundaryPoints):
        (WebCore::Range::deleteContents):
        (WebCore::Range::processContents):
        (WebCore::Range::extractContents):
        (WebCore::Range::insertNode):
        (WebCore::Range::setStartAfter):
        (WebCore::Range::setEndBefore):
        (WebCore::Range::setEndAfter):
        (WebCore::Range::selectNode):
        (WebCore::Range::surroundContents):
        (WebCore::Range::setStartBefore):
        * editing/TextIterator.cpp:
        (WebCore::TextIterator::TextIterator):
        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::createPattern):
        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::play):
        (WebCore::HTMLMediaElement::pause):
        * html/HTMLSelectElement.cpp:
        (WebCore::HTMLSelectElement::add):
        (WebCore::HTMLSelectElement::setOption):
        * xml/XPathEvaluator.cpp:
        (WebCore::XPathEvaluator::evaluate):

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

WebCore/ChangeLog
WebCore/bindings/js/kjs_binding.cpp
WebCore/dom/Attr.cpp
WebCore/dom/Document.cpp
WebCore/dom/Element.cpp
WebCore/dom/Range.cpp
WebCore/editing/TextIterator.cpp
WebCore/html/CanvasRenderingContext2D.cpp
WebCore/html/HTMLMediaElement.cpp
WebCore/html/HTMLSelectElement.cpp
WebCore/xml/XPathEvaluator.cpp

index 65904122223168c646e2d91a2d1f4d793abd43f5..7c6511dcd0f3e2bf185cdfb1c32c54903513b2cc 100644 (file)
@@ -1,3 +1,46 @@
+2007-11-11  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+
+        Fix a bunch of cases where the exception code is checked by the function but is not zeroed first.
+
+        * bindings/js/kjs_binding.cpp:
+        (KJS::setDOMException):
+        * dom/Attr.cpp:
+        (WebCore::Attr::setPrefix):
+        * dom/Document.cpp:
+        (WebCore::Document::createElement):
+        * dom/Element.cpp:
+        (WebCore::Element::setPrefix):
+        * dom/Range.cpp:
+        (WebCore::Range::setStart):
+        (WebCore::Range::setEnd):
+        (WebCore::Range::isPointInRange):
+        (WebCore::Range::comparePoint):
+        (WebCore::Range::compareBoundaryPoints):
+        (WebCore::Range::deleteContents):
+        (WebCore::Range::processContents):
+        (WebCore::Range::extractContents):
+        (WebCore::Range::insertNode):
+        (WebCore::Range::setStartAfter):
+        (WebCore::Range::setEndBefore):
+        (WebCore::Range::setEndAfter):
+        (WebCore::Range::selectNode):
+        (WebCore::Range::surroundContents):
+        (WebCore::Range::setStartBefore):
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::TextIterator):
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::createPattern):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::play):
+        (WebCore::HTMLMediaElement::pause):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::add):
+        (WebCore::HTMLSelectElement::setOption):
+        * xml/XPathEvaluator.cpp:
+        (WebCore::XPathEvaluator::evaluate):
+
 2007-11-11  Darin Adler  <darin@apple.com>
 
         Reviewed by Mitz.
index eb27fa989439423710394f2fbf272e9e7f9fd216..0e186a2bb6f38c7b48b85697c8dd67d4fe7080f6 100644 (file)
@@ -402,7 +402,7 @@ static const char* const svgExceptionNames[] = {
 
 void setDOMException(ExecState* exec, ExceptionCode ec)
 {
-    if (ec == 0 || exec->hadException())
+    if (!ec || exec->hadException())
         return;
 
     const char* type = "DOM";
index 5573cc367f34d8ed3873270232ea445f570e9bfd..866c6d5d10907e3278cd26e812403761edf483ea 100644 (file)
@@ -88,6 +88,7 @@ const AtomicString& Attr::prefix() const
 
 void Attr::setPrefix(const AtomicString &_prefix, ExceptionCode& ec)
 {
+    ec = 0;
     checkSetPrefix(_prefix, ec);
     if (ec)
         return;
index de8d4e84da85c4a89ed15879e421800d65fb02fc..2437c8984d9bba10fc20c6a05b426b53830e9ecb 100644 (file)
@@ -711,6 +711,7 @@ PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool cre
         e = new Element(qName, document());
     
     if (e && !qName.prefix().isNull()) {
+        ec = 0;
         e->setPrefix(qName.prefix(), ec);
         if (ec)
             return 0;
index d16e5ba4ace71ac1de5f01bd6c0760fd6aac522a..3df69f094815352a6490f86be0e2f077d0d686be 100644 (file)
@@ -550,6 +550,7 @@ String Element::nodeNamePreservingCase() const
 
 void Element::setPrefix(const AtomicString &_prefix, ExceptionCode& ec)
 {
+    ec = 0;
     checkSetPrefix(_prefix, ec);
     if (ec)
         return;
index 3fe5f71eed3bc6ce86c98eee945610bb6d9326c4..2fb23cfcddf8010aa766391f19bae413752c39b0 100644 (file)
@@ -213,7 +213,8 @@ void Range::setStart( Node *refNode, int offset, ExceptionCode& ec)
         return;
     }
 
-    checkNodeWOffset( refNode, offset, ec );
+    ec = 0;
+    checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return;
 
@@ -251,7 +252,8 @@ void Range::setEnd( Node *refNode, int offset, ExceptionCode& ec)
         return;
     }
 
-    checkNodeWOffset( refNode, offset, ec );
+    ec = 0;
+    checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return;
 
@@ -310,11 +312,11 @@ bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec)
         return false;
     }
 
+    ec = 0;
     checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return false;
 
-
     // point is not before the start and not after the end
     if ((compareBoundaryPoints(refNode, offset, m_startContainer.get(), m_startOffset) != -1) && 
         (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) != 1))
@@ -349,6 +351,7 @@ short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec)
         return 0;
     }
 
+    ec = 0;
     checkNodeWOffset(refNode, offset, ec);
     if (ec)
         return 0;
@@ -426,7 +429,10 @@ short Range::compareBoundaryPoints(CompareHow how, const Range *sourceRange, Exc
         return 0;
     }
 
+    ec = 0;
     Node *thisCont = commonAncestorContainer(ec);
+    if (ec)
+        return 0;
     Node *sourceCont = sourceRange->commonAncestorContainer(ec);
     if (ec)
         return 0;
@@ -575,6 +581,7 @@ void Range::deleteContents(ExceptionCode& ec) {
         return;
     }
 
+    ec = 0;
     checkDeleteExtract(ec);
     if (ec)
         return;
@@ -626,6 +633,7 @@ PassRefPtr<DocumentFragment> Range::processContents ( ActionType action, Excepti
 
     // ### perhaps disable node deletion notification for this range while we do this?
 
+    ec = 0;
     if (collapsed(ec))
         return 0;
     if (ec)
@@ -951,6 +959,7 @@ PassRefPtr<DocumentFragment> Range::extractContents(ExceptionCode& ec)
         return 0;
     }
 
+    ec = 0;
     checkDeleteExtract(ec);
     if (ec)
         return 0;
@@ -1045,16 +1054,15 @@ void Range::insertNode(PassRefPtr<Node> newNode, ExceptionCode& ec)
         return;
     }
 
-    if( m_startContainer->nodeType() == Node::TEXT_NODE ||
-        m_startContainer->nodeType() == Node::CDATA_SECTION_NODE )
-    {
-        Text *newText = static_cast<Text*>(m_startContainer.get())->splitText(m_startOffset,ec);
+    if(m_startContainer->nodeType() == Node::TEXT_NODE ||
+       m_startContainer->nodeType() == Node::CDATA_SECTION_NODE) {
+        ec = 0;
+        Text *newText = static_cast<Text*>(m_startContainer.get())->splitText(m_startOffset, ec);
         if (ec)
             return;
-        m_startContainer->parentNode()->insertBefore( newNode, newText, ec );
-    }
-    else {
-        m_startContainer->insertBefore( newNode, m_startContainer->childNode( m_startOffset ), ec );
+        m_startContainer->parentNode()->insertBefore(newNode, newText, ec);
+    } else {
+        m_startContainer->insertBefore(newNode, m_startContainer->childNode(m_startOffset), ec);
     }
 }
 
@@ -1221,11 +1229,12 @@ void Range::setStartAfter( Node *refNode, ExceptionCode& ec)
         return;
     }
 
+    ec = 0;
     checkNodeBA( refNode, ec );
     if (ec)
         return;
 
-    setStart( refNode->parentNode(), refNode->nodeIndex()+1, ec );
+    setStart(refNode->parentNode(), refNode->nodeIndex() + 1, ec);
 }
 
 void Range::setEndBefore( Node *refNode, ExceptionCode& ec)
@@ -1245,11 +1254,12 @@ void Range::setEndBefore( Node *refNode, ExceptionCode& ec)
         return;
     }
 
-    checkNodeBA( refNode, ec );
+    ec = 0;
+    checkNodeBA(refNode, ec);
     if (ec)
         return;
 
-    setEnd( refNode->parentNode(), refNode->nodeIndex(), ec );
+    setEnd(refNode->parentNode(), refNode->nodeIndex(), ec);
 }
 
 void Range::setEndAfter( Node *refNode, ExceptionCode& ec)
@@ -1269,11 +1279,12 @@ void Range::setEndAfter( Node *refNode, ExceptionCode& ec)
         return;
     }
 
-    checkNodeBA( refNode, ec );
+    ec = 0;
+    checkNodeBA(refNode, ec);
     if (ec)
         return;
 
-    setEnd( refNode->parentNode(), refNode->nodeIndex()+1, ec );
+    setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, ec);
 
 }
 
@@ -1313,6 +1324,7 @@ void Range::selectNode( Node *refNode, ExceptionCode& ec)
         return;
     }
 
+    ec = 0;
     setStartBefore( refNode, ec );
     if (ec)
         return;
@@ -1422,6 +1434,7 @@ void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
         }
     }
 
+    ec = 0;
     while (Node* n = newParent->firstChild()) {
         newParent->removeChild(n, ec);
         if (ec)
@@ -1456,11 +1469,12 @@ void Range::setStartBefore( Node *refNode, ExceptionCode& ec)
         return;
     }
 
-    checkNodeBA( refNode, ec );
+    ec = 0;
+    checkNodeBA(refNode, ec);
     if (ec)
         return;
 
-    setStart( refNode->parentNode(), refNode->nodeIndex(), ec );
+    setStart(refNode->parentNode(), refNode->nodeIndex(), ec);
 }
 
 void Range::checkDeleteExtract(ExceptionCode& ec)
index 2b827b0ca4775db9df03ee80f89ab613f29b3d53..da9295913d9d115af6c862f0ffa7c2fa6e6812c7 100644 (file)
@@ -94,7 +94,7 @@ TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisibleP
     int startOffset = r->startOffset(ec);
     Node *endContainer = r->endContainer(ec);
     int endOffset = r->endOffset(ec);
-    if (ec != 0)
+    if (ec)
         return;
 
     // Callers should be handing us well-formed ranges. If we discover that this isn't
index 4a88430359891e693602ca2e4599900faf9b9647..d6f39d429e754bfed6acf69c622d593a2fc80c44 100644 (file)
@@ -1047,6 +1047,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
     const String& repetitionType, ExceptionCode& ec)
 {
     bool repeatX, repeatY;
+    ec = 0;
     CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
     if (ec)
         return 0;
@@ -1057,6 +1058,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElem
     const String& repetitionType, ExceptionCode& ec)
 {
     bool repeatX, repeatY;
+    ec = 0;
     CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
     if (ec)
         return 0;
index 7dae125b482a99a2ae5146d1dd11ff4b798df7c4..d621a9300f2bfe676e214fe2e517a690674b3136 100644 (file)
@@ -601,6 +601,7 @@ void HTMLMediaElement::play(ExceptionCode& ec)
 {
     // 3.14.9.7. Playing the media resource
     if (!m_movie || networkState() == EMPTY) {
+        ec = 0;
         load(ec);
         if (ec)
             return;
@@ -624,6 +625,7 @@ void HTMLMediaElement::pause(ExceptionCode& ec)
 {
     // 3.14.9.7. Playing the media resource
     if (!m_movie || networkState() == EMPTY) {
+        ec = 0;
         load(ec);
         if (ec)
             return;
index da4dd2e2d817efdd09fb5bfbfaa1a2f6c9b7e9d3..d0c045c8e1d5f14dd239015cd13373d7dd1d5c75 100644 (file)
@@ -216,13 +216,14 @@ unsigned HTMLSelectElement::length() const
     return len;
 }
 
-void HTMLSelectElement::add( HTMLElement *element, HTMLElement *before, ExceptionCode& ec)
+void HTMLSelectElement::add(HTMLElement *element, HTMLElement *before, ExceptionCode& ec)
 {
     RefPtr<HTMLElement> protectNewChild(element); // make sure the element is ref'd and deref'd so we don't leak it
 
     if (!element || !(element->hasLocalName(optionTag) || element->hasLocalName(hrTag)))
         return;
 
+    ec = 0;
     insertBefore(element, before, ec);
     if (!ec)
         setRecalcListItems();
@@ -1026,7 +1027,7 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc
         remove(index);
     }
     // finally add the new element
-    if (ec == 0) {
+    if (!ec) {
         add(option, before, ec);
         if (diff >= 0 && option->selected())
             setSelectedIndex(index, !m_multiple);
index 71a147d82941de1186bf3c703c67706fd69722a4..170701239ea2cecc13821612a8fd85825a684952 100644 (file)
@@ -64,6 +64,7 @@ PassRefPtr<XPathResult> XPathEvaluator::evaluate(const String& expression,
         return 0;
     }
 
+    ec = 0;
     RefPtr<XPathExpression> expr = createExpression(expression, resolver, ec);
     if (ec)
         return 0;