Title: [231390] trunk/Source/WebCore
Revision
231390
Author
[email protected]
Date
2018-05-04 16:52:43 -0700 (Fri, 04 May 2018)

Log Message

Rename DocumentOrderedMap to TreeScopeOrderedMap
https://bugs.webkit.org/show_bug.cgi?id=185290

Reviewed by Zalan Bujtas.

Renamed the class since it's almost always a mistake to use this class as a member variable of Document.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* dom/MouseRelatedEvent.cpp: Include the forgotten DOMWindow.h. Unified build files bit us here.
* dom/TreeScope.cpp:
(WebCore::TreeScope::addElementById):
(WebCore::TreeScope::addElementByName):
(WebCore::TreeScope::addImageMap):
(WebCore::TreeScope::addImageElementByUsemap):
(WebCore::TreeScope::labelElementForId):
* dom/TreeScope.h:
* dom/TreeScopeOrderedMap.cpp: Renamed from DocumentOrderedMap.cpp
* dom/TreeScopeOrderedMap.h: Renamed from DocumentOrderedMap.h
* html/HTMLDocument.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231389 => 231390)


--- trunk/Source/WebCore/ChangeLog	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/ChangeLog	2018-05-04 23:52:43 UTC (rev 231390)
@@ -1,3 +1,26 @@
+2018-05-04  Ryosuke Niwa  <[email protected]>
+
+        Rename DocumentOrderedMap to TreeScopeOrderedMap
+        https://bugs.webkit.org/show_bug.cgi?id=185290
+
+        Reviewed by Zalan Bujtas.
+
+        Renamed the class since it's almost always a mistake to use this class as a member variable of Document.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/MouseRelatedEvent.cpp: Include the forgotten DOMWindow.h. Unified build files bit us here.
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::addElementById):
+        (WebCore::TreeScope::addElementByName):
+        (WebCore::TreeScope::addImageMap):
+        (WebCore::TreeScope::addImageElementByUsemap):
+        (WebCore::TreeScope::labelElementForId):
+        * dom/TreeScope.h:
+        * dom/TreeScopeOrderedMap.cpp: Renamed from DocumentOrderedMap.cpp
+        * dom/TreeScopeOrderedMap.h: Renamed from DocumentOrderedMap.h
+        * html/HTMLDocument.h:
+
 2018-05-04  Don Olmstead  <[email protected]>
 
         [Win][WebKit] Fix forwarding headers for Windows build

Modified: trunk/Source/WebCore/Sources.txt (231389 => 231390)


--- trunk/Source/WebCore/Sources.txt	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/Sources.txt	2018-05-04 23:52:43 UTC (rev 231390)
@@ -729,7 +729,6 @@
 dom/DocumentEventQueue.cpp
 dom/DocumentFragment.cpp
 dom/DocumentMarkerController.cpp
-dom/DocumentOrderedMap.cpp
 dom/DocumentParser.cpp
 dom/DocumentSharedObjectPool.cpp
 dom/DocumentTouch.cpp @no-unify
@@ -826,6 +825,7 @@
 dom/TransitionEvent.cpp
 dom/Traversal.cpp
 dom/TreeScope.cpp
+dom/TreeScopeOrderedMap.cpp
 dom/TreeWalker.cpp
 dom/UIEvent.cpp
 dom/UIEventWithKeyState.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (231389 => 231390)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-05-04 23:52:43 UTC (rev 231390)
@@ -432,7 +432,7 @@
 		1479FAF0109AE37500DED655 /* RenderRubyBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 1479FAE8109AE37500DED655 /* RenderRubyBase.h */; };
 		1479FAF2109AE37500DED655 /* RenderRubyRun.h in Headers */ = {isa = PBXBuildFile; fileRef = 1479FAEA109AE37500DED655 /* RenderRubyRun.h */; };
 		1479FAF4109AE37500DED655 /* RenderRubyText.h in Headers */ = {isa = PBXBuildFile; fileRef = 1479FAEC109AE37500DED655 /* RenderRubyText.h */; };
