Bug 73885 - DOM4 remove method
Summary: DOM4 remove method
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Erik Arvidsson
URL: http://dvcs.w3.org/hg/domcore/raw-fil...
Keywords: WebExposed
Depends on:
Blocks:
 
Reported: 2011-12-05 19:11 PST by Erik Arvidsson
Modified: 2019-02-06 09:03 PST (History)
11 users (show)

See Also:


Attachments
Patch (9.32 KB, patch)
2011-12-05 19:13 PST, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (11.58 KB, patch)
2011-12-16 10:29 PST, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (23.20 KB, patch)
2011-12-16 12:10 PST, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (25.04 KB, patch)
2011-12-19 11:00 PST, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (26.47 KB, patch)
2011-12-19 11:52 PST, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (25.37 KB, patch)
2012-09-24 09:31 PDT, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (25.45 KB, patch)
2012-09-24 09:50 PDT, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (11.81 KB, patch)
2012-09-24 12:13 PDT, Erik Arvidsson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2011-12-05 19:11:44 PST
DOM4 remove method
Comment 1 Erik Arvidsson 2011-12-05 19:13:31 PST
Created attachment 117978 [details]
Patch
Comment 2 Adam Barth 2011-12-05 22:23:08 PST
Comment on attachment 117978 [details]
Patch

