Title: [173885] trunk/Source/WebCore
Revision
173885
Author
[email protected]
Date
2014-09-23 12:53:08 -0700 (Tue, 23 Sep 2014)

Log Message

Have DOMImplementation::document() and Element::attributes() return references
https://bugs.webkit.org/show_bug.cgi?id=137035

Reviewed by Andreas Kling.

Have DOMImplementation::document() and Element::attributes() return
references instead of pointers as they can never return null.

No new tests, no behavior change.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
Update the JS Bindings code generator to use WTF::getPtr() in a couple
more places so that the implementation can return references instead
of pointers even when [GenerateIsReachable=xxx] IDL extended attribute
is used.

* dom/DOMImplementation.h:
(WebCore::DOMImplementation::document):
* dom/Element.cpp:
(WebCore::Element::attributes):
* dom/Element.h:
(WebCore::Node::attributes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173884 => 173885)


--- trunk/Source/WebCore/ChangeLog	2014-09-23 19:30:18 UTC (rev 173884)
+++ trunk/Source/WebCore/ChangeLog	2014-09-23 19:53:08 UTC (rev 173885)
@@ -1,5 +1,31 @@
 2014-09-23  Chris Dumez  <[email protected]>
 
+        Have DOMImplementation::document() and Element::attributes() return references
+        https://bugs.webkit.org/show_bug.cgi?id=137035
+
+        Reviewed by Andreas Kling.
+
+        Have DOMImplementation::document() and Element::attributes() return
+        references instead of pointers as they can never return null.
+
+        No new tests, no behavior change.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        Update the JS Bindings code generator to use WTF::getPtr() in a couple
+        more places so that the implementation can return references instead
+        of pointers even when [GenerateIsReachable=xxx] IDL extended attribute
+        is used.
+
+        * dom/DOMImplementation.h:
+        (WebCore::DOMImplementation::document):
+        * dom/Element.cpp:
+        (WebCore::Element::attributes):
+        * dom/Element.h:
+        (WebCore::Node::attributes):
+
+2014-09-23  Chris Dumez  <[email protected]>
+
         Have Document::ensureTemplateDocument() return a reference
         https://bugs.webkit.org/show_bug.cgi?id=137033
 

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (173884 => 173885)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2014-09-23 19:30:18 UTC (rev 173884)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2014-09-23 19:53:08 UTC (rev 173885)
@@ -2986,19 +2986,19 @@
             if (GetGenerateIsReachable($interface) eq "Impl") {
                 $rootString  = "    ${implType}* root = &js${interfaceName}->impl();\n";
             } elsif (GetGenerateIsReachable($interface) eq "ImplWebGLRenderingContext") {
-                $rootString  = "    WebGLRenderingContext* root = js${interfaceName}->impl().context();\n";
+                $rootString  = "    WebGLRenderingContext* root = WTF::getPtr(js${interfaceName}->impl().context());\n";
             } elsif (GetGenerateIsReachable($interface) eq "ImplFrame") {
-                $rootString  = "    Frame* root = js${interfaceName}->impl().frame();\n";
+                $rootString  = "    Frame* root = WTF::getPtr(js${interfaceName}->impl().frame());\n";
                 $rootString .= "    if (!root)\n";
                 $rootString .= "        return false;\n";
             } elsif (GetGenerateIsReachable($interface) eq "ImplDocument") {
-                $rootString  = "    Document* root = js${interfaceName}->impl().document();\n";
+                $rootString  = "    Document* root = WTF::getPtr(js${interfaceName}->impl().document());\n";
                 $rootString .= "    if (!root)\n";
                 $rootString .= "        return false;\n";
             } elsif (GetGenerateIsReachable($interface) eq "ImplElementRoot") {
                 $implIncludes{"Element.h"} = 1;
                 $implIncludes{"JSNodeCustom.h"} = 1;
-                $rootString  = "    Element* element = js${interfaceName}->impl().element();\n";
+                $rootString  = "    Element* element = WTF::getPtr(js${interfaceName}->impl().element());\n";
                 $rootString .= "    if (!element)\n";
                 $rootString .= "        return false;\n";
                 $rootString .= "    void* root = WebCore::root(element);\n";

Modified: trunk/Source/WebCore/dom/DOMImplementation.h (173884 => 173885)


--- trunk/Source/WebCore/dom/DOMImplementation.h	2014-09-23 19:30:18 UTC (rev 173884)
+++ trunk/Source/WebCore/dom/DOMImplementation.h	2014-09-23 19:53:08 UTC (rev 173885)
@@ -50,7 +50,7 @@
     
     void ref() { m_document.ref(); }
     void deref() { m_document.deref(); }
-    Document* document() { return &m_document; }
+    Document& document() { return m_document; }
 
     // DOM methods & attributes for DOMImplementation
     static bool hasFeature(const String& feature, const String& version);

Modified: trunk/Source/WebCore/dom/Element.cpp (173884 => 173885)


--- trunk/Source/WebCore/dom/Element.cpp	2014-09-23 19:30:18 UTC (rev 173884)
+++ trunk/Source/WebCore/dom/Element.cpp	2014-09-23 19:53:08 UTC (rev 173885)
@@ -352,14 +352,14 @@
         removeAttribute(name);
 }
 
-NamedNodeMap* Element::attributes() const
+NamedNodeMap& Element::attributes() const
 {
     ElementRareData& rareData = const_cast<Element*>(this)->ensureElementRareData();
     if (NamedNodeMap* attributeMap = rareData.attributeMap())
-        return attributeMap;
+        return *attributeMap;
 
     rareData.setAttributeMap(NamedNodeMap::create(const_cast<Element&>(*this)));
-    return rareData.attributeMap();
+    return *rareData.attributeMap();
 }
 
 Node::NodeType Element::nodeType() const

Modified: trunk/Source/WebCore/dom/Element.h (173884 => 173885)


--- trunk/Source/WebCore/dom/Element.h	2014-09-23 19:30:18 UTC (rev 173884)
+++ trunk/Source/WebCore/dom/Element.h	2014-09-23 19:53:08 UTC (rev 173885)
@@ -285,7 +285,7 @@
     void setBooleanAttribute(const QualifiedName& name, bool);
 
     // For exposing to DOM only.
-    NamedNodeMap* attributes() const;
+    NamedNodeMap& attributes() const;
 
     enum AttributeModificationReason {
         ModifiedDirectly,
@@ -711,7 +711,7 @@
 
 inline NamedNodeMap* Node::attributes() const
 {
-    return isElementNode() ? toElement(this)->attributes() : nullptr;
+    return isElementNode() ? &toElement(this)->attributes() : nullptr;
 }
 
 inline Element* Node::parentElement() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to