Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: third_party/WebKit/Source/core/dom/DocumentOrderedMap.h

Issue 1555653002: Handle some failing DocumentOrderedMap ID lookups across tree removals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: non-assert buildfix Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 #include "wtf/HashMap.h" 37 #include "wtf/HashMap.h"
38 #include "wtf/text/AtomicString.h" 38 #include "wtf/text/AtomicString.h"
39 #include "wtf/text/AtomicStringHash.h" 39 #include "wtf/text/AtomicStringHash.h"
40 #include "wtf/text/StringImpl.h" 40 #include "wtf/text/StringImpl.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class Element; 44 class Element;
45 class TreeScope; 45 class TreeScope;
46 46
47 class DocumentOrderedMap : public NoBaseWillBeGarbageCollectedFinalized<Document OrderedMap> { 47 class DocumentOrderedMap : public NoBaseWillBeGarbageCollected<DocumentOrderedMa p> {
48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); 48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap);
49 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentOrderedMap);
49 public: 50 public:
50 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); 51 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create();
51 ~DocumentOrderedMap();
52 52
53 void add(const AtomicString&, Element*); 53 void add(const AtomicString&, Element*);
54 void remove(const AtomicString&, Element*); 54 void remove(const AtomicString&, Element*);
55 55
56 bool contains(const AtomicString&) const; 56 bool contains(const AtomicString&) const;
57 bool containsMultiple(const AtomicString&) const; 57 bool containsMultiple(const AtomicString&) const;
58 // concrete instantiations of the get<>() method template 58 // concrete instantiations of the get<>() method template
59 Element* getElementById(const AtomicString&, const TreeScope*) const; 59 Element* getElementById(const AtomicString&, const TreeScope*) const;
60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons t AtomicString&, const TreeScope*) const; 60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons t AtomicString&, const TreeScope*) const;
61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; 61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const;
62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope* ) const; 62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope* ) const;
63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope* ) const; 63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope* ) const;
64 64
65 DECLARE_TRACE(); 65 DECLARE_TRACE();
66 66
67 #if ENABLE(ASSERT) 67 #if ENABLE(ASSERT)
68 void willRemoveId(const AtomicString&); 68 // While removing a ContainerNode, ID lookups won't be precise should the tr ee
69 // have elements with duplicate IDs contained in the element being removed.
70 // Rare trees, but ID lookups may legitimately fail across such removals;
71 // this scope object informs DocumentOrderedMaps about the transitory
72 // state of the underlying tree.
73 class RemoveScope {
74 STACK_ALLOCATED();
75 public:
76 RemoveScope();
77 ~RemoveScope();
78 };
79 #else
80 class RemoveScope {
81 STACK_ALLOCATED();
82 public:
83 RemoveScope() { }
84 ~RemoveScope() { }
85 };
69 #endif 86 #endif
70 87
71 private: 88 private:
72 DocumentOrderedMap(); 89 DocumentOrderedMap();
73 90
74 template<bool keyMatches(const AtomicString&, const Element&)> 91 template<bool keyMatches(const AtomicString&, const Element&)>
75 Element* get(const AtomicString&, const TreeScope*) const; 92 Element* get(const AtomicString&, const TreeScope*) const;
76 93
77 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { 94 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> {
78 public: 95 public:
79 explicit MapEntry(Element* firstElement) 96 explicit MapEntry(Element* firstElement)
80 : element(firstElement) 97 : element(firstElement)
81 , count(1) 98 , count(1)
82 { 99 {
83 } 100 }
84 101
85 DECLARE_TRACE(); 102 DECLARE_TRACE();
86 103
87 RawPtrWillBeMember<Element> element; 104 RawPtrWillBeMember<Element> element;
88 unsigned count; 105 unsigned count;
89 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; 106 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList;
90 }; 107 };
91 108
92 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; 109 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>;
93 110
94 mutable Map m_map; 111 mutable Map m_map;
95 #if ENABLE(ASSERT)
96 AtomicString m_removingId;
97 #endif
98 }; 112 };
99 113
100 inline bool DocumentOrderedMap::contains(const AtomicString& id) const 114 inline bool DocumentOrderedMap::contains(const AtomicString& id) const
101 { 115 {
102 return m_map.contains(id); 116 return m_map.contains(id);
103 } 117 }
104 118
105 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const 119 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const
106 { 120 {
107 Map::const_iterator it = m_map.find(id); 121 Map::const_iterator it = m_map.find(id);
108 return it != m_map.end() && it->value->count > 1; 122 return it != m_map.end() && it->value->count > 1;
109 } 123 }
110 124
111 } // namespace blink 125 } // namespace blink
112 126
113 #endif // DocumentOrderedMap_h 127 #endif // DocumentOrderedMap_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ContainerNode.cpp ('k') | third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698