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

Unified Diff: Source/modules/fetch/Body.cpp

Issue 899653002: Use ExclusiveStreamReader to lock Body. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@exclusive-reader
Patch Set: rebase Created 5 years, 10 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
« no previous file with comments | « Source/modules/fetch/Body.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/fetch/Body.cpp
diff --git a/Source/modules/fetch/Body.cpp b/Source/modules/fetch/Body.cpp
index 892a13b10b8e8f415f58ccd49d951061b2143ab3..97e750314e5112c7ee716805fc2165dade5a56fb 100644
--- a/Source/modules/fetch/Body.cpp
+++ b/Source/modules/fetch/Body.cpp
@@ -15,6 +15,7 @@
#include "core/fileapi/FileReaderLoader.h"
#include "core/fileapi/FileReaderLoaderClient.h"
#include "core/frame/UseCounter.h"
+#include "core/streams/ExclusiveStreamReader.h"
#include "core/streams/UnderlyingSource.h"
#include "modules/fetch/BodyStreamBuffer.h"
@@ -233,7 +234,7 @@ private:
ScriptPromise Body::readAsync(ScriptState* scriptState, ResponseType type)
{
- if (m_bodyUsed)
+ if (bodyUsed())
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Already read"));
// When the main thread sends a V8::TerminateExecution() signal to a worker
@@ -246,7 +247,7 @@ ScriptPromise Body::readAsync(ScriptState* scriptState, ResponseType type)
if (!executionContext)
return ScriptPromise();
- m_bodyUsed = true;
+ setBodyUsed();
m_responseType = type;
ASSERT(!m_resolver);
@@ -346,11 +347,20 @@ ReadableStream* Body::body()
bool Body::bodyUsed() const
{
- return m_bodyUsed;
+ return m_bodyUsed || (m_stream && m_stream->isLocked());
}
void Body::setBodyUsed()
{
+ ASSERT(!m_bodyUsed);
+ ASSERT(!m_stream || !m_stream->isLocked());
+ // Note that technically we can set BodyUsed even when the stream is
+ // closed or errored, but getReader doesn't work then.
+ if (m_stream && m_stream->stateInternal() != ReadableStream::Closed && m_stream->stateInternal() != ReadableStream::Errored) {
+ TrackExceptionState exceptionState;
+ m_streamReader = m_stream->getReader(exceptionState);
+ ASSERT(!exceptionState.hadException());
+ }
m_bodyUsed = true;
}
@@ -391,6 +401,7 @@ DEFINE_TRACE(Body)
visitor->trace(m_resolver);
visitor->trace(m_stream);
visitor->trace(m_streamSource);
+ visitor->trace(m_streamReader);
ActiveDOMObject::trace(visitor);
}
« no previous file with comments | « Source/modules/fetch/Body.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698