Title: [153970] trunk/Source/WebCore
Revision
153970
Author
[email protected]
Date
2013-08-12 18:12:18 -0700 (Mon, 12 Aug 2013)

Log Message

Encapsulate access to documentNamedItemMap and windowNamedItemMap
https://bugs.webkit.org/show_bug.cgi?id=119701

Reviewed by Darin Adler.

Encapsulate m_documentNamedItem and m_windowNamedItem by adding various methods on HTMLDocument.
This will help us doing more refactorings in the future.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
(WebCore::JSDOMWindow::getOwnPropertyDescriptor):
* bindings/js/JSHTMLDocumentCustom.cpp:
(WebCore::JSHTMLDocument::canGetItemsForName):
(WebCore::JSHTMLDocument::nameGetter):
* dom/Element.cpp:
(WebCore::Element::updateNameForDocument):
(WebCore::Element::updateIdForDocument):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::addDocumentNamedItem): Added.
(WebCore::HTMLDocument::removeDocumentNamedItem): Added.
(WebCore::HTMLDocument::addWindowNamedItem): Added.
(WebCore::HTMLDocument::removeWindowNamedItem): Added.
* html/HTMLDocument.h:
(WebCore::HTMLDocument::documentNamedItem): Added.
(WebCore::HTMLDocument::hasDocumentNamedItem): Added.
(WebCore::HTMLDocument::documentNamedItemContainsMultipleElements): Added.
(WebCore::HTMLDocument::windowNamedItem): Added.
(WebCore::HTMLDocument::hasWindowNamedItem): Added.
(WebCore::HTMLDocument::windowNamedItemContainsMultipleElements): Added.
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153969 => 153970)


--- trunk/Source/WebCore/ChangeLog	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/ChangeLog	2013-08-13 01:12:18 UTC (rev 153970)
@@ -1,3 +1,41 @@
+2013-08-12  Ryosuke Niwa  <[email protected]>
+
+        Encapsulate access to documentNamedItemMap and windowNamedItemMap
+        https://bugs.webkit.org/show_bug.cgi?id=119701
+
+        Reviewed by Darin Adler.
+
+        Encapsulate m_documentNamedItem and m_windowNamedItem by adding various methods on HTMLDocument.
+        This will help us doing more refactorings in the future.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::namedItemGetter):
+        (WebCore::JSDOMWindow::getOwnPropertySlot):
+        (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+        (WebCore::JSDOMWindow::getOwnPropertyDescriptor):
+        * bindings/js/JSHTMLDocumentCustom.cpp:
+        (WebCore::JSHTMLDocument::canGetItemsForName):
+        (WebCore::JSHTMLDocument::nameGetter):
+        * dom/Element.cpp:
+        (WebCore::Element::updateNameForDocument):
+        (WebCore::Element::updateIdForDocument):
+        * html/HTMLDocument.cpp:
+        (WebCore::HTMLDocument::addDocumentNamedItem): Added.
+        (WebCore::HTMLDocument::removeDocumentNamedItem): Added.
+        (WebCore::HTMLDocument::addWindowNamedItem): Added.
+        (WebCore::HTMLDocument::removeWindowNamedItem): Added.
+        * html/HTMLDocument.h:
+        (WebCore::HTMLDocument::documentNamedItem): Added.
+        (WebCore::HTMLDocument::hasDocumentNamedItem): Added.
+        (WebCore::HTMLDocument::documentNamedItemContainsMultipleElements): Added.
+        (WebCore::HTMLDocument::windowNamedItem): Added.
+        (WebCore::HTMLDocument::hasWindowNamedItem): Added.
+        (WebCore::HTMLDocument::windowNamedItemContainsMultipleElements): Added.
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseAttribute):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+
 2013-08-12  Patrick Gansterer  <[email protected]>
 
         [CMake] Use the correct list of files when compiling ANGLESupport on Windows

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (153969 => 153970)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -96,18 +96,17 @@
     ASSERT(document->isHTMLDocument());
 
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    if (!atomicPropertyName || !toHTMLDocument(document)->windowNamedItemMap().contains(atomicPropertyName))
+    if (!atomicPropertyName || !toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName))
         return jsUndefined();
 