-		14947FFE12F80CD200A0F631 /* DocumentOrderedMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		14947FFE12F80CD200A0F631 /* TreeScopeOrderedMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 14947FFC12F80CD200A0F631 /* TreeScopeOrderedMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		14993BE60B2F2B1C0050497F /* FocusController.h in Headers */ = {isa = PBXBuildFile; fileRef = 14993BE40B2F2B1C0050497F /* FocusController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		14CF7B3409F6ECD700EB3665 /* JSCSSRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 14CF7B3209F6ECD700EB3665 /* JSCSSRule.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		14D64B5D134A5B6B00E58FDA /* TreeScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D64B5B134A5B6B00E58FDA /* TreeScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -5822,8 +5822,8 @@
 		14813BF309EDF88E00F757E1 /* IDLParser.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = IDLParser.pm; path = scripts/IDLParser.pm; sourceTree = "<group>"; };
 		148B4FFF1B6904C500C954E4 /* CountQueuingStrategy.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CountQueuingStrategy.idl; sourceTree = "<group>"; };
 		148B4FFF1B6904C500C954E5 /* ByteLengthQueuingStrategy.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ByteLengthQueuingStrategy.idl; sourceTree = "<group>"; };
-		14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentOrderedMap.cpp; sourceTree = "<group>"; };
-		14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentOrderedMap.h; sourceTree = "<group>"; };
+		14947FFB12F80CD200A0F631 /* TreeScopeOrderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TreeScopeOrderedMap.cpp; sourceTree = "<group>"; };
+		14947FFC12F80CD200A0F631 /* TreeScopeOrderedMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TreeScopeOrderedMap.h; sourceTree = "<group>"; };
 		14993BE30B2F2B1C0050497F /* FocusController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FocusController.cpp; sourceTree = "<group>"; };
 		14993BE40B2F2B1C0050497F /* FocusController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FocusController.h; sourceTree = "<group>"; };
 		14A98E05136386A200C9FED2 /* Blob.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Blob.idl; sourceTree = "<group>"; };
@@ -26076,8 +26076,6 @@
 				ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */,
 				CE057FA31220731100A476D5 /* DocumentMarkerController.cpp */,
 				CE057FA41220731100A476D5 /* DocumentMarkerController.h */,
-				14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */,
-				14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */,
 				9B0FE8731D9E02DF004A8ACB /* DocumentOrShadowRoot.idl */,
 				A8C2280D11D4A59700D5A7D3 /* DocumentParser.cpp */,
 				BCCFBAE70B5152ED0001F1D7 /* DocumentParser.h */,
@@ -26401,6 +26399,8 @@
 				37FD4297118368460093C029 /* TreeDepthLimit.h */,
 				14D64B5A134A5B6B00E58FDA /* TreeScope.cpp */,
 				14D64B5B134A5B6B00E58FDA /* TreeScope.h */,
+				14947FFB12F80CD200A0F631 /* TreeScopeOrderedMap.cpp */,
+				14947FFC12F80CD200A0F631 /* TreeScopeOrderedMap.h */,
 				854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */,
 				854FE72F0A2297BE0058D7AD /* TreeWalker.h */,
 				1A750D3C0A90DE35000FF215 /* TreeWalker.idl */,
@@ -27603,7 +27603,6 @@
 				656D37360ADBA5DE00A4554D /* DocumentLoader.h in Headers */,
 				ED2BA83C09A24B91006C0AC4 /* DocumentMarker.h in Headers */,
 				CE057FA61220731100A476D5 /* DocumentMarkerController.h in Headers */,
-				14947FFE12F80CD200A0F631 /* DocumentOrderedMap.h in Headers */,
 				BCCFBAE80B5152ED0001F1D7 /* DocumentParser.h in Headers */,
 				4A4F48AA16B0DFC000EDBB29 /* DocumentRuleSets.h in Headers */,
 				AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */,
@@ -30580,6 +30579,7 @@
 				854FE7370A2297BE0058D7AD /* Traversal.h in Headers */,
 				37FD4298118368460093C029 /* TreeDepthLimit.h in Headers */,
 				14D64B5D134A5B6B00E58FDA /* TreeScope.h in Headers */,
+				14947FFE12F80CD200A0F631 /* TreeScopeOrderedMap.h in Headers */,
 				854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */,
 				C375D7FE16639519006184AB /* TypeAhead.h in Headers */,
 				E46A2B1C17CA65B9000DBCD8 /* TypedElementDescendantIterator.h in Headers */,

Deleted: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (231389 => 231390)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2018-05-04 23:52:43 UTC (rev 231390)
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "DocumentOrderedMap.h"
-
-#include "ContainerNodeAlgorithms.h"
-#include "ElementIterator.h"
-#include "HTMLImageElement.h"
-#include "HTMLLabelElement.h"
-#include "HTMLMapElement.h"
-#include "HTMLNameCollection.h"
-
-namespace WebCore {
-
-using namespace HTMLNames;
-
-void DocumentOrderedMap::clear()
-{
-    m_map.clear();
-}
-
-void DocumentOrderedMap::add(const AtomicStringImpl& key, Element& element, const TreeScope& treeScope)
-{
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &treeScope);
-    ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode().containsIncludingShadowDOM(&element));
-
-    if (!element.isInTreeScope())
-        return;
-    Map::AddResult addResult = m_map.ensure(&key, [&element] {
-        return MapEntry(&element);
-    });
-    MapEntry& entry = addResult.iterator->value;
-
-#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
-    ASSERT_WITH_SECURITY_IMPLICATION(!entry.registeredElements.contains(&element));
-    entry.registeredElements.add(&element);
-#endif
-
-    if (addResult.isNewEntry)
-        return;
-
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
-    entry.element = nullptr;
-    entry.count++;
-    entry.orderedList.clear();
-}
-
-void DocumentOrderedMap::remove(const AtomicStringImpl& key, Element& element)
-{
-    m_map.checkConsistency();
-    auto it = m_map.find(&key);
-
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(it != m_map.end());
-
-    MapEntry& entry = it->value;
-    ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.remove(&element));
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
-    if (entry.count == 1) {
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!entry.element || entry.element == &element);
-        m_map.remove(it);
-    } else {
-        if (entry.element == &element)
-            entry.element = nullptr;
-        entry.count--;
-        entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left.
-    }
-}
-
-template <typename KeyMatchingFunction>
-inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope, const KeyMatchingFunction& keyMatches) const
-{
-    m_map.checkConsistency();
-
-    auto it = m_map.find(&key);
-    if (it == m_map.end())
-        return nullptr;
-
-    MapEntry& entry = it->value;
-    ASSERT(entry.count);
-    if (entry.element) {
-        auto& element = *entry.element;
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
-        ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.contains(&element));
-        return &element;
-    }
-
-    // We know there's at least one node that matches; iterate to find the first one.
-    for (auto& element : descendantsOfType<Element>(scope.rootNode())) {
-        if (!keyMatches(key, element))
-            continue;
-        entry.element = &element;
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
-        ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.contains(entry.element));
-        return &element;
-    }
-
-#if !ASSERT_DISABLED
-    // FormAssociatedElement may call getElementById to find its owner form in the middle of a tree removal.
-    if (auto* currentScope = ContainerChildRemovalScope::currentScope()) {
-        ASSERT(&scope.rootNode() == &currentScope->parentOfRemovedTree().rootNode());
-        Node& removedTree = currentScope->removedChild();
-        ASSERT(is<ContainerNode>(removedTree));
-        for (auto& element : descendantsOfType<Element>(downcast<ContainerNode>(removedTree))) {
-            if (!keyMatches(key, element))
-                continue;
-            bool removedFromAncestorHasNotBeenCalledYet = element.isConnected();
-            ASSERT(removedFromAncestorHasNotBeenCalledYet);
-            return nullptr;
-        }
-    }
-    ASSERT_NOT_REACHED();
-#endif
-
-    return nullptr;
-}
-
-Element* DocumentOrderedMap::getElementById(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return element.getIdAttribute().impl() == &key;
-    });
-}
-
-Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return element.getNameAttribute().impl() == &key;
-    });
-}
-
-HTMLMapElement* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return downcast<HTMLMapElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().impl() == &key;
-    }));
-}
-
-HTMLImageElement* DocumentOrderedMap::getElementByUsemap(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return downcast<HTMLImageElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        // FIXME: HTML5 specification says we should match both image and object elements.
-        return is<HTMLImageElement>(element) && downcast<HTMLImageElement>(element).matchesUsemap(key);
-    }));
-}
-
-HTMLLabelElement* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return downcast<HTMLLabelElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return is<HTMLLabelElement>(element) && element.attributeWithoutSynchronization(forAttr).impl() == &key;
-    }));
-}
-
-Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return WindowNameCollection::elementMatches(element, &key);
-    });
-}
-
-Element* DocumentOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
-        return DocumentNameCollection::elementMatches(element, &key);
-    });
-}
-
-const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStringImpl& key, const TreeScope& scope) const
-{
-    m_map.checkConsistency();
-
-    auto it = m_map.find(&key);
-    if (it == m_map.end())
-        return nullptr;
-
-    MapEntry& entry = it->value;
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
-
-    if (entry.orderedList.isEmpty()) {
-        entry.orderedList.reserveCapacity(entry.count);
-        auto elementDescandents = descendantsOfType<Element>(scope.rootNode());
-        auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
-        auto end = elementDescandents.end();
-        for (; it != end; ++it) {
-            auto& element = *it;
-            if (element.getIdAttribute().impl() != &key)
-                continue;
-            entry.orderedList.append(&element);
-        }
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.orderedList.size() == entry.count);
-    }
-
-    return &entry.orderedList;
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/dom/DocumentOrderedMap.h (231389 => 231390)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.h	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.h	2018-05-04 23:52:43 UTC (rev 231390)
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
-#include <wtf/Vector.h>
-#include <wtf/text/AtomicStringImpl.h>
-
-namespace WebCore {
-
-class Element;
-class HTMLImageElement;
-class HTMLLabelElement;
-class HTMLMapElement;
-class TreeScope;
-
-class DocumentOrderedMap {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    void add(const AtomicStringImpl&, Element&, const TreeScope&);
-    void remove(const AtomicStringImpl&, Element&);
-    void clear();
-
-    bool contains(const AtomicStringImpl&) const;
-    bool containsSingle(const AtomicStringImpl&) const;
-    bool containsMultiple(const AtomicStringImpl&) const;
-
-    // concrete instantiations of the get<>() method template
-    Element* getElementById(const AtomicStringImpl&, const TreeScope&) const;
-    Element* getElementByName(const AtomicStringImpl&, const TreeScope&) const;
-    HTMLMapElement* getElementByMapName(const AtomicStringImpl&, const TreeScope&) const;
-    HTMLImageElement* getElementByUsemap(const AtomicStringImpl&, const TreeScope&) const;
-    HTMLLabelElement* getElementByLabelForAttribute(const AtomicStringImpl&, const TreeScope&) const;
-    Element* getElementByWindowNamedItem(const AtomicStringImpl&, const TreeScope&) const;
-    Element* getElementByDocumentNamedItem(const AtomicStringImpl&, const TreeScope&) const;
-
-    const Vector<Element*>* getAllElementsById(const AtomicStringImpl&, const TreeScope&) const;
-
-private:
-    template <typename KeyMatchingFunction>
-    Element* get(const AtomicStringImpl&, const TreeScope&, const KeyMatchingFunction&) const;
-
-    struct MapEntry {
-        MapEntry() { }
-        explicit MapEntry(Element* firstElement)
-            : element(firstElement)
-            , count(1)
-        { }
-
-        Element* element { nullptr };
-        unsigned count { 0 };
-        Vector<Element*> orderedList;
-#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
-        HashSet<Element*> registeredElements;
-#endif
-    };
-
-    typedef HashMap<const AtomicStringImpl*, MapEntry> Map;
-
-    mutable Map m_map;
-};
-
-inline bool DocumentOrderedMap::containsSingle(const AtomicStringImpl& id) const
-{
-    auto it = m_map.find(&id);
-    return it != m_map.end() && it->value.count == 1;
-}
-
-inline bool DocumentOrderedMap::contains(const AtomicStringImpl& id) const
-{
-    return m_map.contains(&id);
-}
-
-inline bool DocumentOrderedMap::containsMultiple(const AtomicStringImpl& id) const
-{
-    auto it = m_map.find(&id);
-    return it != m_map.end() && it->value.count > 1;
-}
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/dom/MouseRelatedEvent.cpp (231389 => 231390)


--- trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2018-05-04 23:52:43 UTC (rev 231390)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "MouseRelatedEvent.h"
 
+#include "DOMWindow.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameView.h"

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (231389 => 231390)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2018-05-04 23:52:43 UTC (rev 231390)
@@ -141,7 +141,7 @@
 void TreeScope::addElementById(const AtomicStringImpl& elementId, Element& element, bool notifyObservers)
 {
     if (!m_elementsById)
-        m_elementsById = std::make_unique<DocumentOrderedMap>();
+        m_elementsById = std::make_unique<TreeScopeOrderedMap>();
     m_elementsById->add(elementId, element, *this);
     if (notifyObservers)
         m_idTargetObserverRegistry->notifyObservers(elementId);
@@ -168,7 +168,7 @@
 void TreeScope::addElementByName(const AtomicStringImpl& name, Element& element)
 {
     if (!m_elementsByName)
-        m_elementsByName = std::make_unique<DocumentOrderedMap>();
+        m_elementsByName = std::make_unique<TreeScopeOrderedMap>();
     m_elementsByName->add(name, element, *this);
 }
 
@@ -239,7 +239,7 @@
     if (!name)
         return;
     if (!m_imageMapsByName)
-        m_imageMapsByName = std::make_unique<DocumentOrderedMap>();
+        m_imageMapsByName = std::make_unique<TreeScopeOrderedMap>();
     m_imageMapsByName->add(*name, imageMap, *this);
 }
 
@@ -263,7 +263,7 @@
 void TreeScope::addImageElementByUsemap(const AtomicStringImpl& name, HTMLImageElement& element)
 {
     if (!m_imagesByUsemap)
-        m_imagesByUsemap = std::make_unique<DocumentOrderedMap>();
+        m_imagesByUsemap = std::make_unique<TreeScopeOrderedMap>();
     return m_imagesByUsemap->add(name, element, *this);
 }
 
@@ -300,7 +300,7 @@
 
     if (!m_labelsByForAttribute) {
         // Populate the map on first access.
-        m_labelsByForAttribute = std::make_unique<DocumentOrderedMap>();
+        m_labelsByForAttribute = std::make_unique<TreeScopeOrderedMap>();
 
         for (auto& label : descendantsOfType<HTMLLabelElement>(m_rootNode)) {
             const AtomicString& forValue = label.attributeWithoutSynchronization(forAttr);

Modified: trunk/Source/WebCore/dom/TreeScope.h (231389 => 231390)


--- trunk/Source/WebCore/dom/TreeScope.h	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/dom/TreeScope.h	2018-05-04 23:52:43 UTC (rev 231390)
@@ -26,7 +26,7 @@
 
 #pragma once
 
-#include "DocumentOrderedMap.h"
+#include "TreeScopeOrderedMap.h"
 #include <memory>
 #include <wtf/Forward.h>
 #include <wtf/Vector.h>
@@ -126,11 +126,11 @@
     std::reference_wrapper<Document> m_documentScope;
     TreeScope* m_parentTreeScope;
 
-    std::unique_ptr<DocumentOrderedMap> m_elementsById;
-    std::unique_ptr<DocumentOrderedMap> m_elementsByName;
-    std::unique_ptr<DocumentOrderedMap> m_imageMapsByName;
-    std::unique_ptr<DocumentOrderedMap> m_imagesByUsemap;
-    std::unique_ptr<DocumentOrderedMap> m_labelsByForAttribute;
+    std::unique_ptr<TreeScopeOrderedMap> m_elementsById;
+    std::unique_ptr<TreeScopeOrderedMap> m_elementsByName;
+    std::unique_ptr<TreeScopeOrderedMap> m_imageMapsByName;
+    std::unique_ptr<TreeScopeOrderedMap> m_imagesByUsemap;
+    std::unique_ptr<TreeScopeOrderedMap> m_labelsByForAttribute;
 
     std::unique_ptr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
 };

Copied: trunk/Source/WebCore/dom/TreeScopeOrderedMap.cpp (from rev 231389, trunk/Source/WebCore/dom/DocumentOrderedMap.cpp) (0 => 231390)


--- trunk/Source/WebCore/dom/TreeScopeOrderedMap.cpp	                        (rev 0)
+++ trunk/Source/WebCore/dom/TreeScopeOrderedMap.cpp	2018-05-04 23:52:43 UTC (rev 231390)
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TreeScopeOrderedMap.h"
+
+#include "ContainerNodeAlgorithms.h"
+#include "ElementIterator.h"
+#include "HTMLImageElement.h"
+#include "HTMLLabelElement.h"
+#include "HTMLMapElement.h"
+#include "HTMLNameCollection.h"
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+void TreeScopeOrderedMap::clear()
+{
+    m_map.clear();
+}
+
+void TreeScopeOrderedMap::add(const AtomicStringImpl& key, Element& element, const TreeScope& treeScope)
+{
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &treeScope);
+    ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode().containsIncludingShadowDOM(&element));
+
+    if (!element.isInTreeScope())
+        return;
+    Map::AddResult addResult = m_map.ensure(&key, [&element] {
+        return MapEntry(&element);
+    });
+    MapEntry& entry = addResult.iterator->value;
+
+#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
+    ASSERT_WITH_SECURITY_IMPLICATION(!entry.registeredElements.contains(&element));
+    entry.registeredElements.add(&element);
+#endif
+
+    if (addResult.isNewEntry)
+        return;
+
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
+    entry.element = nullptr;
+    entry.count++;
+    entry.orderedList.clear();
+}
+
+void TreeScopeOrderedMap::remove(const AtomicStringImpl& key, Element& element)
+{
+    m_map.checkConsistency();
+    auto it = m_map.find(&key);
+
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(it != m_map.end());
+
+    MapEntry& entry = it->value;
+    ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.remove(&element));
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
+    if (entry.count == 1) {
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!entry.element || entry.element == &element);
+        m_map.remove(it);
+    } else {
+        if (entry.element == &element)
+            entry.element = nullptr;
+        entry.count--;
+        entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left.
+    }
+}
+
+template <typename KeyMatchingFunction>
+inline Element* TreeScopeOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope, const KeyMatchingFunction& keyMatches) const
+{
+    m_map.checkConsistency();
+
+    auto it = m_map.find(&key);
+    if (it == m_map.end())
+        return nullptr;
+
+    MapEntry& entry = it->value;
+    ASSERT(entry.count);
+    if (entry.element) {
+        auto& element = *entry.element;
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
+        ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.contains(&element));
+        return &element;
+    }
+
+    // We know there's at least one node that matches; iterate to find the first one.
+    for (auto& element : descendantsOfType<Element>(scope.rootNode())) {
+        if (!keyMatches(key, element))
+            continue;
+        entry.element = &element;
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
+        ASSERT_WITH_SECURITY_IMPLICATION(entry.registeredElements.contains(entry.element));
+        return &element;
+    }
+
+#if !ASSERT_DISABLED
+    // FormAssociatedElement may call getElementById to find its owner form in the middle of a tree removal.
+    if (auto* currentScope = ContainerChildRemovalScope::currentScope()) {
+        ASSERT(&scope.rootNode() == &currentScope->parentOfRemovedTree().rootNode());
+        Node& removedTree = currentScope->removedChild();
+        ASSERT(is<ContainerNode>(removedTree));
+        for (auto& element : descendantsOfType<Element>(downcast<ContainerNode>(removedTree))) {
+            if (!keyMatches(key, element))
+                continue;
+            bool removedFromAncestorHasNotBeenCalledYet = element.isConnected();
+            ASSERT(removedFromAncestorHasNotBeenCalledYet);
+            return nullptr;
+        }
+    }
+    ASSERT_NOT_REACHED();
+#endif
+
+    return nullptr;
+}
+
+Element* TreeScopeOrderedMap::getElementById(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return element.getIdAttribute().impl() == &key;
+    });
+}
+
+Element* TreeScopeOrderedMap::getElementByName(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return element.getNameAttribute().impl() == &key;
+    });
+}
+
+HTMLMapElement* TreeScopeOrderedMap::getElementByMapName(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return downcast<HTMLMapElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().impl() == &key;
+    }));
+}
+
+HTMLImageElement* TreeScopeOrderedMap::getElementByUsemap(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return downcast<HTMLImageElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        // FIXME: HTML5 specification says we should match both image and object elements.
+        return is<HTMLImageElement>(element) && downcast<HTMLImageElement>(element).matchesUsemap(key);
+    }));
+}
+
+HTMLLabelElement* TreeScopeOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return downcast<HTMLLabelElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return is<HTMLLabelElement>(element) && element.attributeWithoutSynchronization(forAttr).impl() == &key;
+    }));
+}
+
+Element* TreeScopeOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return WindowNameCollection::elementMatches(element, &key);
+    });
+}
+
+Element* TreeScopeOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return DocumentNameCollection::elementMatches(element, &key);
+    });
+}
+
+const Vector<Element*>* TreeScopeOrderedMap::getAllElementsById(const AtomicStringImpl& key, const TreeScope& scope) const
+{
+    m_map.checkConsistency();
+
+    auto it = m_map.find(&key);
+    if (it == m_map.end())
+        return nullptr;
+
+    MapEntry& entry = it->value;
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
+
+    if (entry.orderedList.isEmpty()) {
+        entry.orderedList.reserveCapacity(entry.count);
+        auto elementDescandents = descendantsOfType<Element>(scope.rootNode());
+        auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
+        auto end = elementDescandents.end();
+        for (; it != end; ++it) {
+            auto& element = *it;
+            if (element.getIdAttribute().impl() != &key)
+                continue;
+            entry.orderedList.append(&element);
+        }
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(entry.orderedList.size() == entry.count);
+    }
+
+    return &entry.orderedList;
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/dom/TreeScopeOrderedMap.h (from rev 231389, trunk/Source/WebCore/dom/DocumentOrderedMap.h) (0 => 231390)


--- trunk/Source/WebCore/dom/TreeScopeOrderedMap.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/TreeScopeOrderedMap.h	2018-05-04 23:52:43 UTC (rev 231390)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/Vector.h>
+#include <wtf/text/AtomicStringImpl.h>
+
+namespace WebCore {
+
+class Element;
+class HTMLImageElement;
+class HTMLLabelElement;
+class HTMLMapElement;
+class TreeScope;
+
+class TreeScopeOrderedMap {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    void add(const AtomicStringImpl&, Element&, const TreeScope&);
+    void remove(const AtomicStringImpl&, Element&);
+    void clear();
+
+    bool contains(const AtomicStringImpl&) const;
+    bool containsSingle(const AtomicStringImpl&) const;
+    bool containsMultiple(const AtomicStringImpl&) const;
+
+    // concrete instantiations of the get<>() method template
+    Element* getElementById(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByName(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLMapElement* getElementByMapName(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLImageElement* getElementByUsemap(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLLabelElement* getElementByLabelForAttribute(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByWindowNamedItem(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByDocumentNamedItem(const AtomicStringImpl&, const TreeScope&) const;
+
+    const Vector<Element*>* getAllElementsById(const AtomicStringImpl&, const TreeScope&) const;
+
+private:
+    template <typename KeyMatchingFunction>
+    Element* get(const AtomicStringImpl&, const TreeScope&, const KeyMatchingFunction&) const;
+
+    struct MapEntry {
+        MapEntry() { }
+        explicit MapEntry(Element* firstElement)
+            : element(firstElement)
+            , count(1)
+        { }
+
+        Element* element { nullptr };
+        unsigned count { 0 };
+        Vector<Element*> orderedList;
+#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
+        HashSet<Element*> registeredElements;
+#endif
+    };
+
+    typedef HashMap<const AtomicStringImpl*, MapEntry> Map;
+
+    mutable Map m_map;
+};
+
+inline bool TreeScopeOrderedMap::containsSingle(const AtomicStringImpl& id) const
+{
+    auto it = m_map.find(&id);
+    return it != m_map.end() && it->value.count == 1;
+}
+
+inline bool TreeScopeOrderedMap::contains(const AtomicStringImpl& id) const
+{
+    return m_map.contains(&id);
+}
+
+inline bool TreeScopeOrderedMap::containsMultiple(const AtomicStringImpl& id) const
+{
+    auto it = m_map.find(&id);
+    return it != m_map.end() && it->value.count > 1;
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLDocument.h (231389 => 231390)


--- trunk/Source/WebCore/html/HTMLDocument.h	2018-05-04 23:42:44 UTC (rev 231389)
+++ trunk/Source/WebCore/html/HTMLDocument.h	2018-05-04 23:52:43 UTC (rev 231390)
@@ -69,8 +69,8 @@
     Ref<DocumentParser> createParser() override;
     Ref<Document> cloneDocumentWithoutChildren() const final;
 
-    DocumentOrderedMap m_documentNamedItem;
-    DocumentOrderedMap m_windowNamedItem;
+    TreeScopeOrderedMap m_documentNamedItem;
+    TreeScopeOrderedMap m_windowNamedItem;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to