RESOLVED FIXED Bug 67651
Move Element.contains to Node
https://bugs.webkit.org/show_bug.cgi?id=67651
Summary Move Element.contains to Node
Erik Arvidsson
Reported 2011-09-06 10:26:26 PDT
We currently expose contains on Element. The new spec moves this to Node to allow the check if a node is in the document (and other use cases)
Attachments
Patch (29.94 KB, patch)
2011-09-06 15:26 PDT, Erik Arvidsson
no flags
Patch with O(1) document.contains (32.83 KB, patch)
2011-09-07 10:47 PDT, Erik Arvidsson
no flags
Patch (33.61 KB, patch)
2011-09-07 14:15 PDT, Erik Arvidsson
no flags
Patch DOM Core -> DOM4 (33.61 KB, patch)
2011-09-07 14:18 PDT, Erik Arvidsson
no flags
Patch. Added null check in DeleteSelectionCommand::mergeParagraphs (34.57 KB, patch)
2011-09-07 14:51 PDT, Erik Arvidsson
no flags
Patch. Expanded tests (34.81 KB, patch)
2011-09-07 15:07 PDT, Erik Arvidsson
no flags
Patch for landing (35.33 KB, patch)
2011-09-07 15:55 PDT, Erik Arvidsson
no flags
Patch for landing (35.33 KB, patch)
2011-09-07 16:11 PDT, Erik Arvidsson
no flags
mac binding fix (1.19 KB, patch)
2011-09-08 13:04 PDT, Ryosuke Niwa
no flags
Patch (36.70 KB, patch)
2011-09-09 11:32 PDT, Erik Arvidsson
no flags
Patch (36.70 KB, patch)
2011-09-09 12:15 PDT, Erik Arvidsson
no flags
Patch (36.73 KB, patch)
2011-09-09 13:43 PDT, Erik Arvidsson
no flags
Erik Arvidsson
Comment 1 2011-09-06 15:26:37 PDT
Erik Arvidsson
Comment 2 2011-09-06 16:51:55 PDT
One of the reasons we are moving contains to Node is so that we can do efficient tests whether a node is in the document. contains for Document now only need to check inDocument and compare the ownerDocument which is O(1) instead of O(depth). However, to add this I either need to make contains virtual or add code for special casing Document nodes inside Node::contains. I'm unsure which one (if any) would be preferred?
Erik Arvidsson
Comment 3 2011-09-07 10:47:37 PDT
Created attachment 106598 [details] Patch with O(1) document.contains
WebKit Review Bot
Comment 4 2011-09-07 11:45:24 PDT
Comment on attachment 106598 [details] Patch with O(1) document.contains Attachment 106598 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/9608269 New failing tests: editing/deleting/5272440.html
Darin Adler
Comment 5 2011-09-07 13:11:50 PDT
Comment on attachment 106598 [details] Patch with O(1) document.contains View in context: https://bugs.webkit.org/attachment.cgi?id=106598&action=review > Source/WebCore/dom/Node.cpp:1341 > + if (nodeType() == DOCUMENT_NODE) The nodeType call is a slow way, involving a virtual function call, to check if a node is a document. I believe the fast way is node->document() == this, but there may be an even faster way.
Erik Arvidsson
Comment 6 2011-09-07 13:35:29 PDT
Comment on attachment 106598 [details] Patch with O(1) document.contains I'll update to use document() instead of nodeType() which is non virtual so it should also prevent the crash when this is null.
Darin Adler
Comment 7 2011-09-07 13:36:43 PDT
(In reply to comment #6) > I'll update to use document() instead of nodeType() which is non virtual so it should also prevent the crash when this is null. It’s not legal to call a member function on an pointer that is null even if it’s non-virtual. We should not write code that depends on that. If we want a function that works with a null pointer then it needs to be a non-member function.
Darin Adler
Comment 8 2011-09-07 13:37:38 PDT
(In reply to comment #6) > I'll update to use document() instead of nodeType() which is non virtual so it should also prevent the crash when this is null. Calling document() will still crash when this is null, because it will try to read the document pointer out of the object!
Erik Arvidsson
Comment 9 2011-09-07 14:15:22 PDT
Darin Adler
Comment 10 2011-09-07 14:16:56 PDT
Comment on attachment 106635 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=106635&action=review > Source/WebCore/dom/Node.cpp:1340 > + if (!node || !this) > return false; It's not legal to call a member function on a null pointer. So it's never correct to check this for 0. This change should not be made. We don’t want this to be the one function in the entire WebKit project doing this.
Darin Adler
Comment 11 2011-09-07 14:18:11 PDT
(In reply to comment #10) > > Source/WebCore/dom/Node.cpp:1340 > > + if (!node || !this) > > return false; > > It's not legal to call a member function on a null pointer. So it's never correct to check this for 0. This change should not be made. We don’t want this to be the one function in the entire WebKit project doing this. If this change was needed, we’d need test coverage too, and I think that is not possible because it’s not called that way.
Erik Arvidsson
Comment 12 2011-09-07 14:18:54 PDT
Created attachment 106636 [details] Patch DOM Core -> DOM4
Darin Adler
Comment 13 2011-09-07 14:19:35 PDT
Comment on attachment 106636 [details] Patch DOM Core -> DOM4 review- because of spurious !this check
Erik Arvidsson
Comment 14 2011-09-07 14:20:51 PDT
(In reply to comment #13) > (From update of attachment 106636 [details]) > review- because of spurious !this check The invalid case come from the editing code. I'll add the check there.
Erik Arvidsson
Comment 15 2011-09-07 14:51:12 PDT
Created attachment 106646 [details] Patch. Added null check in DeleteSelectionCommand::mergeParagraphs
Erik Arvidsson
Comment 16 2011-09-07 15:07:23 PDT
Created attachment 106652 [details] Patch. Expanded tests
Ryosuke Niwa
Comment 17 2011-09-07 15:35:43 PDT
Comment on attachment 106652 [details] Patch. Expanded tests View in context: https://bugs.webkit.org/attachment.cgi?id=106652&action=review > Source/WebCore/ChangeLog:7 > + You should explain the change and refer to the relevant parts of the spec. > Source/WebCore/dom/Node.cpp:1340 > if (!node) > return false; Should we also optimize the case where two nodes do not belong to the same document? > Source/WebCore/editing/DeleteSelectionCommand.cpp:608 > - if (!startOfParagraphToMove.deepEquivalent().deprecatedNode() || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode())) { > + if (!endBlock || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode()) || !startOfParagraphToMove.deepEquivalent().deprecatedNode()) { Is there a test that catches this crash?
Ryosuke Niwa
Comment 18 2011-09-07 15:35:43 PDT
Comment on attachment 106652 [details] Patch. Expanded tests View in context: https://bugs.webkit.org/attachment.cgi?id=106652&action=review > Source/WebCore/ChangeLog:7 > + You should explain the change and refer to the relevant parts of the spec. > Source/WebCore/dom/Node.cpp:1340 > if (!node) > return false; Should we also optimize the case where two nodes do not belong to the same document? > Source/WebCore/editing/DeleteSelectionCommand.cpp:608 > - if (!startOfParagraphToMove.deepEquivalent().deprecatedNode() || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode())) { > + if (!endBlock || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode()) || !startOfParagraphToMove.deepEquivalent().deprecatedNode()) { Is there a test that catches this crash?
Darin Adler
Comment 19 2011-09-07 15:42:36 PDT
I agree with all of Ryosuke’s comments, but I also feel this is landable as-is.
Erik Arvidsson
Comment 20 2011-09-07 15:49:20 PDT
(In reply to comment #18) > (From update of attachment 106652 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=106652&action=review > > > Source/WebCore/ChangeLog:7 > > + > > You should explain the change and refer to the relevant parts of the spec. OK. Will do. > > Source/WebCore/dom/Node.cpp:1340 > > if (!node) > > return false; > > Should we also optimize the case where two nodes do not belong to the same document? I don't think that is a common case but I'm willing to be convinced. > > Source/WebCore/editing/DeleteSelectionCommand.cpp:608 > > - if (!startOfParagraphToMove.deepEquivalent().deprecatedNode() || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode())) { > > + if (!endBlock || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode()) || !startOfParagraphToMove.deepEquivalent().deprecatedNode()) { > > Is there a test that catches this crash? Yup, editing/deleting/5272440.html
Erik Arvidsson
Comment 21 2011-09-07 15:55:48 PDT
Created attachment 106665 [details] Patch for landing
Ryosuke Niwa
Comment 22 2011-09-07 15:57:39 PDT
Comment on attachment 106665 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=106665&action=review > LayoutTests/ChangeLog:11 > + Reviewed by Darin Adler. This line should appear before the comment but after the bug titles & urls. > Source/WebCore/ChangeLog:11 > + Reviewed by Darin Adler. Ditto.
Erik Arvidsson
Comment 23 2011-09-07 16:00:26 PDT
Comment on attachment 106665 [details] Patch for landing webkit-patch failure
Erik Arvidsson
Comment 24 2011-09-07 16:11:15 PDT
Created attachment 106669 [details] Patch for landing
WebKit Review Bot
Comment 25 2011-09-08 12:37:25 PDT
Comment on attachment 106669 [details] Patch for landing Clearing flags on attachment: 106669 Committed r94781: <http://trac.webkit.org/changeset/94781>
WebKit Review Bot
Comment 26 2011-09-08 12:37:31 PDT
All reviewed patches have been landed. Closing bug.
Ryosuke Niwa
Comment 27 2011-09-08 12:56:21 PDT
This broke mac build. We need to keep the entry in Element.idl for objective-c binding.
Ryosuke Niwa
Comment 28 2011-09-08 12:59:44 PDT
(In reply to comment #27) > This broke mac build. We need to keep the entry in Element.idl for objective-c binding. I have a build fix locally and will land shortly. Just making sure it actually builds.
Ryosuke Niwa
Comment 29 2011-09-08 13:04:08 PDT
Created attachment 106775 [details] mac binding fix
Ryosuke Niwa
Comment 30 2011-09-08 13:21:05 PDT
Reopening the bug because the landed patch broke Mac binding.
Erik Arvidsson
Comment 31 2011-09-08 13:35:22 PDT
Ryosuke: Is it out of the question to change the ObjC public interfaces?
Ryosuke Niwa
Comment 32 2011-09-08 13:36:38 PDT
(In reply to comment #31) > Ryosuke: Is it out of the question to change the ObjC public interfaces? Apparently we can't because they're exposed in the WebKit framework.
Erik Arvidsson
Comment 33 2011-09-08 13:49:00 PDT
Comment on attachment 106775 [details] mac binding fix LGTM but I'm not a reviewer
Eric Seidel (no email)
Comment 34 2011-09-08 14:35:33 PDT
Tim used to be the public API guy, but I don't know who is these days.
Ryosuke Niwa
Comment 35 2011-09-08 14:39:09 PDT
We have a concern about defining contains on both Node.idl and Element.idl in Objective-C and we're rolling out the patch while we're figuring out how to fix that.
Timothy Hatcher
Comment 36 2011-09-08 14:59:00 PDT
What is wrong with "contains"? Does it conflict with some NSObject method?
Ryosuke Niwa
Comment 37 2011-09-08 15:01:27 PDT
(In reply to comment #36) > What is wrong with "contains"? Does it conflict with some NSObject method? So there's an Objective-C binding for bool Element::contains(Element*) but since we're moving it to Node, we now have bool Node::contains(Node*) and the binding code is giving us an error. I attempted to fix this by adding back Element::contains(Element*) to Element.idl but we weren't sure if that'll cause problems given there already is Node::contains(Node*) in Node.idl.
Timothy Hatcher
Comment 38 2011-09-08 16:35:28 PDT
It shouldn't cause problems to have the method in both places. But I'm curious what the error is, since it would be better to fix that without it being in both places.
Erik Arvidsson
Comment 39 2011-09-08 16:46:40 PDT
(In reply to comment #38) > It shouldn't cause problems to have the method in both places. But I'm curious what the error is, since it would be better to fix that without it being in both places. Source/WebCore/bindings/objc/PublicDOMInterfaces.h has @interface DOMElement : DOMNode WEBKIT_VERSION_1_3 ... - (BOOL)contains:(DOMElement *)element AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER; and my patch moved contains to Node which made DOMElement not have a contains any more. I'm not sure what errors Ryosuke saw with his patch though?
Timothy Hatcher
Comment 40 2011-09-08 17:28:11 PDT
PublicDOMInterfaces.h is designed to prevent accidental changes to public API. It isn't smart enough to know when methods move up in the inheritance chain, like from DOMElement to DOMNode. In this case it is safe to move "contains" from Element.idl to Node.idl and update PublicDOMInterfaces.h to reflect the move.
Timothy Hatcher
Comment 41 2011-09-08 17:30:35 PDT
Actually it isn't smart enough to know when methods move at all. It is up to the patch author to update PublicDOMInterfaces.h when it is a binary compatible safe change or when the API has been approved to become public by Apple.
Ryosuke Niwa
Comment 42 2011-09-08 18:37:06 PDT
By the way, I'd consider this as a feature addition since it adds new IDL attribute on Node. You should probably be making a post on webkit-dev.
Sam Weinig
Comment 43 2011-09-08 18:51:38 PDT
(In reply to comment #42) > By the way, I'd consider this as a feature addition since it adds new IDL attribute on Node. You should probably be making a post on webkit-dev. I don't think that is necessary. It is moving code around to match a new spec, let's not go to overboard on these kind of posts to webkit-dev.
Ryosuke Niwa
Comment 44 2011-09-08 18:55:43 PDT
(In reply to comment #43) > (In reply to comment #42) > > By the way, I'd consider this as a feature addition since it adds new IDL attribute on Node. You should probably be making a post on webkit-dev. > > I don't think that is necessary. It is moving code around to match a new spec, let's not go to overboard on these kind of posts to webkit-dev. Okay, sounds good to me. I just wanted to make sure nobody will later object to this change and complain, etc...
Erik Arvidsson
Comment 45 2011-09-09 09:39:30 PDT
(In reply to comment #41) > Actually it isn't smart enough to know when methods move at all. It is up to the patch author to update PublicDOMInterfaces.h when it is a binary compatible safe change or when the API has been approved to become public by Apple. Timothy: I looked at PublicDOMInterfaces.h and it isn't clear to me how I need to update it. Do you mind giving me a helping hand?
Timothy Hatcher
Comment 46 2011-09-09 10:32:03 PDT
(In reply to comment #45) > (In reply to comment #41) > > Actually it isn't smart enough to know when methods move at all. It is up to the patch author to update PublicDOMInterfaces.h when it is a binary compatible safe change or when the API has been approved to become public by Apple. > > Timothy: I looked at PublicDOMInterfaces.h and it isn't clear to me how I need to update it. Do you mind giving me a helping hand? You just edit it like you would a normal ObjC header. Remove the method from DOMElement and add it to DOMNode, and make the argument take a DOMNode instead of DOMElement.
Erik Arvidsson
Comment 47 2011-09-09 11:32:10 PDT
Eric Seidel (no email)
Comment 48 2011-09-09 11:35:59 PDT
Comment on attachment 106892 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=106892&action=review > Source/WebCore/bindings/objc/PublicDOMInterfaces.h:310 > +- (BOOL)contains:(DOMNode t *)node AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER; 't' Looks like a typo.
Ryosuke Niwa
Comment 49 2011-09-09 11:46:11 PDT
So the conclusion is to modify PublicDOMInterfaces.h ?
Timothy Hatcher
Comment 50 2011-09-09 11:55:41 PDT
(In reply to comment #49) > So the conclusion is to modify PublicDOMInterfaces.h ? Yes. Since this change will not break existing users of the API since it just moves down in the class inheritance. We have done this a few times, for example when tabIndex, blur and focus became shared. http://trac.webkit.org/changeset/32664/trunk/WebCore/bindings/objc/PublicDOMInterfaces.h
Erik Arvidsson
Comment 51 2011-09-09 11:57:29 PDT
Thanks Timothy. Thanks Eric. I'm rebuilding and re testing to ensure I didn't do anything else stupid before I'll upload a new patch.
Erik Arvidsson
Comment 52 2011-09-09 12:15:22 PDT
WebKit Review Bot
Comment 53 2011-09-09 12:54:41 PDT
Erik Arvidsson
Comment 54 2011-09-09 13:43:40 PDT
WebKit Review Bot
Comment 55 2011-09-09 20:20:49 PDT
Comment on attachment 106913 [details] Patch Clearing flags on attachment: 106913 Committed r94898: <http://trac.webkit.org/changeset/94898>
WebKit Review Bot
Comment 56 2011-09-09 20:20:56 PDT
All reviewed patches have been landed. Closing bug.
Lucas Forschler
Comment 57 2019-02-06 09:03:33 PST
Mass moving XML DOM bugs to the "DOM" Component.
Note You need to log in before you can comment on or make changes to this bug.