-    if (UNLIKELY(!toHTMLDocument(document)->windowNamedItemMap().containsSingle(atomicPropertyName))) {
+    if (UNLIKELY(toHTMLDocument(document)->windowNamedItemContainsMultipleElements(atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
         ASSERT(!collection->isEmpty());
         ASSERT(!collection->hasExactlyOneItem());
         return toJS(exec, thisObj->globalObject(), WTF::getPtr(collection));
     }
 
-    Node* node = toHTMLDocument(document)->windowNamedItemMap().getElementByWindowNamedItem(atomicPropertyName, document);
-    return toJS(exec, thisObj->globalObject(), node);
+    return toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(atomicPropertyName));
 }
 
 bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
@@ -247,7 +246,7 @@
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && toHTMLDocument(document)->windowNamedItemMap().contains(atomicPropertyName)) {
+        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName)) {
             slot.setCustom(thisObject, namedItemGetter);
             return true;
         }
@@ -323,7 +322,7 @@
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && toHTMLDocument(document)->windowNamedItemMap().contains(atomicPropertyName)) {
+        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName)) {
             slot.setCustom(thisObject, namedItemGetter);
             return true;
         }
@@ -394,7 +393,7 @@
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && toHTMLDocument(document)->windowNamedItemMap().contains(atomicPropertyName)) {
+        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName)) {
             PropertySlot slot(thisObject);
             slot.setCustom(thisObject, namedItemGetter);
             descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);

Modified: trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp (153969 => 153970)


--- trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -54,7 +54,7 @@
 bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* document, PropertyName propertyName)
 {
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    return atomicPropertyName && document->documentNamedItemMap().contains(atomicPropertyName);
+    return atomicPropertyName && document->hasDocumentNamedItem(atomicPropertyName);
 }
 
 JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName)
@@ -63,17 +63,17 @@
     HTMLDocument* document = toHTMLDocument(thisObj->impl());
 
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    if (!atomicPropertyName || !document->documentNamedItemMap().contains(atomicPropertyName))
+    if (!atomicPropertyName || !document->hasDocumentNamedItem(atomicPropertyName))
         return jsUndefined();
 
-    if (UNLIKELY(!document->documentNamedItemMap().containsSingle(atomicPropertyName))) {
+    if (UNLIKELY(document->documentNamedItemContainsMultipleElements(atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->documentNamedItems(atomicPropertyName);
         ASSERT(!collection->isEmpty());
         ASSERT(!collection->hasExactlyOneItem());
         return toJS(exec, thisObj->globalObject(), WTF::getPtr(collection));
     }
 
-    Node* node = document->documentNamedItemMap().getElementByDocumentNamedItem(atomicPropertyName, document);
+    Node* node = document->documentNamedItem(atomicPropertyName);
     Frame* frame;
     if (node->hasTagName(iframeTag) && (frame = toHTMLIFrameElement(node)->contentFrame()))
         return toJS(exec, frame);

Modified: trunk/Source/WebCore/dom/Element.cpp (153969 => 153970)


--- trunk/Source/WebCore/dom/Element.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/dom/Element.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -2740,17 +2740,17 @@
     if (WindowNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
         const AtomicString& id = WindowNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
         if (!oldName.isEmpty() && oldName != id)
-            document->windowNamedItemMap().remove(oldName.impl(), this);
+            document->removeWindowNamedItem(oldName, this);
         if (!newName.isEmpty() && newName != id)
-            document->windowNamedItemMap().add(newName.impl(), this);
+            document->addWindowNamedItem(newName, this);
     }
 
     if (DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
         const AtomicString& id = DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
         if (!oldName.isEmpty() && oldName != id)
-            document->documentNamedItemMap().remove(oldName.impl(), this);
+            document->removeDocumentNamedItem(oldName, this);
         if (!newName.isEmpty() && newName != id)
-            document->documentNamedItemMap().add(newName.impl(), this);
+            document->addDocumentNamedItem(newName, this);
     }
 }
 
@@ -2791,17 +2791,17 @@
     if (WindowNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
         const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && WindowNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
         if (!oldId.isEmpty() && oldId != name)
-            document->windowNamedItemMap().remove(oldId.impl(), this);
+            document->removeWindowNamedItem(oldId, this);
         if (!newId.isEmpty() && newId != name)
-            document->windowNamedItemMap().add(newId.impl(), this);
+            document->addWindowNamedItem(newId, this);
     }
 
     if (DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
         const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
         if (!oldId.isEmpty() && oldId != name)
-            document->documentNamedItemMap().remove(oldId.impl(), this);
+            document->removeDocumentNamedItem(oldId, this);
         if (!newId.isEmpty() && newId != name)
-            document->documentNamedItemMap().add(newId.impl(), this);
+            document->addDocumentNamedItem(newId, this);
     }
 }
 

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (153969 => 153970)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -355,6 +355,26 @@
     return attrSet;
 }
 
