Changeset 217972 in webkit


Ignore:
Timestamp:
Jun 9, 2017 1:59:22 AM (7 years ago)
Author:
rniwa@webkit.org
Message:

Move TreeScope::adoptIfNeeded to Node and rename it to setTreeScopeRecursively
https://bugs.webkit.org/show_bug.cgi?id=173129

Reviewed by Antti Koivisto.

Renamed TreeScope::adoptIfNeeded to setTreeScopeRecursively and moved to Node.

The old name was really confusing because due to the existence of Document::adoptNode, a DOM API,
which removes the adopted node from its parent if there was one before adopting the node.
Most confusingly, this function called TreeScope::adoptIfNeeded.

Also inlined the tree scope check to avoid calling to moveTreeToNewScope when there is nothing to do.

This patch effectively reverts r104528.

No new tests. Existing tests cover this.

  • dom/Attr.cpp:

(WebCore::Attr::detachFromElementWithValue):
(WebCore::Attr::attachToElement):

  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::takeAllChildrenFrom):
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::replaceChild):
(WebCore::ContainerNode::removeBetween):
(WebCore::ContainerNode::replaceAllChildren):
(WebCore::ContainerNode::appendChildWithoutPreInsertionValidityCheck):
(WebCore::ContainerNode::parserAppendChild):

  • dom/ContainerNodeAlgorithms.cpp:

(WebCore::addChildNodesToDeletionQueue):

  • dom/Document.cpp:

(WebCore::Document::adoptNode):

  • dom/Element.cpp:

(WebCore::Element::ensureAttr):

  • dom/Node.cpp:

(WebCore::DidMoveToNewDocumentAssertionScope): Added. The old assertion wasn't sufficient when
HTMLTemplateElement made a recursive call to setTreeScopeRecursively.
(WebCore::DidMoveToNewDocumentAssertionScope::DidMoveToNewDocumentAssertionScope):
(WebCore::DidMoveToNewDocumentAssertionScope::~DidMoveToNewDocumentAssertionScope):
(WebCore::DidMoveToNewDocumentAssertionScope::didRecieveCall):
(WebCore::moveNodeToNewDocument): Moved from TreeScope. Calls to incrementReferencingNodeCount
and decrementReferencingNodeCount to Node::didMoveToNewDocument. This function is now eliminated
in a release build.
(WebCore::moveShadowTreeToNewDocument): Moved from TreeScope.
(WebCore::Node::moveTreeToNewScope): Ditto.
(WebCore::Node::didMoveToNewDocument): See the description for moveNodeToNewDocument above.

  • dom/Node.h:

(WebCore::Node::isParsingChildrenFinished): Moved to avoid having its own protected section.
(WebCore::Node::setIsParsingChildrenFinished): Ditto.
(WebCore::Node::clearIsParsingChildrenFinished): Ditto.
(WebCore::Node::setTreeScopeRecursively): Moved from TreeScope::adoptIfNeeded.

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::~ShadowRoot):

  • dom/TreeScope.cpp:

(WebCore::TreeScope::adoptIfNeeded): Deleted.
(WebCore::TreeScope::moveTreeToNewScope): Deleted.
(WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled): Deleted.
(WebCore::TreeScope::moveNodeToNewDocument): Deleted.
(WebCore::TreeScope::moveShadowTreeToNewDocument): Deleted.

  • dom/TreeScope.h:
  • html/HTMLTemplateElement.cpp:

