Add an argument indicating the type of removal to Node::removedFrom
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 10:05:21 +0000 (10:05 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 10:05:21 +0000 (10:05 +0000)
commit2a503302552d6a01acf26e3a0c00d0f7bdcab3a4
tree97b54a5141a7106e3318c5339abbf278d3677c8d
parentdf9654f80f67cd043856a31625dbe53b38ee76fa
Add an argument indicating the type of removal to Node::removedFrom
https://bugs.webkit.org/show_bug.cgi?id=178505

Reviewed by Antti Koivisto.

Like r223628, added RemovalType as the first argument to Node::removedFrom, which contains two booleans indicating
whether the node just become disconnected from a document, and whether node's tree scope had changed or not.

These boolean flags simplifies the logic in removedFrom implementations, and are required to have a better
guarantee about the correctness of node flags during calls to removedFrom. Right now, Node::isConnected() and
Node::isInShadowTree() are both outdated until Node::removedFrom is called.

Also renamed the second argument of removedFrom to parentOfRemovedTree to make the semantics clear.

Note that in some implementations of removedFrom, we check whether isConnected() was true to decide whether
the node had already been disconnected from a document prior to calls to this particular call of removedFrom.
This extra check is no longer necessary since no node will be removed from a document without first being inserted
completely somewhere after r223458.

No new tests since there should be no behavioral changes.

* dom/ContainerNodeAlgorithms.cpp:
(WebCore::notifyNodeInsertedIntoDocument): Replaced RELEASE_ASSERT with RELEASE_ASSERT_WITH_SECURITY_IMPLICATION.
(WebCore::notifyNodeRemovedFromDocument): Replaced the check that the node had not been re-connected by scripts
by a release assert now that we believe we've eliminated all causes of these unwanted DOM mutations in r223458.
Also moved the code to call setCSSTarget to Element::removedFrom. This random call to setCSSTarget predates r114351,
as well as r40475. It was originally introduced by r29311 into Node::removedFromDocument() ten years ago.
(WebCore::notifyNodeRemovedFromTree): Moved NoEventDispatchAssertion to notifyChildNodeRemoved.
(WebCore::notifyChildNodeRemoved): Added NoEventDispatchAssertion.
* dom/ContainerNodeAlgorithms.h:
* dom/Element.cpp:
(WebCore::Element::removedFrom): Replaced the complicated code to detect when this element is removed from a document
and its tree scope had changed by removalType.disconnectedFromDocument and removalType.treeScopeChanged.
* dom/Element.h:
* dom/Node.cpp:
(WebCore::Node::removedFrom):
* dom/Node.h: Replaced a long block of comments above insertedInto by two lines of concise comments now that
the semantics of insertedInto and didFinishInsertingNode are more clear, and enforced by assertions.
(WebCore::Node::RemovalType::RemovalType): Addedl
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::removedFrom):
* dom/ProcessingInstruction.h:
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::removedFrom): The extra !isConnected() check is no longer needed. See the description above.
* dom/ShadowRoot.h:
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::removedFrom):
* html/FormAssociatedElement.h:
* html/HTMLBaseElement.cpp:
(WebCore::HTMLBaseElement::removedFrom):
* html/HTMLBaseElement.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::removedFrom):
* html/HTMLFormControlElement.h:
* html/HTMLFormControlElementWithState.cpp:
(WebCore::HTMLFormControlElementWithState::removedFrom):
* html/HTMLFormControlElementWithState.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::removedFrom):
* html/HTMLFormElement.h:
* html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::removedFrom):
* html/HTMLFrameSetElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::removedFrom):
* html/HTMLImageElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::removedFrom):
* html/HTMLInputElement.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::removedFrom): The extra !isConnected() check is no longer needed. See above.
* html/HTMLLinkElement.h:
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::removedFrom):
* html/HTMLMapElement.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::removedFrom):
* html/HTMLMediaElement.h:
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::removedFrom):
* html/HTMLObjectElement.h:
* html/HTMLSlotElement.cpp:
(WebCore::HTMLSlotElement::removedFrom): Simplifies the logic to detect when this slot element is being
removed from a shadow tree using removalType.treeScopeChanged.
* html/HTMLSlotElement.h:
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::insertedInto): Added a FIXME for an obvious bug.
(WebCore::HTMLSourceElement::removedFrom): Ditto.
* html/HTMLSourceElement.h:
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::removedFrom):
* html/HTMLStyleElement.h:
* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::removedFrom):
* html/HTMLTitleElement.h:
* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::removedFrom): Ditto.
* html/HTMLTrackElement.h:
* svg/SVGElement.cpp:
(WebCore::SVGElement::removedFrom): Replaced isConnected() check before calling Node::removedFrom by the check of
removalType.disconnectedFromDocument.
* svg/SVGElement.h:
* svg/SVGFEImageElement.cpp:
(WebCore::SVGFEImageElement::removedFrom):
* svg/SVGFEImageElement.h:
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::removedFrom):
* svg/SVGFontFaceElement.h:
* svg/SVGMPathElement.cpp:
(WebCore::SVGMPathElement::removedFrom):
* svg/SVGMPathElement.h:
* svg/SVGPathElement.cpp:
(WebCore::SVGPathElement::removedFrom):
* svg/SVGPathElement.h:
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::removedFrom):
* svg/SVGSVGElement.h:
* svg/SVGStyleElement.cpp:
(WebCore::SVGStyleElement::removedFrom): The extra !isConnected() check is no longer needed. See above.
* svg/SVGStyleElement.h:
* svg/SVGTRefElement.cpp:
(WebCore::SVGTRefElement::removedFrom):
* svg/SVGTRefElement.h:
* svg/SVGTextPathElement.cpp:
(WebCore::SVGTextPathElement::removedFrom):
* svg/SVGTextPathElement.h:
* svg/SVGTitleElement.cpp:
(WebCore::SVGTitleElement::removedFrom):
* svg/SVGTitleElement.h:
* svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::removedFrom):
* svg/SVGUseElement.h:
* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::removedFrom):
* svg/animation/SVGSMILElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223685 268f45cc-cd09-0410-ab3c-d52691b4dbfc
69 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNodeAlgorithms.cpp
Source/WebCore/dom/ContainerNodeAlgorithms.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/dom/ProcessingInstruction.h
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/ShadowRoot.h
Source/WebCore/html/FormAssociatedElement.cpp
Source/WebCore/html/FormAssociatedElement.h
Source/WebCore/html/HTMLBaseElement.cpp
Source/WebCore/html/HTMLBaseElement.h
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFormControlElementWithState.cpp
Source/WebCore/html/HTMLFormControlElementWithState.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLFrameSetElement.cpp
Source/WebCore/html/HTMLFrameSetElement.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/HTMLMapElement.cpp
Source/WebCore/html/HTMLMapElement.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLObjectElement.h
Source/WebCore/html/HTMLSlotElement.cpp
Source/WebCore/html/HTMLSlotElement.h
Source/WebCore/html/HTMLSourceElement.cpp
Source/WebCore/html/HTMLSourceElement.h
Source/WebCore/html/HTMLStyleElement.cpp
Source/WebCore/html/HTMLStyleElement.h
Source/WebCore/html/HTMLTitleElement.cpp
Source/WebCore/html/HTMLTitleElement.h
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/svg/SVGElement.cpp
Source/WebCore/svg/SVGElement.h
Source/WebCore/svg/SVGFEImageElement.cpp
Source/WebCore/svg/SVGFEImageElement.h
Source/WebCore/svg/SVGFontFaceElement.cpp
Source/WebCore/svg/SVGFontFaceElement.h
Source/WebCore/svg/SVGMPathElement.cpp
Source/WebCore/svg/SVGMPathElement.h
Source/WebCore/svg/SVGPathElement.cpp
Source/WebCore/svg/SVGPathElement.h
Source/WebCore/svg/SVGSVGElement.cpp
Source/WebCore/svg/SVGSVGElement.h
Source/WebCore/svg/SVGStyleElement.cpp
Source/WebCore/svg/SVGStyleElement.h
Source/WebCore/svg/SVGTRefElement.cpp
Source/WebCore/svg/SVGTRefElement.h
Source/WebCore/svg/SVGTextPathElement.cpp
Source/WebCore/svg/SVGTextPathElement.h
Source/WebCore/svg/SVGTitleElement.cpp
Source/WebCore/svg/SVGTitleElement.h
Source/WebCore/svg/SVGUseElement.cpp
Source/WebCore/svg/SVGUseElement.h
Source/WebCore/svg/animation/SVGSMILElement.cpp
Source/WebCore/svg/animation/SVGSMILElement.h