+void HTMLDocument::addDocumentNamedItem(const AtomicString& name, Element* item)
+{
+    m_documentNamedItem.add(name.impl(), item);
+}
+
+void HTMLDocument::removeDocumentNamedItem(const AtomicString& name, Element* item)
+{
+    m_documentNamedItem.remove(name.impl(), item);
+}
+
+void HTMLDocument::addWindowNamedItem(const AtomicString& name, Element* item)
+{
+    m_windowNamedItem.add(name.impl(), item);
+}
+
+void HTMLDocument::removeWindowNamedItem(const AtomicString& name, Element* item)
+{
+    m_windowNamedItem.remove(name.impl(), item);
+}
+
 bool HTMLDocument::isCaseSensitiveAttribute(const QualifiedName& attributeName)
 {
     static HashSet<AtomicStringImpl*>* htmlCaseInsensitiveAttributesSet = createHtmlCaseInsensitiveAttributesSet();

Modified: trunk/Source/WebCore/html/HTMLDocument.h (153969 => 153970)


--- trunk/Source/WebCore/html/HTMLDocument.h	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/html/HTMLDocument.h	2013-08-13 01:12:18 UTC (rev 153970)
@@ -68,9 +68,18 @@
     void captureEvents();
     void releaseEvents();
 
-    DocumentOrderedMap& documentNamedItemMap() { return m_documentNamedItem; }
-    DocumentOrderedMap& windowNamedItemMap() { return m_windowNamedItem; }
+    Element* documentNamedItem(const AtomicStringImpl* name) const { return m_documentNamedItem.getElementByDocumentNamedItem(name, this); }
+    bool hasDocumentNamedItem(const AtomicStringImpl* name) const { return m_documentNamedItem.contains(name); }
+    bool documentNamedItemContainsMultipleElements(const AtomicStringImpl* name) const { return m_documentNamedItem.containsMultiple(name); }
+    void addDocumentNamedItem(const AtomicString&, Element*);
+    void removeDocumentNamedItem(const AtomicString&, Element*);
 
+    Element* windowNamedItem(const AtomicStringImpl* name) const { return m_windowNamedItem.getElementByWindowNamedItem(name, this); }
+    bool hasWindowNamedItem(const AtomicStringImpl* name) const { return m_windowNamedItem.contains(name); }
+    bool windowNamedItemContainsMultipleElements(const AtomicStringImpl* name) const { return m_windowNamedItem.containsMultiple(name); }
+    void addWindowNamedItem(const AtomicString&, Element*);
+    void removeWindowNamedItem(const AtomicString&, Element*);
+
     static bool isCaseSensitiveAttribute(const QualifiedName&);
 
 protected:

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (153969 => 153970)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -144,9 +144,9 @@
                 const AtomicString& id = getIdAttribute();
                 if (!id.isEmpty() && id != getNameAttribute()) {
                     if (willHaveName)
-                        document->documentNamedItemMap().add(id.impl(), this);
+                        document->addDocumentNamedItem(id, this);
                     else
-                        document->documentNamedItemMap().remove(id.impl(), this);
+                        document->removeDocumentNamedItem(id, this);
                 }
             }
         }

Modified: trunk/Source/WebCore/html/HTMLObjectElement.cpp (153969 => 153970)


--- trunk/Source/WebCore/html/HTMLObjectElement.cpp	2013-08-13 01:10:07 UTC (rev 153969)
+++ trunk/Source/WebCore/html/HTMLObjectElement.cpp	2013-08-13 01:12:18 UTC (rev 153970)
@@ -445,17 +445,17 @@
         const AtomicString& id = getIdAttribute();
         if (!id.isEmpty()) {
             if (isNamedItem)
-                document->documentNamedItemMap().add(id.impl(), this);
+                document->addDocumentNamedItem(id, this);
             else
-                document->documentNamedItemMap().remove(id.impl(), this);
+                document->removeDocumentNamedItem(id, this);
         }
 
         const AtomicString& name = getNameAttribute();
         if (!name.isEmpty() && id != name) {
             if (isNamedItem)
-                document->documentNamedItemMap().add(name.impl(), this);
+                document->addDocumentNamedItem(name, this);
             else
-                document->documentNamedItemMap().remove(name.impl(), this);
+                document->removeDocumentNamedItem(name, this);
         }
     }
     m_docNamedItem = isNamedItem;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to