Cleanup XMLHttpRequestUpload a little
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 May 2018 23:45:15 +0000 (23:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 May 2018 23:45:15 +0000 (23:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185344

Patch by Sam Weinig <sam@webkit.org> on 2018-05-05
Reviewed by Yusuke Suzuki.

* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::visitAdditionalChildren):
Use auto to reduce redundancy.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::upload):
* xml/XMLHttpRequest.h:
Switch upload() to return a reference.

* xml/XMLHttpRequestUpload.cpp:
(WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload):
(WebCore::XMLHttpRequestUpload::dispatchProgressEvent):
* xml/XMLHttpRequestUpload.h:
Cleanup formatting, modernize and switch XMLHttpRequest member from a pointer
to a reference.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231398 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.h
Source/WebCore/xml/XMLHttpRequestUpload.cpp
Source/WebCore/xml/XMLHttpRequestUpload.h

index c5e9d01..7a6d26c 100644 (file)
@@ -1,3 +1,26 @@
+2018-05-05  Sam Weinig  <sam@webkit.org>
+
+        Cleanup XMLHttpRequestUpload a little
+        https://bugs.webkit.org/show_bug.cgi?id=185344
+
+        Reviewed by Yusuke Suzuki.
+
+        * bindings/js/JSXMLHttpRequestCustom.cpp:
+        (WebCore::JSXMLHttpRequest::visitAdditionalChildren):
+        Use auto to reduce redundancy.
+
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::upload):
+        * xml/XMLHttpRequest.h:
+        Switch upload() to return a reference.
+        
+        * xml/XMLHttpRequestUpload.cpp:
+        (WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload):
+        (WebCore::XMLHttpRequestUpload::dispatchProgressEvent):
+        * xml/XMLHttpRequestUpload.h:
+        Cleanup formatting, modernize and switch XMLHttpRequest member from a pointer
+        to a reference.
+
 2018-05-05  Dean Jackson  <dino@apple.com>
 
         Draw a drop-shadow behind the system preview badge
index 8362e69..4840bf2 100644 (file)
@@ -43,10 +43,10 @@ using namespace JSC;
 
 void JSXMLHttpRequest::visitAdditionalChildren(SlotVisitor& visitor)
 {
-    if (XMLHttpRequestUpload* upload = wrapped().optionalUpload())
+    if (auto* upload = wrapped().optionalUpload())
         visitor.addOpaqueRoot(upload);
 
-    if (Document* responseDocument = wrapped().optionalResponseXML())
+    if (auto* responseDocument = wrapped().optionalResponseXML())
         visitor.addOpaqueRoot(responseDocument);
 }
 
index 19e5ae4..53c0f23 100644 (file)
@@ -59,7 +59,6 @@
 #include <JavaScriptCore/ArrayBufferView.h>
 #include <JavaScriptCore/JSCInlines.h>
 #include <JavaScriptCore/JSLock.h>
-#include <mutex>
 #include <wtf/RefCountedLeakCounter.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/CString.h>
@@ -280,11 +279,11 @@ String XMLHttpRequest::responseURL() const
     return responseURL.string();
 }
 
-XMLHttpRequestUpload* XMLHttpRequest::upload()
+XMLHttpRequestUpload& XMLHttpRequest::upload()
 {
     if (!m_upload)
-        m_upload = std::make_unique<XMLHttpRequestUpload>(this);
-    return m_upload.get();
+        m_upload = std::make_unique<XMLHttpRequestUpload>(*this);
+    return *m_upload;
 }
 
 void XMLHttpRequest::changeState(State newState)
index 1eec158..e32d013 100644 (file)
@@ -108,7 +108,7 @@ public:
 
     String responseURL() const;
 
-    XMLHttpRequestUpload* upload();
+    XMLHttpRequestUpload& upload();
     XMLHttpRequestUpload* optionalUpload() const { return m_upload.get(); }
 
     const ResourceResponse& resourceResponse() const { return m_response; }
index c968099..36859b8 100644 (file)
 
 namespace WebCore {
 
-XMLHttpRequestUpload::XMLHttpRequestUpload(XMLHttpRequest* xmlHttpRequest)
+XMLHttpRequestUpload::XMLHttpRequestUpload(XMLHttpRequest& xmlHttpRequest)
     : m_xmlHttpRequest(xmlHttpRequest)
-    , m_lengthComputable(false)
-    , m_loaded(0)
-    , m_total(0)
 {
 }
 
@@ -51,7 +48,7 @@ void XMLHttpRequestUpload::dispatchThrottledProgressEvent(bool lengthComputable,
     dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total));
 }
 
-void XMLHttpRequestUpload::dispatchProgressEvent(const AtomicString &type)
+void XMLHttpRequestUpload::dispatchProgressEvent(const AtomicStringtype)
 {
     ASSERT(type == eventNames().loadstartEvent || type == eventNames().progressEvent || type == eventNames().loadEvent || type == eventNames().loadendEvent || type == eventNames().abortEvent || type == eventNames().errorEvent || type == eventNames().timeoutEvent);
 
index 3ef2a66..b13af61 100644 (file)
 
 namespace WebCore {
 
-    class ScriptExecutionContext;
-    class XMLHttpRequest;
-
-    class XMLHttpRequestUpload final : public XMLHttpRequestEventTarget {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        explicit XMLHttpRequestUpload(XMLHttpRequest*);
-
-        void ref() { m_xmlHttpRequest->ref(); }
-        void deref() { m_xmlHttpRequest->deref(); }
-        XMLHttpRequest* xmlHttpRequest() const { return m_xmlHttpRequest; }
-
-        EventTargetInterface eventTargetInterface() const override { return XMLHttpRequestUploadEventTargetInterfaceType; }
-        ScriptExecutionContext* scriptExecutionContext() const override { return m_xmlHttpRequest->scriptExecutionContext(); }
-
-        void dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total);
-        void dispatchProgressEvent(const AtomicString &type);
-
-    private:
-        void refEventTarget() final { ref(); }
-        void derefEventTarget() final { deref(); }
-
-        XMLHttpRequest* m_xmlHttpRequest;
-        bool m_lengthComputable;
-        unsigned long long m_loaded;
-        unsigned long long m_total;
-    };
+class XMLHttpRequestUpload final : public XMLHttpRequestEventTarget {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit XMLHttpRequestUpload(XMLHttpRequest&);
+
+    void ref() { m_xmlHttpRequest.ref(); }
+    void deref() { m_xmlHttpRequest.deref(); }
+    XMLHttpRequest& xmlHttpRequest() const { return m_xmlHttpRequest; }
+
+    EventTargetInterface eventTargetInterface() const override { return XMLHttpRequestUploadEventTargetInterfaceType; }
+    ScriptExecutionContext* scriptExecutionContext() const override { return m_xmlHttpRequest.scriptExecutionContext(); }
+
+    void dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total);
+    void dispatchProgressEvent(const AtomicString& type);
+
+private:
+    void refEventTarget() final { ref(); }
+    void derefEventTarget() final { deref(); }
+
+    XMLHttpRequest& m_xmlHttpRequest;
+    bool m_lengthComputable { false };
+    unsigned long long m_loaded { 0 };
+    unsigned long long m_total { 0 };
+};
     
 } // namespace WebCore