(WebCore::HTMLTemplateElement::didMoveToNewDocument):

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r217971 r217972  
     12017-06-08  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move TreeScope::adoptIfNeeded to Node and rename it to setTreeScopeRecursively
     4        https://bugs.webkit.org/show_bug.cgi?id=173129
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Renamed TreeScope::adoptIfNeeded to setTreeScopeRecursively and moved to Node.
     9
     10        The old name was really confusing because due to the existence of Document::adoptNode, a DOM API,
     11        which removes the adopted node from its parent if there was one before adopting the node.
     12        Most confusingly, this function called TreeScope::adoptIfNeeded.
     13
     14        Also inlined the tree scope check to avoid calling to moveTreeToNewScope when there is nothing to do.
     15
     16        This patch effectively reverts r104528.
     17
     18        No new tests. Existing tests cover this.
     19
     20        * dom/Attr.cpp:
     21        (WebCore::Attr::detachFromElementWithValue):
     22        (WebCore::Attr::attachToElement):
     23        * dom/ContainerNode.cpp:
     24        (WebCore::ContainerNode::takeAllChildrenFrom):
     25        (WebCore::ContainerNode::insertBefore):
     26        (WebCore::ContainerNode::replaceChild):
     27        (WebCore::ContainerNode::removeBetween):
     28        (WebCore::ContainerNode::replaceAllChildren):
     29        (WebCore::ContainerNode::appendChildWithoutPreInsertionValidityCheck):
     30        (WebCore::ContainerNode::parserAppendChild):
     31        * dom/ContainerNodeAlgorithms.cpp:
     32        (WebCore::addChildNodesToDeletionQueue):
     33        * dom/Document.cpp:
     34        (WebCore::Document::adoptNode):
     35        * dom/Element.cpp:
     36        (WebCore::Element::ensureAttr):
     37        * dom/Node.cpp:
     38        (WebCore::DidMoveToNewDocumentAssertionScope): Added. The old assertion wasn't sufficient when
     39        HTMLTemplateElement made a recursive call to setTreeScopeRecursively.
     40        (WebCore::DidMoveToNewDocumentAssertionScope::DidMoveToNewDocumentAssertionScope):
     41        (WebCore::DidMoveToNewDocumentAssertionScope::~DidMoveToNewDocumentAssertionScope):
     42        (WebCore::DidMoveToNewDocumentAssertionScope::didRecieveCall):
     43        (WebCore::moveNodeToNewDocument): Moved from TreeScope. Calls to incrementReferencingNodeCount
     44        and decrementReferencingNodeCount to Node::didMoveToNewDocument. This function is now eliminated
     45        in a release build.
     46        (WebCore::moveShadowTreeToNewDocument): Moved from TreeScope.
     47        (WebCore::Node::moveTreeToNewScope): Ditto.
     48        (WebCore::Node::didMoveToNewDocument): See the description for moveNodeToNewDocument above.
     49        * dom/Node.h:
     50        (WebCore::Node::isParsingChildrenFinished): Moved to avoid having its own protected section.
     51        (WebCore::Node::setIsParsingChildrenFinished): Ditto.
     52        (WebCore::Node::clearIsParsingChildrenFinished): Ditto.
     53        (WebCore::Node::setTreeScopeRecursively): Moved from TreeScope::adoptIfNeeded.
     54        * dom/ShadowRoot.cpp:
     55        (WebCore::ShadowRoot::~ShadowRoot):
     56        * dom/TreeScope.cpp:
     57        (WebCore::TreeScope::adoptIfNeeded): Deleted.
     58        (WebCore::TreeScope::moveTreeToNewScope): Deleted.
     59        (WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled): Deleted.
     60        (WebCore::TreeScope::moveNodeToNewDocument): Deleted.
     61        (WebCore::TreeScope::moveShadowTreeToNewDocument): Deleted.
     62        * dom/TreeScope.h:
     63        * html/HTMLTemplateElement.cpp:
     64        (WebCore::HTMLTemplateElement::didMoveToNewDocument):
     65
    1662017-06-09  Adrien Plazas  <aplazas@igalia.com>
    267
  • trunk/Source/WebCore/dom/Attr.cpp

    r217957 r217972  
    136136    m_standaloneValue = value;
    137137    m_element = nullptr;
    138     document().adoptIfNeeded(*this);
     138    setTreeScopeRecursively(document());
    139139}
    140140
     
    144144    m_element = &element;
    145145    m_standaloneValue = nullAtom;
    146     element.treeScope().adoptIfNeeded(*this);
     146    setTreeScopeRecursively(element.treeScope());
    147147}
    148148
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r217794 r217972  
    151151        RELEASE_ASSERT(!child->parentNode() && &child->treeScope() == &treeScope());
    152152        ASSERT(!ensurePreInsertionValidity(child, nullptr).hasException());
    153         treeScope().adoptIfNeeded(child);
     153        child->setTreeScopeRecursively(treeScope());
    154154        parserAppendChild(child);
    155155    }
     
    291291            NoEventDispatchAssertion assertNoEventDispatch;
    292292
    293             treeScope().adoptIfNeeded(child);
     293            child->setTreeScopeRecursively(treeScope());
    294294            insertBeforeCommon(next, child);
    295295        }
     
    467467        {
    468468            NoEventDispatchAssertion assertNoEventDispatch;
    469             treeScope().adoptIfNeeded(child);
     469            child->setTreeScopeRecursively(treeScope());
    470470            if (refChild)
    471471                insertBeforeCommon(*refChild, child.get());
     
    588588    oldChild.setParentNode(nullptr);
    589589
    590     document().adoptIfNeeded(oldChild);
     590    oldChild.setTreeScopeRecursively(document());
    591591}
    592592
     
    642642
    643643    // If node is not null, adopt node into parent's node document.
    644     treeScope().adoptIfNeeded(node);
     644    node->setTreeScopeRecursively(treeScope());
    645645
    646646    // Remove all parent's children, in tree order.
     
    757757        {
    758758            NoEventDispatchAssertion assertNoEventDispatch;
    759             treeScope().adoptIfNeeded(child);
     759            child->setTreeScopeRecursively(treeScope());
    760760            appendChildCommon(child);
    761761        }
     
    781781
    782782        appendChildCommon(newChild);
    783         treeScope().adoptIfNeeded(newChild);
     783        newChild.setTreeScopeRecursively(treeScope());
    784784    }
    785785
  • trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp

    r217926 r217972  
    180180        } else {
    181181            Ref<Node> protect(*node); // removedFromDocument may remove remove all references to this node.
    182             container.document().adoptIfNeeded(*node);
     182            node->setTreeScopeRecursively(container.document());
    183183            if (node->isInTreeScope())
    184184                notifyChildNodeRemoved(container, *node);
  • trunk/Source/WebCore/dom/Document.cpp

    r217864 r217972  
    992992    }
    993993
    994     adoptIfNeeded(source);
     994    source.setTreeScopeRecursively(*this);
    995995
    996996    return Ref<Node> { source };
  • trunk/Source/WebCore/dom/Element.cpp

    r217957 r217972  
    34133413    if (!attrNode) {
    34143414        attrNode = Attr::create(*this, name);
    3415         treeScope().adoptIfNeeded(*attrNode);
     3415        attrNode->setTreeScopeRecursively(treeScope());
    34163416        attrNodeList.append(attrNode);
    34173417    }
  • trunk/Source/WebCore/dom/Node.cpp

    r217926 r217972  
    19231923}
    19241924
     1925#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
     1926class DidMoveToNewDocumentAssertionScope {
     1927public:
     1928    DidMoveToNewDocumentAssertionScope(Node& node, Document& oldDocument, Document& newDocument)
     1929        : m_node(node)
     1930        , m_oldDocument(oldDocument)
     1931        , m_newDocument(newDocument)
     1932        , m_previousScope(s_scope)
     1933    {
     1934        s_scope = this;
     1935    }
     1936
     1937    ~DidMoveToNewDocumentAssertionScope()
     1938    {
     1939        ASSERT_WITH_SECURITY_IMPLICATION(m_called);
     1940        s_scope = m_previousScope;
     1941    }
     1942
     1943    static void didRecieveCall(Node& node, Document& oldDocument, Document& newDocument)
     1944    {
     1945        ASSERT_WITH_SECURITY_IMPLICATION(s_scope);
     1946        ASSERT_WITH_SECURITY_IMPLICATION(!s_scope->m_called);
     1947        ASSERT_WITH_SECURITY_IMPLICATION(&s_scope->m_node == &node);
     1948        ASSERT_WITH_SECURITY_IMPLICATION(&s_scope->m_oldDocument == &oldDocument);
     1949        ASSERT_WITH_SECURITY_IMPLICATION(&s_scope->m_newDocument == &newDocument);
     1950        s_scope->m_called = true;
     1951    }
     1952
     1953private:
     1954    Node& m_node;
     1955    Document& m_oldDocument;
     1956    Document& m_newDocument;
     1957    bool m_called { false };
     1958    DidMoveToNewDocumentAssertionScope* m_previousScope;
     1959
     1960    static DidMoveToNewDocumentAssertionScope* s_scope;
     1961};
     1962
     1963DidMoveToNewDocumentAssertionScope* DidMoveToNewDocumentAssertionScope::s_scope = nullptr;
     1964
     1965#else
     1966class DidMoveToNewDocumentAssertionScope {
     1967public:
     1968    DidMoveToNewDocumentAssertionScope(Node&, Document&, Document&) { }
     1969    static void didRecieveCall(Node&, Document&, Document&) { }
     1970};
     1971#endif
     1972
     1973static ALWAYS_INLINE void moveNodeToNewDocument(Node& node, Document& oldDocument, Document& newDocument)
     1974{
     1975    ASSERT(!node.isConnected() || &oldDocument != &newDocument);
     1976    DidMoveToNewDocumentAssertionScope scope(node, oldDocument, newDocument);
     1977    node.didMoveToNewDocument(oldDocument, newDocument);
     1978}
     1979
     1980static void moveShadowTreeToNewDocument(ShadowRoot& shadowRoot, Document& oldDocument, Document& newDocument)
     1981{
     1982    for (Node* node = &shadowRoot; node; node = NodeTraversal::next(*node, &shadowRoot)) {
     1983        moveNodeToNewDocument(*node, oldDocument, newDocument);
     1984        if (auto* shadow = node->shadowRoot())
     1985            moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
     1986    }
     1987}
     1988
     1989void Node::moveTreeToNewScope(Node& root, TreeScope& oldScope, TreeScope& newScope)
     1990{
     1991    ASSERT(&oldScope != &newScope);
     1992    ASSERT_WITH_SECURITY_IMPLICATION(&root.treeScope() == &oldScope);
     1993
     1994    // If an element is moved from a document and then eventually back again the collection cache for
     1995    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
     1996    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
     1997    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
     1998    Document& oldDocument = oldScope.documentScope();
     1999    Document& newDocument = newScope.documentScope();
     2000    bool shouldUpdateDocumentScope = &oldDocument != &newDocument;
     2001    if (shouldUpdateDocumentScope) {
     2002        oldDocument.incrementReferencingNodeCount();
     2003        oldDocument.incDOMTreeVersion();
     2004    }
     2005
     2006    for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
     2007        ASSERT(!node->isTreeScope());
     2008        ASSERT(&node->treeScope() == &oldScope);
     2009        node->setTreeScope(newScope);
     2010
     2011        if (shouldUpdateDocumentScope)
     2012            moveNodeToNewDocument(*node, oldDocument, newDocument);
     2013        else if (node->hasRareData()) {
     2014            if (auto* nodeLists = node->rareData()->nodeLists())
     2015                nodeLists->adoptTreeScope();
     2016        }
     2017
     2018        if (!is<Element>(*node))
     2019            continue;
     2020        Element& element = downcast<Element>(*node);
     2021
     2022        if (element.hasSyntheticAttrChildNodes()) {
     2023            for (auto& attr : element.attrNodeList())
     2024                moveTreeToNewScope(*attr, oldScope, newScope);
     2025        }
     2026
     2027        if (auto* shadow = element.shadowRoot()) {
     2028            ASSERT_WITH_SECURITY_IMPLICATION(&shadow->document() == &oldDocument);
     2029            shadow->setParentTreeScope(newScope);
     2030            if (shouldUpdateDocumentScope)
     2031                moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
     2032        }
     2033    }
     2034
     2035    if (shouldUpdateDocumentScope)
     2036        oldDocument.decrementReferencingNodeCount();
     2037}
     2038
    19252039void Node::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
    19262040{
    19272041    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
    1928     TreeScope::ensureDidMoveToNewDocumentWasCalled(oldDocument);
     2042    DidMoveToNewDocumentAssertionScope::didRecieveCall(*this, oldDocument, newDocument);
     2043
     2044    newDocument.incrementReferencingNodeCount();
     2045    oldDocument.decrementReferencingNodeCount();
    19292046
    19302047    if (hasRareData()) {
  • trunk/Source/WebCore/dom/Node.h

    r217904 r217972  
    370370        return *m_treeScope;
    371371    }
     372    void setTreeScopeRecursively(TreeScope&);
    372373    static ptrdiff_t treeScopeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_treeScope); }
    373374
     
    491492    ScriptExecutionContext* scriptExecutionContext() const final; // Implemented in Document.h
    492493
     494    virtual void didMoveToNewDocument(Document& oldDocument, Document& newDocument);
     495
    493496    bool addEventListener(const AtomicString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override;
    494497    bool removeEventListener(const AtomicString& eventType, EventListener&, const ListenerOptions&) override;
     
    614617    void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; }
    615618    void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
     619
     620    bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
     621    void setIsParsingChildrenFinished() { setFlag(IsParsingChildrenFinishedFlag); }
     622    void clearIsParsingChildrenFinished() { clearFlag(IsParsingChildrenFinishedFlag); }
    616623
    617624    enum ConstructionType {
     
    632639    Node(Document&, ConstructionType);
    633640
    634     virtual void didMoveToNewDocument(Document& oldDocument, Document& newDocument);
    635    
    636641    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const { }
    637642
     
    672677
    673678    void adjustStyleValidity(Style::Validity, Style::InvalidationMode);
    674    
     679
    675680    void* opaqueRootSlow() const;
     681
     682    static void moveTreeToNewScope(Node&, TreeScope& oldScope, TreeScope& newScope);
    676683
    677684    int m_refCount;
     
    687694        NodeRareDataBase* m_rareData;
    688695    } m_data { nullptr };
    689 
    690 protected:
    691     bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
    692     void setIsParsingChildrenFinished() { setFlag(IsParsingChildrenFinishedFlag); }
    693     void clearIsParsingChildrenFinished() { clearFlag(IsParsingChildrenFinishedFlag); }
    694696};
    695697
     
    791793}
    792794
     795inline void Node::setTreeScopeRecursively(TreeScope& newTreeScope)
     796{
     797    ASSERT(!isDocumentNode());
     798    ASSERT(!m_deletionHasBegun);
     799    if (m_treeScope != &newTreeScope)
     800        moveTreeToNewScope(*this, *m_treeScope, newTreeScope);
     801}
     802
    793803} // namespace WebCore
    794804
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r217876 r217972  
    8282
    8383    // We must remove all of our children first before the TreeScope destructor
    84     // runs so we don't go through TreeScope::adoptIfNeeded for each child with a
     84    // runs so we don't go through Node::setTreeScopeRecursively for each child with a
    8585    // destructed tree scope in each descendant.
    8686    removeDetachedChildren();
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r217876 r217972  
    369369}
    370370
    371 void TreeScope::adoptIfNeeded(Node& node)
    372 {
    373     ASSERT(!node.isDocumentNode());
    374     ASSERT(!node.m_deletionHasBegun);
    375     TreeScope& treeScopeOfNode = node.treeScope();
    376     if (this != &treeScopeOfNode)
    377         moveTreeToNewScope(node, treeScopeOfNode, *this);
    378 }
    379 
    380 void TreeScope::moveTreeToNewScope(Node& root, TreeScope& oldScope, TreeScope& newScope)
    381 {
    382     ASSERT(&oldScope != &newScope);
    383     ASSERT_WITH_SECURITY_IMPLICATION(&root.treeScope() == &oldScope);
    384 
    385     // If an element is moved from a document and then eventually back again the collection cache for
    386     // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
    387     // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
    388     // we ensure that the collection cache will be invalidated as needed when the element is moved back.
    389     Document& oldDocument = oldScope.documentScope();
    390     Document& newDocument = newScope.documentScope();
    391     bool willMoveToNewDocument = &oldDocument != &newDocument;
    392     if (willMoveToNewDocument) {
    393         oldDocument.incrementReferencingNodeCount();
    394         oldDocument.incDOMTreeVersion();
    395     }
    396 
    397     for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
    398         ASSERT(!node->isTreeScope());
    399         ASSERT(&node->treeScope() == &oldScope);
    400         node->setTreeScope(newScope);
    401 
    402         if (willMoveToNewDocument)
    403             moveNodeToNewDocument(*node, oldDocument, newDocument);
    404         else if (node->hasRareData()) {
    405             if (auto* nodeLists = node->rareData()->nodeLists())
    406                 nodeLists->adoptTreeScope();
    407         }
    408 
    409         if (!is<Element>(*node))
    410             continue;
    411 
    412         if (node->hasSyntheticAttrChildNodes()) {
    413             for (auto& attr : downcast<Element>(*node).attrNodeList())
    414                 moveTreeToNewScope(*attr, oldScope, newScope);
    415         }
    416 
    417         if (auto* shadow = node->shadowRoot()) {
    418             ASSERT_WITH_SECURITY_IMPLICATION(&shadow->document() == &oldDocument);
    419             shadow->setParentTreeScope(newScope);
    420             if (willMoveToNewDocument)
    421                 moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
    422         }
    423     }
    424 
    425     if (willMoveToNewDocument)
    426         oldDocument.decrementReferencingNodeCount();
    427 }
    428 
    429 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
    430 static bool didMoveToNewDocumentWasCalled = false;
    431 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = nullptr;
    432 
    433 void TreeScope::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument)
    434 {
    435     ASSERT_WITH_SECURITY_IMPLICATION(!didMoveToNewDocumentWasCalled);
    436     ASSERT_WITH_SECURITY_IMPLICATION(&oldDocument == oldDocumentDidMoveToNewDocumentWasCalledWith);
    437     didMoveToNewDocumentWasCalled = true;
    438 }
    439 #endif
    440 
    441 void TreeScope::moveNodeToNewDocument(Node& node, Document& oldDocument, Document& newDocument)
    442 {
    443     ASSERT(!node.isConnected() || &oldDocument != &newDocument);
    444 
    445     newDocument.incrementReferencingNodeCount();
    446     oldDocument.decrementReferencingNodeCount();
    447 
    448 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
    449     didMoveToNewDocumentWasCalled = false;
    450     oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument;
    451 #endif
    452 
    453     node.didMoveToNewDocument(oldDocument, newDocument);
    454     ASSERT_WITH_SECURITY_IMPLICATION(didMoveToNewDocumentWasCalled);
    455 }
    456 
    457 void TreeScope::moveShadowTreeToNewDocument(ShadowRoot& shadowRoot, Document& oldDocument, Document& newDocument)
    458 {
    459     for (Node* node = &shadowRoot; node; node = NodeTraversal::next(*node, &shadowRoot)) {
    460         moveNodeToNewDocument(*node, oldDocument, newDocument);
    461         if (auto* shadow = node->shadowRoot())
    462             moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
    463     }
    464 }
    465 
    466371static Element* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
    467372{
  • trunk/Source/WebCore/dom/TreeScope.h

    r217876 r217972  
    9797    Element* findAnchor(const String& name);
    9898
    99     // Used by the basic DOM mutation methods (e.g., appendChild()).
    100     void adoptIfNeeded(Node&);
    101 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
    102     static void ensureDidMoveToNewDocumentWasCalled(Document& oldDocument);
    103 #else
    104     static void ensureDidMoveToNewDocumentWasCalled(Document&) { }
    105 #endif
    106 
    10799    ContainerNode& rootNode() const { return m_rootNode; }
    108100
     
    123115
    124116private:
    125     void moveTreeToNewScope(Node&, TreeScope& oldScope, TreeScope& newScope);
    126     void moveNodeToNewDocument(Node&, Document& oldDocument, Document& newDocument);
    127     void moveShadowTreeToNewDocument(ShadowRoot&, Document& oldDocument, Document& newDocument);
    128117
    129118    ContainerNode& m_rootNode;
  • trunk/Source/WebCore/html/HTMLTemplateElement.cpp

    r217876 r217972  
    8989        return;
    9090    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
    91     newDocument.ensureTemplateDocument().adoptIfNeeded(*m_content);
     91    m_content->setTreeScopeRecursively(newDocument.ensureTemplateDocument());
    9292}
    9393
Note: See TracChangeset for help on using the changeset viewer.