Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp

Issue 1969333002: [Fetch API] |(new Response(stream)).body| should return |stream| (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp b/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
index 9eec54a24245ef5dd7d7b8f15eb97104eff97f15..0eff04e1895884269705097c52e78357b900418d 100644
--- a/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
+++ b/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
@@ -13,6 +13,7 @@
#include "core/streams/ReadableStreamOperations.h"
#include "modules/fetch/Body.h"
#include "modules/fetch/DataConsumerHandleUtil.h"
+#include "modules/fetch/ReadableStreamDataConsumerHandle.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/blob/BlobData.h"
#include "platform/network/EncodedFormData.h"
@@ -84,6 +85,7 @@ BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat
, m_scriptState(scriptState)
, m_handle(std::move(handle))
, m_reader(m_handle->obtainReader(this))
+ , m_madeFromReadableStream(false)
{
if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) {
ScriptState::Scope scope(scriptState);
@@ -101,6 +103,22 @@ BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat
}
}
+BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream)
+ : UnderlyingSourceBase(scriptState)
+ , m_scriptState(scriptState)
+ , m_madeFromReadableStream(true)
+{
+ ScriptState::Scope scope(scriptState);
+ ASSERT(RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled());
+ ASSERT(ReadableStreamOperations::isReadableStream(scriptState, stream));
haraken 2016/05/12 08:22:57 Use DCHECK.
yhirano 2016/05/12 08:28:15 Done.
+ v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
+ ASSERT(!bodyValue.IsEmpty());
+ ASSERT(bodyValue->IsObject());
+ v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
+
+ V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBodyStream(scriptState->isolate()), stream.v8Value());
+}
+
ScriptValue BodyStreamBuffer::stream()
{
ScriptState::Scope scope(m_scriptState.get());
@@ -121,6 +139,9 @@ PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
if (isStreamClosed() || isStreamErrored())
return nullptr;
+ if (m_madeFromReadableStream)
+ return nullptr;
+
RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(policy);
if (blobDataHandle) {
closeAndLockAndDisturb();
@@ -136,6 +157,9 @@ PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData()
if (isStreamClosed() || isStreamErrored())
return nullptr;
+ if (m_madeFromReadableStream)
+ return nullptr;
+
RefPtr<EncodedFormData> formData = m_reader->drainAsFormData();
if (formData) {
closeAndLockAndDisturb();
@@ -148,6 +172,19 @@ PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle()
{
ASSERT(!isStreamLocked());
ASSERT(!isStreamDisturbed());
+
+ if (m_madeFromReadableStream) {
+ ScriptState::Scope scope(m_scriptState.get());
+ NonThrowableExceptionState exceptionState;
+ ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.get(), stream(), exceptionState);
haraken 2016/05/12 08:22:57 Is it okay to ignore the exception?
yhirano 2016/05/12 08:28:15 Yes. It throws an exception only when locked, and
+ // We need to have |reader| alive by some means (as written in
+ // ReadableStreamDataConsumerHandle). |this| BodyStreamBuffer will be
+ // kept alive while the stream is locked and readable, and the stream
+ // has a reference to the reader. Hence we don't need to keep the reader
+ // explicitly.
+ return ReadableStreamDataConsumerHandle::create(m_scriptState.get(), reader);
+ }
+
// We need to call these before calling closeAndLockAndDisturb.
const bool isClosed = isStreamClosed();
const bool isErrored = isStreamErrored();

Powered by Google App Engine
This is Rietveld 408576698