Title: [197347] trunk/Source/WebCore
Revision
197347
Author
[email protected]
Date
2016-02-29 05:01:51 -0800 (Mon, 29 Feb 2016)

Log Message

Refactor FetchBody constructors
https://bugs.webkit.org/show_bug.cgi?id=154721

Reviewed by Sam Weinig and Darin Adler.

Covered by existing tests.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract): Renamed from "fromJSValue"
(WebCore::FetchBody::extractFromBody): Renamed from "fromRequestBody" and making use of move constructor.
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::FetchBody): Making default constructor public and removing empty static method.
* Modules/fetch/FetchRequest.cpp:
(WebCore::buildBody):
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::error):
(WebCore::FetchResponse::redirect):
(WebCore::FetchResponse::initializeWith):
* Modules/fetch/FetchResponse.h:
(WebCore::FetchResponse::create):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197346 => 197347)


--- trunk/Source/WebCore/ChangeLog	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/ChangeLog	2016-02-29 13:01:51 UTC (rev 197347)
@@ -1,3 +1,26 @@
+2016-02-29  Youenn Fablet  <[email protected]>
+
+        Refactor FetchBody constructors
+        https://bugs.webkit.org/show_bug.cgi?id=154721
+
+        Reviewed by Sam Weinig and Darin Adler.
+
+        Covered by existing tests.
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::extract): Renamed from "fromJSValue"
+        (WebCore::FetchBody::extractFromBody): Renamed from "fromRequestBody" and making use of move constructor.
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::FetchBody): Making default constructor public and removing empty static method.
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::buildBody):
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::error):
+        (WebCore::FetchResponse::redirect):
+        (WebCore::FetchResponse::initializeWith):
+        * Modules/fetch/FetchResponse.h:
+        (WebCore::FetchResponse::create):
+
 2016-02-28  Antti Koivisto  <[email protected]>
 
         ::slotted doesn't work in nested shadow trees

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (197346 => 197347)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-02-29 13:01:51 UTC (rev 197347)
@@ -61,7 +61,7 @@
 {
 }
 
-FetchBody FetchBody::fromJSValue(JSC::ExecState& state, JSC::JSValue value)
+FetchBody FetchBody::extract(JSC::ExecState& state, JSC::JSValue value)
 {
     if (value.inherits(JSBlob::info()))
         return FetchBody(*JSBlob::toWrapped(value));
@@ -69,27 +69,16 @@
         return FetchBody(*JSDOMFormData::toWrapped(value));
     if (value.isString())
         return FetchBody(value.toWTFString(&state));
-    return FetchBody();
+    return { };
 }
 
-// FIXME: Once FetchResponse is added, check whether using a move constructor instead.
-// Ensure whether resetting m_mimeType to the empty string be not observable.
-FetchBody FetchBody::fromRequestBody(FetchBody* body)
+FetchBody FetchBody::extractFromBody(FetchBody* body)
 {
     if (!body)
-        return FetchBody();
+        return { };
 
-    FetchBody result;
-    result.m_type = body->m_type;
-    result.m_mimeType = body->m_mimeType;
-
-    result.m_blob = WTFMove(body->m_blob);
-    result.m_formData = WTFMove(body->m_formData);
-    result.m_text = WTFMove(body->m_text);
-
     body->m_isDisturbed = true;
-
-    return result;
+    return FetchBody(WTFMove(*body));
 }
 
 template<typename T> inline bool FetchBody::processIfEmptyOrDisturbed(DOMPromise<T, ExceptionCode>& promise)

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (197346 => 197347)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.h	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h	2016-02-29 13:01:51 UTC (rev 197347)
@@ -68,9 +68,9 @@
     void setMimeType(const String& mimeType) { m_mimeType = mimeType; }
     String mimeType() const { return m_mimeType; }
 
-    static FetchBody fromJSValue(JSC::ExecState&, JSC::JSValue);
-    static FetchBody fromRequestBody(FetchBody*);
-    static FetchBody empty() { return FetchBody(); }
+    static FetchBody extract(JSC::ExecState&, JSC::JSValue);
+    static FetchBody extractFromBody(FetchBody*);
+    FetchBody() = default;
 
 private:
     template<typename T> bool processIfEmptyOrDisturbed(DOMPromise<T, ExceptionCode>&);
@@ -80,7 +80,6 @@
     FetchBody(Ref<Blob>&&);
     FetchBody(Ref<DOMFormData>&&);
     FetchBody(String&&);
-    FetchBody() { }
 
     Type m_type = Type::None;
     String m_mimeType;

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (197346 => 197347)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-02-29 13:01:51 UTC (rev 197347)
@@ -216,7 +216,7 @@
 {
     JSC::JSValue value;
     bool hasInitBody = init.get("body", value);
-    FetchBody body = hasInitBody ? FetchBody::fromJSValue(*init.execState(), value) : FetchBody::fromRequestBody(inputBody);
+    FetchBody body = hasInitBody ? FetchBody::extract(*init.execState(), value) : FetchBody::extractFromBody(inputBody);
 
     String type = headers.fastGet(HTTPHeaderName::ContentType);
     if (hasInitBody && type.isEmpty() && !body.mimeType().isEmpty()) {

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (197346 => 197347)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-02-29 13:01:51 UTC (rev 197347)
@@ -50,7 +50,7 @@
 
 Ref<FetchResponse> FetchResponse::error()
 {
-    return adoptRef(*new FetchResponse(Type::Error, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+    return adoptRef(*new FetchResponse(Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
 }
 
 RefPtr<FetchResponse> FetchResponse::redirect(ScriptExecutionContext* context, const String& url, int status, ExceptionCode& ec)
@@ -65,7 +65,7 @@
         ec = TypeError;
         return nullptr;
     }
-    RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(Type::Default, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+    RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
     redirectResponse->m_response.setHTTPStatusCode(status);
     redirectResponse->m_headers->fastSet(HTTPHeaderName::Location, requestURL.string());
     return redirectResponse;
@@ -102,7 +102,7 @@
             ec = TypeError;
             return;
         }
-        m_body = FetchBody::fromJSValue(*init.execState(), body);
+        m_body = FetchBody::extract(*init.execState(), body);
         if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty())
             m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType());
     }

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (197346 => 197347)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-02-29 11:47:14 UTC (rev 197346)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-02-29 13:01:51 UTC (rev 197347)
@@ -47,7 +47,7 @@
 
 class FetchResponse : public RefCounted<FetchResponse> {
 public:
-    static Ref<FetchResponse> create() { return adoptRef(*new FetchResponse(Type::Default, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
+    static Ref<FetchResponse> create() { return adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
     static Ref<FetchResponse> error();
     static RefPtr<FetchResponse> redirect(ScriptExecutionContext*, const String&, int, ExceptionCode&);
     // FIXME: Binding generator should not require below method to handle optional status parameter.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to