CVS commit by faure: Propagate correct DOM exception code from checkAddChild to setInnerHTML (instead of making one up when setInnerHTML returns false). Testcase by spaze, the real bug still needs to be fixed. M +6 -0 ChangeLog 1.427 M +12 -10 dom/html_element.cpp 1.26 M +17 -18 html/html_elementimpl.cpp 1.186 M +2 -2 html/html_elementimpl.h 1.77 --- kdelibs/khtml/ChangeLog #1.426:1.427 @@ -1,2 +1,8 @@ +2005-05-02 David Faure + + Propagate correct DOM exception code from checkAddChild to setInnerHTML. + * html/html_elementimpl.cpp (setInnerHTML, setInnerText) + * dom/html_element.cpp (setInnerHTML, setInnerText) + 2005-05-01 Allan Sandfeld Jensen --- kdelibs/khtml/html/html_elementimpl.cpp #1.185:1.186 @@ -548,26 +548,28 @@ DocumentFragment HTMLElementImpl::create } -bool HTMLElementImpl::setInnerHTML( const DOMString &html ) +void HTMLElementImpl::setInnerHTML( const DOMString &html, int &exceptioncode ) { DocumentFragment fragment = createContextualFragment( html ); - if ( fragment.isNull() ) - return false; + if ( fragment.isNull() ) { + exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; + return; + } - int ec = 0; // Make sure adding the new child is ok, before removing all children (#96187) - checkAddChild( fragment.handle(), ec); - if ( ec ) - return false; + checkAddChild( fragment.handle(), exceptioncode ); + if ( exceptioncode ) + return; removeChildren(); - appendChild( fragment.handle(), ec ); - return !ec; + appendChild( fragment.handle(), exceptioncode ); } -bool HTMLElementImpl::setInnerText( const DOMString &text ) +void HTMLElementImpl::setInnerText( const DOMString &text, int& exceptioncode ) { // following the IE specs. - if( endTag[id()] == FORBIDDEN ) - return false; + if( endTag[id()] == FORBIDDEN ) { + exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; + return; + } // IE disallows innerHTML on inline elements. I don't see why we should have this restriction, as our // dhtml engine can cope with it. Lars @@ -584,5 +586,6 @@ bool HTMLElementImpl::setInnerText( cons case ID_THEAD: case ID_TR: - return false; + exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR; + return; default: break; @@ -592,9 +595,5 @@ bool HTMLElementImpl::setInnerText( cons TextImpl *t = new TextImpl( docPtr(), text.implementation() ); - int ec = 0; - appendChild( t, ec ); - if ( !ec ) - return true; - return false; + appendChild( t, exceptioncode ); } --- kdelibs/khtml/html/html_elementimpl.h #1.76:1.77 @@ -62,6 +62,6 @@ public: DOMString innerText() const; DocumentFragment createContextualFragment( const DOMString &html ); - bool setInnerHTML( const DOMString &html ); - bool setInnerText( const DOMString &text ); + void setInnerHTML( const DOMString &html, int& exceptioncode ); + void setInnerText( const DOMString &text, int& exceptioncode ); virtual DOMString toString() const; --- kdelibs/khtml/dom/html_element.cpp #1.25:1.26 @@ -140,9 +140,10 @@ DOMString HTMLElement::innerHTML() const void HTMLElement::setInnerHTML( const DOMString &html ) { - bool ok = false; - if( impl ) - ok = ((HTMLElementImpl *)impl)->setInnerHTML( html ); - if ( !ok ) - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); + if( !impl ) + return; + int exceptioncode = 0; + ((HTMLElementImpl *)impl)->setInnerHTML( html, exceptioncode ); + if ( exceptioncode ) + throw DOMException( exceptioncode ); } @@ -155,9 +156,10 @@ DOMString HTMLElement::innerText() const void HTMLElement::setInnerText( const DOMString &text ) { - bool ok = false; - if( impl ) - ok = ((HTMLElementImpl *)impl)->setInnerText( text ); - if ( !ok ) - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); + if( !impl ) + return; + int exceptioncode = 0; + ((HTMLElementImpl *)impl)->setInnerText( text, exceptioncode ); + if ( exceptioncode ) + throw DOMException( exceptioncode ); }