Do we need to use a prefix here?  Given Henri's recent post about prefixes, http://hsivonen.iki.fi/vendor-prefixes/, we probably want to avoid them whenever possible.
Comment 3 Adam Barth 2011-12-05 22:23:42 PST
@Anne: Would you prefer DOM4 to be implemented with vendor prefixes or without?
Comment 4 Ojan Vafai 2011-12-06 10:20:09 PST
(In reply to comment #3)
> @Anne: Would you prefer DOM4 to be implemented with vendor prefixes or without?

This bug is probably not the best place to discuss this. There's a variety of strong opinions WRT Henri's post. We should start a thread on webkit-dev.
Comment 5 Adam Barth 2011-12-06 10:28:45 PST
> This bug is probably not the best place to discuss this. There's a variety of strong opinions WRT Henri's post. We should start a thread on webkit-dev.

Yes, or in the WhatWG.  Ideally we'd involve Henri and Anne in the discussion so everyone is on the same page.
Comment 6 Anne van Kesteren 2011-12-15 08:57:40 PST
No prefixes works for me. Everyone agrees on this method as far as I can tell. Maybe message www-dom@w3.org to that effect so people can complain?
Comment 7 Erik Arvidsson 2011-12-16 10:29:00 PST
Created attachment 119631 [details]
Patch
Comment 8 Darin Adler 2011-12-16 10:33:36 PST
Comment on attachment 119631 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=119631&action=review

Patch looks pretty good, but there is a problem with exception code handling.

> Source/WebCore/dom/Node.h:178
> -    void remove(ExceptionCode&);
> +    void remove(ExceptionCode& = ASSERT_NO_EXCEPTION);

This change doesn’t makes sense. If the DOM does not want an exception from this function, then there is no reason for any caller to want an exception. We have these exceptions only for the benefit of the DOM.

If there are any exceptions that could happen when called from the DOM, an assert is inappropriate. Nothing that a webpage does should be able to cause an assertion to fire.
Comment 9 Erik Arvidsson 2011-12-16 11:08:37 PST
(In reply to comment #8)
> (From update of attachment 119631 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=119631&action=review
> 
> Patch looks pretty good, but there is a problem with exception code handling.
> 
> > Source/WebCore/dom/Node.h:178
> > -    void remove(ExceptionCode&);
> > +    void remove(ExceptionCode& = ASSERT_NO_EXCEPTION);
> 
> This change doesn’t makes sense. If the DOM does not want an exception from this function, then there is no reason for any caller to want an exception. We have these exceptions only for the benefit of the DOM.
> 
> If there are any exceptions that could happen when called from the DOM, an assert is inappropriate. Nothing that a webpage does should be able to cause an assertion to fire.

removeChild calls Node::remove and removeChild may throw an exception.
Comment 10 Erik Arvidsson 2011-12-16 11:16:13 PST
Correction not removeChild but others. I'll go through all callers and let them handle the exception in the few cases where it is needed.
Comment 11 Alexey Proskuryakov 2011-12-16 11:31:08 PST
Erik, why did you change component? This is core DOM, not HTML.
Comment 12 Erik Arvidsson 2011-12-16 11:49:26 PST
(In reply to comment #11)
> Erik, why did you change component? This is core DOM, not HTML.

Alexey, just like you said; This is Core DOM, not XML :-)
Comment 13 Alexey Proskuryakov 2011-12-16 11:55:06 PST
But there is no other XML DOM besides Core DOM, is there? On the other hand, HTML DOM has a number of additions, and we also use the component for things like parsing, see <https://bugs.webkit.org/describecomponents.cgi?product=WebKit>.
Comment 14 Erik Arvidsson 2011-12-16 12:10:48 PST
Created attachment 119647 [details]
Patch
Comment 15 Erik Arvidsson 2011-12-16 12:12:07 PST
Darin, this removes some asserts. I can add back asserts that asserts that the node has a parentNode before calling remove if you feel like those asserts are important?
Comment 16 Early Warning System Bot 2011-12-16 12:29:58 PST
Comment on attachment 119647 [details]
Patch

Attachment 119647 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/10914781
Comment 17 Darin Adler 2011-12-16 22:50:27 PST
Qt:

../../../../Source/WebCore/xml/parser/XMLDocumentParserQt.cpp: In member function 'void WebCore::XMLDocumentParser::parseEndElement()':
../../../../Source/WebCore/xml/parser/XMLDocumentParserQt.cpp:497: error: no matching function for call to 'WebCore::ContainerNode::remove(WebCore::ExceptionCode&)'
Comment 18 Darin Adler 2011-12-16 22:52:02 PST
Comment on attachment 119647 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=119647&action=review

Please fix the Qt build before landing.

> Source/WebCore/dom/Node.h:29
> +#include "ExceptionCodePlaceholder.h"

No need to add this include.
Comment 19 Ojan Vafai 2011-12-18 10:59:17 PST
Comment on attachment 119647 [details]
Patch

This patch is fine. A couple thoughts:
-It seems that, in the presence of sync mutation events, we could get an exception in basically all these cases. This patch doesn't make this worse, but we might want to consider adding an EventScope to Node::remove.
-All the error checks in ContainerNode::removeChild don't apply when remove is called from Element. Would be a nice future patch to restructure the code so that remove and removeChild can call a helper function that does the removal without the error checking. This should be a significant performance improvement.
Comment 20 Erik Arvidsson 2011-12-19 11:00:33 PST
Created attachment 119888 [details]
Patch
Comment 21 Early Warning System Bot 2011-12-19 11:13:32 PST
Comment on attachment 119888 [details]
Patch

Attachment 119888 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/10944010
Comment 22 Erik Arvidsson 2011-12-19 11:52:02 PST
Created attachment 119895 [details]
Patch
Comment 23 Erik Arvidsson 2012-09-24 09:31:43 PDT
Created attachment 165396 [details]
Patch
Comment 24 Alexey Proskuryakov 2012-09-24 09:43:08 PDT
Comment on attachment 165396 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=165396&action=review

> Source/WebCore/ChangeLog:23
> +        (WebCore::Node::remove): Remove ExceptionCode parameter.

Can you please change this comment to a "why" one?
Comment 25 Erik Arvidsson 2012-09-24 09:50:41 PDT
Created attachment 165403 [details]
Patch
Comment 26 Erik Arvidsson 2012-09-24 09:51:15 PDT
(In reply to comment #24)
> (From update of attachment 165396 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=165396&action=review
> 
> > Source/WebCore/ChangeLog:23
> > +        (WebCore::Node::remove): Remove ExceptionCode parameter.
> 
> Can you please change this comment to a "why" one?

That is good advice. I'll try to keep that in mind
Comment 27 Ojan Vafai 2012-09-24 10:30:12 PDT
Comment on attachment 165403 [details]
Patch

I think you can get exceptions in all these cases due to sync firing of mutation events and blur/focus events. All the places in the existing code that ASSERT(!ec) are just wrong. Some day, I'll like for us to try an experiment where we EventScope blur/focus events as well and see if pages break, but until then, remove can throw exceptions. You obviously don't need to fixup the existing code, but I think we need to make the DOM4 method throw in the case that the child has been moved (e.g. during a blur event).
Comment 28 Alexey Proskuryakov 2012-09-24 10:32:55 PDT
Comment on attachment 165403 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=165403&action=review

> Source/WebCore/dom/CharacterData.idl:50
> +        // DOM 4
> +        void remove();

Are remove() methods actually needed everywhere, not just in Node.idl?
Comment 29 Erik Arvidsson 2012-09-24 10:34:50 PDT
(In reply to comment #28)
> (From update of attachment 165403 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=165403&action=review
> 
> > Source/WebCore/dom/CharacterData.idl:50
> > +        // DOM 4
> > +        void remove();
> 
> Are remove() methods actually needed everywhere, not just in Node.idl?

Yes. Not all Nodes have remove.
Comment 30 Ojan Vafai 2012-09-24 10:36:01 PDT
Comment on attachment 165403 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=165403&action=review

>> Source/WebCore/dom/CharacterData.idl:50
>> +        void remove();
> 
> Are remove() methods actually needed everywhere, not just in Node.idl?

DOM4 puts them int these three places specifically to avoid having them in non-sensical places (e.g. Document doesn't need a remove method).
Comment 31 Alexey Proskuryakov 2012-09-24 10:53:50 PDT
I see. It feels inconsistent since removeChild exists on all nodes, but I guess that shouldn't affect web developers in practice.
Comment 32 Erik Arvidsson 2012-09-24 11:06:38 PDT
(In reply to comment #31)
> I see. It feels inconsistent since removeChild exists on all nodes, but I guess that shouldn't affect web developers in practice.

For nodes that cannot have a parentNode remove makes no sense.

Similar rules apply to before, after, prepend and append
Comment 33 Erik Arvidsson 2012-09-24 12:13:38 PDT
Created attachment 165425 [details]
Patch
Comment 34 WebKit Review Bot 2012-09-24 13:03:45 PDT
Comment on attachment 165425 [details]
Patch

Clearing flags on attachment: 165425

Committed r129400: <http://trac.webkit.org/changeset/129400>
Comment 35 WebKit Review Bot 2012-09-24 13:03:51 PDT
All reviewed patches have been landed.  Closing bug.
Comment 36 Lucas Forschler 2019-02-06 09:03:36 PST
Mass moving XML DOM bugs to the "DOM" Component.