Patch for removeAttributeNode

David Faure faure at kde.org
Mon Jun 30 13:23:05 CEST 2003


On Sunday 29 June 2003 02:30, Peter Kelly wrote:
> On Sat, 28 Jun 2003, David Faure wrote:
> 
> > On Saturday 28 June 2003 03:52, Dirk Mueller wrote:
> > > On Fre, 27 Jun 2003, David Faure wrote:
> > > 
> > > > (The "false" doesn't matter, it's ignored). AFAICS this doesn't introduce a memleak
> > > 
> > > it doesn't introduce a memory leak, but its still wrong. why cloning the 
> > > attribute node? it should return the old node, not a clone of it :)
> > >
> > > The real question is why value is suddenly becoming null..
> > 
> > That's quite obvious:
> > 
> >     if (attr->_value) {
> >         attr->_value->deref();
> >         attr->_value = 0;
> >         if (element)
> >             element->parseAttribute(attr);
> >     }
> > 
> > at the end of NamedAttrMapImpl::removeAttribute().
> > 
> > Since this modifies "attr", I need a clone of it, one with the value still set...
> 
> removeNamedItem() is supposed to return the item removed, not a clone. 
> 
> i.e. you should be able to do the following:
> 
> attr = document.createAttribute("align");
> elem.setAttribute(attr);
> a = elem.removeNamedItem("align");
> 
> then (attr == a) should be true.
> 
> To notify the element of the attribute value becoming null you could 
> temporarily set it to null and then back again before returning the 
> attribute.

Thanks, this works much better indeed.

@@ -780,11 +788,11 @@ void NamedAttrMapImpl::removeAttribute(N

     // Notify the element that the attribute has been removed
     // dispatch appropriate mutation events
-    if (attr->_value) {
-        attr->_value->deref();
+    if (element && attr->_value) {
+        DOMStringImpl* value = attr->_value;
         attr->_value = 0;
-        if (element)
-            element->parseAttribute(attr);
+        element->parseAttribute(attr);
+        attr->_value = value;
     }
     if (element) {
         element->dispatchAttrRemovalEvent(attr);

This also fixes hc_elementreplaceexistingattributegevalue.html and
hc_namednodemapsetnameditemreturnvalue.html. Yay!

-- 
David FAURE, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
Qtella users - stability patches at http://blackie.dk/~dfaure/qtella.html


More information about the Khtml-devel mailing list