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

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

Issue 1539803002: [Fetch API] Fix a memory leak with a Response constructed with a ReadableStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@response-constructed-with-stream
Patch Set: Created 4 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 | « third_party/WebKit/Source/modules/fetch/ReadableStreamDataConsumerHandleTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/fetch/Response.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/Response.cpp b/third_party/WebKit/Source/modules/fetch/Response.cpp
index 959d0d8d40d3f9587d240700ac6ffcb446c981af..71a57825d1b8c1dd0f305410b7532dc465492bd4 100644
--- a/third_party/WebKit/Source/modules/fetch/Response.cpp
+++ b/third_party/WebKit/Source/modules/fetch/Response.cpp
@@ -13,11 +13,13 @@
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8Blob.h"
#include "bindings/core/v8/V8FormData.h"
+#include "bindings/core/v8/V8HiddenValue.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMArrayBufferView.h"
#include "core/fileapi/Blob.h"
#include "core/html/FormData.h"
#include "modules/fetch/BodyStreamBuffer.h"
+#include "modules/fetch/DataConsumerHandleUtil.h"
#include "modules/fetch/FetchBlobDataConsumerHandle.h"
#include "modules/fetch/FetchFormDataConsumerHandle.h"
#include "modules/fetch/ReadableStreamDataConsumerHandle.h"
@@ -111,6 +113,7 @@ Response* Response::create(ScriptState* scriptState, ExceptionState& exceptionSt
Response* Response::create(ScriptState* scriptState, ScriptValue bodyValue, const Dictionary& init, ExceptionState& exceptionState)
{
v8::Local<v8::Value> body = bodyValue.v8Value();
+ ScriptValue reader;
v8::Isolate* isolate = scriptState->isolate();
ExecutionContext* executionContext = scriptState->executionContext();
@@ -135,6 +138,14 @@ Response* Response::create(ScriptState* scriptState, ScriptValue bodyValue, cons
bodyHandle = FetchFormDataConsumerHandle::create(executionContext, formData.release());
} else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnabled() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) {
bodyHandle = ReadableStreamDataConsumerHandle::create(scriptState, bodyValue);
+ reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState);
+ if (exceptionState.hadException()) {
+ reader = ScriptValue();
+ bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorDataConsumerHandle());
+ exceptionState.clearException();
+ } else {
+ bodyHandle = ReadableStreamDataConsumerHandle::create(scriptState, reader);
+ }
} else {
String string = toUSVString(isolate, body, exceptionState);
if (exceptionState.hadException())
@@ -143,7 +154,20 @@ Response* Response::create(ScriptState* scriptState, ScriptValue bodyValue, cons
contentType = "text/plain;charset=UTF-8";
}
// TODO(yhirano): Add the URLSearchParams case.
- return create(executionContext, bodyHandle.release(), contentType, ResponseInit(init, exceptionState), exceptionState);
+ Response* response = create(executionContext, bodyHandle.release(), contentType, ResponseInit(init, exceptionState), exceptionState);
+ if (!exceptionState.hadException() && !reader.isEmpty()) {
+ // Add a hidden reference so that the weak persistent in the
+ // ReadableStreamDataConsumerHandle will be valid as long as the
+ // Response is valid.
+ v8::Local<v8::Value> wrapper = toV8(response, scriptState);
+ if (wrapper.IsEmpty()) {
+ exceptionState.throwTypeError("Cannot create a Response wrapper");
+ return nullptr;
+ }
+ ASSERT(wrapper->IsObject());
+ V8HiddenValue::setHiddenValue(scriptState, wrapper.As<v8::Object>(), V8HiddenValue::readableStreamReaderInResponse(scriptState->isolate()), reader.v8Value());
+ }
+ return response;
}
Response* Response::create(ExecutionContext* context, PassOwnPtr<FetchDataConsumerHandle> bodyHandle, const String& contentType, const ResponseInit& init, ExceptionState& exceptionState)
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/ReadableStreamDataConsumerHandleTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698