Skip to content
Permalink
Browse files
Move consume promise from FetchBody to FetchBodyConsumer
https://bugs.webkit.org/show_bug.cgi?id=176121

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-31
Reviewed by Alex Christensen.

No change of behavior.

FetchBodyConsumer should be made responsible for data consumption through promise getters and ReadableStream.
This will allow making data consumption consistent for Request and Response.
This patch is doing the first step.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeOnceLoadingFinished):
(WebCore::FetchBody::consumeBlob):
(WebCore::FetchBody::loadingFailed):
(WebCore::FetchBody::loadingSucceeded):
(WebCore::FetchBody::clone const):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::cleanConsumer):
(WebCore::FetchBody::cleanConsumePromise): Deleted.
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::setConsumePromise):
(WebCore::FetchBodyConsumer::loadingFailed):
(WebCore::FetchBodyConsumer::loadingSucceeded):
(WebCore::FetchBodyConsumer::clean):
* Modules/fetch/FetchBodyConsumer.h:
(WebCore::FetchBodyConsumer::clean): Deleted.
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::stop):

Canonical link: https://commits.webkit.org/192829@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221427 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf authored and webkit-commit-queue committed Aug 31, 2017
1 parent 3786b78 commit 15e5456296ee911c2f4fcc24d80c97e2a60a2a86
@@ -1,3 +1,35 @@
2017-08-31 Youenn Fablet <youenn@apple.com>

Move consume promise from FetchBody to FetchBodyConsumer
https://bugs.webkit.org/show_bug.cgi?id=176121

Reviewed by Alex Christensen.

No change of behavior.

FetchBodyConsumer should be made responsible for data consumption through promise getters and ReadableStream.
This will allow making data consumption consistent for Request and Response.
This patch is doing the first step.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeOnceLoadingFinished):
(WebCore::FetchBody::consumeBlob):
(WebCore::FetchBody::loadingFailed):
(WebCore::FetchBody::loadingSucceeded):
(WebCore::FetchBody::clone const):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::cleanConsumer):
(WebCore::FetchBody::cleanConsumePromise): Deleted.
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::setConsumePromise):
(WebCore::FetchBodyConsumer::loadingFailed):
(WebCore::FetchBodyConsumer::loadingSucceeded):
(WebCore::FetchBodyConsumer::clean):
* Modules/fetch/FetchBodyConsumer.h:
(WebCore::FetchBodyConsumer::clean): Deleted.
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::stop):

2017-08-22 Darin Adler <darin@apple.com>

REGRESSION (r220052): ASSERTION FAILED: !frame().isMainFrame() || !needsStyleRecalcOrLayout() in WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive()
@@ -105,7 +105,7 @@ void FetchBody::text(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
void FetchBody::consumeOnceLoadingFinished(FetchBodyConsumer::Type type, Ref<DeferredPromise>&& promise, const String& contentType)
{
m_consumer.setType(type);
m_consumePromise = WTFMove(promise);
m_consumer.setConsumePromise(WTFMove(promise));
if (type == FetchBodyConsumer::Type::Blob)
m_consumer.setContentType(Blob::normalizedContentType(extractMIMETypeFromMediaType(contentType)));
}
@@ -194,23 +194,19 @@ void FetchBody::consumeText(Ref<DeferredPromise>&& promise, const String& text)

void FetchBody::consumeBlob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
{
m_consumePromise = WTFMove(promise);
m_consumer.setConsumePromise(WTFMove(promise));
owner.loadBlob(blobBody(), &m_consumer);
m_data = nullptr;
}

void FetchBody::loadingFailed()
{
if (m_consumePromise) {
m_consumePromise->reject();
m_consumePromise = nullptr;
}
m_consumer.loadingFailed();
}

void FetchBody::loadingSucceeded()
{
if (m_consumePromise)
m_consumer.resolve(m_consumePromise.releaseNonNull());
m_consumer.loadingSucceeded();
}

RefPtr<FormData> FetchBody::bodyAsFormData(ScriptExecutionContext& context) const
@@ -276,7 +272,6 @@ FetchBody::TakenData FetchBody::take()

FetchBody FetchBody::clone() const
{
ASSERT(!m_consumePromise);
FetchBody clone(m_consumer);

if (isArrayBuffer())
@@ -78,7 +78,7 @@ class FetchBody {
FetchBodyConsumer& consumer() { return m_consumer; }

void consumeOnceLoadingFinished(FetchBodyConsumer::Type, Ref<DeferredPromise>&&, const String&);
void cleanConsumePromise() { m_consumePromise = nullptr; }
void cleanConsumer() { m_consumer.clean(); }

FetchBody clone() const;
ReadableStream* readableStream() { return m_readableStream.get(); }
@@ -119,7 +119,6 @@ class FetchBody {
Data m_data { nullptr };

FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
RefPtr<DeferredPromise> m_consumePromise;
RefPtr<ReadableStream> m_readableStream;
};

@@ -148,4 +148,30 @@ String FetchBodyConsumer::takeAsText()
return text;
}

void FetchBodyConsumer::setConsumePromise(Ref<DeferredPromise>&& promise)
{
ASSERT(!m_consumePromise);
m_consumePromise = WTFMove(promise);
}

void FetchBodyConsumer::loadingFailed()
{
if (m_consumePromise) {
m_consumePromise->reject();
m_consumePromise = nullptr;
}
}

void FetchBodyConsumer::loadingSucceeded()
{
if (m_consumePromise)
resolve(m_consumePromise.releaseNonNull());
}

void FetchBodyConsumer::clean()
{
m_buffer = nullptr;
m_consumePromise = nullptr;
}

} // namespace WebCore
@@ -55,17 +55,23 @@ class FetchBodyConsumer {
void setContentType(const String& contentType) { m_contentType = contentType; }
void setType(Type type) { m_type = type; }

void clean() { m_buffer = nullptr; }
void clean();

void resolve(Ref<DeferredPromise>&&);
void resolveWithData(Ref<DeferredPromise>&&, const unsigned char*, unsigned);

bool hasData() const { return !!m_buffer; }

void loadingFailed();
void loadingSucceeded();

void setConsumePromise(Ref<DeferredPromise>&&);

private:
Type m_type;
String m_contentType;
RefPtr<SharedBuffer> m_buffer;
RefPtr<DeferredPromise> m_consumePromise;
};

} // namespace WebCore
@@ -48,7 +48,7 @@ FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, std::optional<Fe
void FetchBodyOwner::stop()
{
if (m_body)
m_body->cleanConsumePromise();
m_body->cleanConsumer();

if (m_blobLoader) {
bool isUniqueReference = hasOneRef();

0 comments on commit 15e5456

Please sign in to comment.