Bug 50971

Summary: Combine setShadowRoot and clearShadowRoot into a simpler API
Product: WebKit Reporter: Dimitri Glazkov (Google) <dglazkov>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 44907    
Attachments:
Description Flags
Patch
none
Now with less confusion.
none
With more clarity in code. none

Dimitri Glazkov (Google)
Reported 2010-12-13 14:08:21 PST
There's no need to have clearShadowHost, setShadowHost(0) should just do it, since it always needs to clean up previous value anyway.
Attachments
Patch (3.66 KB, patch)
2010-12-13 14:57 PST, Dimitri Glazkov (Google)
no flags
Now with less confusion. (3.66 KB, patch)
2010-12-14 11:11 PST, Dimitri Glazkov (Google)
no flags
With more clarity in code. (4.35 KB, patch)
2010-12-16 09:39 PST, Dimitri Glazkov (Google)
no flags
Dimitri Glazkov (Google)
Comment 1 2010-12-13 14:57:52 PST
Darin Adler
Comment 2 2010-12-13 22:12:01 PST
Comment on attachment 76446 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=76446&action=review > WebCore/ChangeLog:5 > + Combine setShadowHost and clearShadowHost into a simpler API You mean setShadowRoot and clearShadowRoot, right? > WebCore/dom/Element.cpp:1093 > + } else if (!newRoot) I think this else is wrong. > WebCore/dom/Element.cpp:1097 > + newRoot->setShadowHost(this); If hasRareData was true and newRoot is a null pointer, then we’ll dereference the null pointer here. > WebCore/dom/Node.h:220 > + Element* shadowHost() const; > + void setShadowHost(Element*); Why are you making these member functions public? Seems unrelated to the rest of the patch?
Dimitri Glazkov (Google)
Comment 3 2010-12-14 11:08:40 PST
Comment on attachment 76446 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=76446&action=review Thanks for the review! New patch coming up. >> WebCore/dom/Element.cpp:1093 >> + } else if (!newRoot) > > I think this else is wrong. You're right! I don't know what I've been drinking last night. >> WebCore/dom/Element.cpp:1097 >> + newRoot->setShadowHost(this); > > If hasRareData was true and newRoot is a null pointer, then we’ll dereference the null pointer here. Yup. My "else" above was enabling this to happen. >> WebCore/dom/Node.h:220 >> + void setShadowHost(Element*); > > Why are you making these member functions public? Seems unrelated to the rest of the patch? Because I need to use setShadowHost() from Element::setShadowRoot() and thought I might as well bring shadowHost() out with it.
Dimitri Glazkov (Google)
Comment 4 2010-12-14 11:11:57 PST
Created attachment 76548 [details] Now with less confusion.
Eric Seidel (no email)
Comment 5 2010-12-15 15:22:48 PST
Comment on attachment 76548 [details] Now with less confusion. View in context: https://bugs.webkit.org/attachment.cgi?id=76548&action=review > WebCore/dom/Element.cpp:1093 > + if (RefPtr<Node> oldRoot = rareData()->m_shadowRoot.release()) { > + document()->removeFocusedNodeOfSubtree(oldRoot.get()); > + oldRoot->setShadowHost(0); > + if (oldRoot->inDocument()) > + oldRoot->removedFromDocument(); > + else > + oldRoot->removedFromTree(true); This feels like a helper method.
Dimitri Glazkov (Google)
Comment 6 2010-12-16 09:39:05 PST
Created attachment 76776 [details] With more clarity in code.
Eric Seidel (no email)
Comment 7 2010-12-24 09:05:48 PST
Comment on attachment 76776 [details] With more clarity in code. View in context: https://bugs.webkit.org/attachment.cgi?id=76776&action=review Seems OK to me. > WebCore/dom/Element.cpp:1087 > + // FIXME: Because today this is never called from script directly, we don't have to worry > + // about compromising DOM tree integrity (eg. node being a parent of this). However, > + // once we implement XBL2, we will have to add integrity checks here. Can we ASSERT here instead of just a FIXME? I'm not sure what we'd ASSERT though... > WebCore/dom/Element.cpp:1089 > + RefPtr<Node> newRoot = node; I'm not sure why you use the newRoot here. We don't really need the extra ref. Maybe Darin asked you to use a local RefPtr? > WebCore/dom/Element.cpp:1093 > + ensureRareData()->m_shadowRoot = newRoot; You could just assign it here w/o the check, no? > WebCore/dom/Element.cpp:1094 > + newRoot->setShadowHost(this); Then you would check ensureRareData()->m_shadowRoot before calling ensureRareData()->m_shadowRoot->setShadowHost(this)? Donno. Your current setup is fine too.
Dimitri Glazkov (Google)
Comment 8 2010-12-28 09:06:30 PST
Comment on attachment 76776 [details] With more clarity in code. View in context: https://bugs.webkit.org/attachment.cgi?id=76776&action=review Cq to the resQUE! :) >> WebCore/dom/Element.cpp:1089 >> + RefPtr<Node> newRoot = node; > > I'm not sure why you use the newRoot here. We don't really need the extra ref. Maybe Darin asked you to use a local RefPtr? Yeah, I could've danced around this with just using node.get() when assigning m_shadowRoot to avoid PassRefPtr derefing. But I generally don't like using PassRefPtrs for doing anything other than passing :) >> WebCore/dom/Element.cpp:1093 >> + ensureRareData()->m_shadowRoot = newRoot; > > You could just assign it here w/o the check, no? No, because ensureRareData always creates a new ElementRareData, which is not necessary if newRoot is 0.
WebKit Commit Bot
Comment 9 2010-12-28 10:54:30 PST
The commit-queue encountered the following flaky tests while processing attachment 76776 [details]: fast/workers/storage/use-same-database-in-page-and-workers.html bug 50995 (author: dumi@chromium.org) The commit-queue is continuing to process your patch.
WebKit Commit Bot
Comment 10 2010-12-28 10:55:57 PST
Comment on attachment 76776 [details] With more clarity in code. Clearing flags on attachment: 76776 Committed r74715: <http://trac.webkit.org/changeset/74715>
WebKit Commit Bot
Comment 11 2010-12-28 10:56:04 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.