Diff
Modified: trunk/Source/WTF/ChangeLog (206437 => 206438)
--- trunk/Source/WTF/ChangeLog 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WTF/ChangeLog 2016-09-27 16:47:49 UTC (rev 206438)
@@ -1,3 +1,17 @@
+2016-09-27 Youenn Fablet <[email protected]>
+
+ [Fetch API] Use Ref<const T> in FetchBody::m_data variant
+ https://bugs.webkit.org/show_bug.cgi?id=162599
+
+ Reviewed by Alex Christensen.
+
+ Enabling to use DeferrableRefCounted<const T> by making m_refCount mutable.
+
+ * wtf/DeferrableRefCounted.h:
+ (WTF::DeferrableRefCountedBase::ref):
+ (WTF::DeferrableRefCountedBase::derefBase):
+ (WTF::DeferrableRefCounted::deref):
+
2016-09-26 Daniel Bates <[email protected]>
Rename IOS_TEXT_AUTOSIZING to TEXT_AUTOSIZING
Modified: trunk/Source/WTF/wtf/DeferrableRefCounted.h (206437 => 206438)
--- trunk/Source/WTF/wtf/DeferrableRefCounted.h 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WTF/wtf/DeferrableRefCounted.h 2016-09-27 16:47:49 UTC (rev 206438)
@@ -20,11 +20,10 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DeferrableRefCounted_h
-#define DeferrableRefCounted_h
+#pragma once
#include <wtf/Assertions.h>
#include <wtf/FastMalloc.h>
@@ -41,39 +40,39 @@
class DeferrableRefCountedBase {
static const unsigned deferredFlag = 1;
static const unsigned normalIncrement = 2;
-
+
public:
- void ref()
+ void ref() const
{
m_refCount += normalIncrement;
}
-
+
bool hasOneRef() const
{
return refCount() == 1;
}
-
+
unsigned refCount() const
{
return m_refCount / normalIncrement;
}
-
+
bool isDeferred() const
{
return !!(m_refCount & deferredFlag);
}
-
+
protected:
DeferrableRefCountedBase()
: m_refCount(normalIncrement)
{
}
-
+
~DeferrableRefCountedBase()
{
}
-
- bool derefBase()
+
+ bool derefBase() const
{
m_refCount -= normalIncrement;
return !m_refCount;
@@ -88,9 +87,9 @@
m_refCount &= ~deferredFlag;
return !m_refCount;
}
-
+
private:
- unsigned m_refCount;
+ mutable unsigned m_refCount;
};
template<typename T>
@@ -97,12 +96,12 @@
class DeferrableRefCounted : public DeferrableRefCountedBase {
WTF_MAKE_NONCOPYABLE(DeferrableRefCounted); WTF_MAKE_FAST_ALLOCATED;
public:
- void deref()
+ void deref() const
{
if (derefBase())
- delete static_cast<T*>(this);
+ delete static_cast<const T*>(this);
}
-
+
bool setIsDeferred(bool value)
{
if (!setIsDeferredBase(value))
@@ -110,7 +109,7 @@
delete static_cast<T*>(this);
return true;
}
-
+
protected:
DeferrableRefCounted() { }
~DeferrableRefCounted() { }
@@ -119,6 +118,3 @@
} // namespace WTF
using WTF::DeferrableRefCounted;
-
-#endif // DeferrableRefCounted_h
-
Modified: trunk/Source/WebCore/ChangeLog (206437 => 206438)
--- trunk/Source/WebCore/ChangeLog 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/ChangeLog 2016-09-27 16:47:49 UTC (rev 206438)
@@ -1,3 +1,30 @@
+2016-09-27 Youenn Fablet <[email protected]>
+
+ [Fetch API] Use Ref<const T> in FetchBody::m_data variant
+ https://bugs.webkit.org/show_bug.cgi?id=162599
+
+ Reviewed by Alex Christensen.
+
+ Covered by existing tests.
+
+ Using Ref<const T> for all variants of m_data except for FormData since FetchBody is actually creating it and may modifiy it.
+ Updating blob loading code path to use a const Blob& instead of a Blob&.
+
+ * Modules/fetch/FetchBody.cpp:
+ (WebCore::FetchBody::FetchBody):
+ (WebCore::FetchBody::extract):
+ (WebCore::FetchBody::clone):
+ * Modules/fetch/FetchBody.h:
+ (WebCore::FetchBody::blobBody):
+ (WebCore::FetchBody::arrayBufferBody):
+ (WebCore::FetchBody::arrayBufferViewBody):
+ * Modules/fetch/FetchBodyOwner.cpp:
+ (WebCore::FetchBodyOwner::loadBlob):
+ * Modules/fetch/FetchBodyOwner.h:
+ * Modules/fetch/FetchLoader.cpp:
+ (WebCore::FetchLoader::start):
+ * Modules/fetch/FetchLoader.h:
+
2016-09-27 Michael Catanzaro <[email protected]>
Unreviewed typo fix
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2016-09-27 16:47:49 UTC (rev 206438)
@@ -46,7 +46,7 @@
namespace WebCore {
-FetchBody::FetchBody(Ref<Blob>&& blob)
+FetchBody::FetchBody(Ref<const Blob>&& blob)
: m_type(Type::Blob)
, m_data(WTFMove(blob))
, m_contentType(this->blobBody().type())
@@ -67,13 +67,13 @@
{
}
-FetchBody::FetchBody(Ref<ArrayBuffer>&& data)
+FetchBody::FetchBody(Ref<const ArrayBuffer>&& data)
: m_type(Type::ArrayBuffer)
, m_data(WTFMove(data))
{
}
-FetchBody::FetchBody(Ref<ArrayBufferView>&& dataView)
+FetchBody::FetchBody(Ref<const ArrayBufferView>&& dataView)
: m_type(Type::ArrayBufferView)
, m_data(WTFMove(dataView))
{
@@ -104,9 +104,10 @@
return { *data };
}
if (value.inherits(JSC::JSArrayBufferView::info())) {
- RefPtr<JSC::ArrayBufferView> data = ""
+ auto data = ""
ASSERT(data);
- return { data.releaseNonNull() };
+ // FIXME: We should be able to efficiently get a Ref<const T> from a RefPtr<T>.
+ return { *data };
}
return { };
}
@@ -335,13 +336,13 @@
switch (m_type) {
case Type::ArrayBuffer:
- clone.m_data = const_cast<ArrayBuffer&>(arrayBufferBody());
+ clone.m_data = arrayBufferBody();
break;
case Type::ArrayBufferView:
- clone.m_data = const_cast<ArrayBufferView&>(arrayBufferViewBody());
+ clone.m_data = arrayBufferViewBody();
break;
case Type::Blob:
- clone.m_data = const_cast<Blob&>(blobBody());
+ clone.m_data = blobBody();
break;
case Type::FormData:
clone.m_data = const_cast<FormData&>(formDataBody());
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.h 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h 2016-09-27 16:47:49 UTC (rev 206438)
@@ -89,9 +89,9 @@
FetchBody clone() const;
private:
- FetchBody(Ref<Blob>&&);
- FetchBody(Ref<ArrayBuffer>&&);
- FetchBody(Ref<ArrayBufferView>&&);
+ FetchBody(Ref<const Blob>&&);
+ FetchBody(Ref<const ArrayBuffer>&&);
+ FetchBody(Ref<const ArrayBufferView>&&);
FetchBody(DOMFormData&, Document&);
FetchBody(String&&);
FetchBody(Type, const String&, const FetchBodyConsumer&);
@@ -105,14 +105,11 @@
void consumeText(Ref<DeferredPromise>&&);
void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
- Blob& blobBody() { return std::experimental::get<Ref<Blob>>(m_data).get(); }
- const Blob& blobBody() const { return std::experimental::get<Ref<Blob>>(m_data).get(); }
+ const Blob& blobBody() const { return std::experimental::get<Ref<const Blob>>(m_data).get(); }
FormData& formDataBody() { return std::experimental::get<Ref<FormData>>(m_data).get(); }
const FormData& formDataBody() const { return std::experimental::get<Ref<FormData>>(m_data).get(); }
- ArrayBuffer& arrayBufferBody() { return std::experimental::get<Ref<ArrayBuffer>>(m_data).get(); }
- const ArrayBuffer& arrayBufferBody() const { return std::experimental::get<Ref<ArrayBuffer>>(m_data).get(); }
- ArrayBufferView& arrayBufferViewBody() { return std::experimental::get<Ref<ArrayBufferView>>(m_data).get(); }
- const ArrayBufferView& arrayBufferViewBody() const { return std::experimental::get<Ref<ArrayBufferView>>(m_data).get(); }
+ const ArrayBuffer& arrayBufferBody() const { return std::experimental::get<Ref<const ArrayBuffer>>(m_data).get(); }
+ const ArrayBufferView& arrayBufferViewBody() const { return std::experimental::get<Ref<const ArrayBufferView>>(m_data).get(); }
String& textBody() { return std::experimental::get<String>(m_data); }
const String& textBody() const { return std::experimental::get<String>(m_data); }
@@ -119,7 +116,7 @@
Type m_type { Type::None };
// FIXME: Add support for URLSearchParams.
- std::experimental::variant<std::nullptr_t, Ref<Blob>, Ref<FormData>, Ref<ArrayBuffer>, Ref<ArrayBufferView>, String> m_data;
+ std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, String> m_data;
String m_contentType;
FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-09-27 16:47:49 UTC (rev 206438)
@@ -141,7 +141,7 @@
m_body.text(*this, WTFMove(promise));
}
-void FetchBodyOwner::loadBlob(Blob& blob, FetchBodyConsumer* consumer)
+void FetchBodyOwner::loadBlob(const Blob& blob, FetchBodyConsumer* consumer)
{
// Can only be called once for a body instance.
ASSERT(isDisturbed());
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-09-27 16:47:49 UTC (rev 206438)
@@ -54,7 +54,7 @@
bool isDisturbedOrLocked() const;
- void loadBlob(Blob&, FetchBodyConsumer*);
+ void loadBlob(const Blob&, FetchBodyConsumer*);
bool isActive() const { return !!m_blobLoader; }
Modified: trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp 2016-09-27 16:47:49 UTC (rev 206438)
@@ -47,7 +47,7 @@
namespace WebCore {
-void FetchLoader::start(ScriptExecutionContext& context, Blob& blob)
+void FetchLoader::start(ScriptExecutionContext& context, const Blob& blob)
{
auto urlForReading = BlobURL::createPublicURL(context.securityOrigin());
if (urlForReading.isEmpty()) {
Modified: trunk/Source/WebCore/Modules/fetch/FetchLoader.h (206437 => 206438)
--- trunk/Source/WebCore/Modules/fetch/FetchLoader.h 2016-09-27 16:02:10 UTC (rev 206437)
+++ trunk/Source/WebCore/Modules/fetch/FetchLoader.h 2016-09-27 16:47:49 UTC (rev 206438)
@@ -48,7 +48,7 @@
RefPtr<SharedBuffer> startStreaming();
void start(ScriptExecutionContext&, const FetchRequest&);
- void start(ScriptExecutionContext&, Blob&);
+ void start(ScriptExecutionContext&, const Blob&);
void stop();
bool isStarted() const { return m_isStarted; }