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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp

Issue 2265863002: Streams: Remove isTerminating() calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove empty checks Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/fetch/BodyStreamBuffer.h" 5 #include "modules/fetch/BodyStreamBuffer.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8HiddenValue.h" 8 #include "bindings/core/v8/V8HiddenValue.h"
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/dom/DOMArrayBuffer.h" 9 #include "core/dom/DOMArrayBuffer.h"
11 #include "core/dom/DOMTypedArray.h" 10 #include "core/dom/DOMTypedArray.h"
12 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
13 #include "core/streams/ReadableStreamController.h" 12 #include "core/streams/ReadableStreamController.h"
14 #include "core/streams/ReadableStreamOperations.h" 13 #include "core/streams/ReadableStreamOperations.h"
15 #include "core/workers/WorkerGlobalScope.h"
16 #include "modules/fetch/Body.h" 14 #include "modules/fetch/Body.h"
17 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" 15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
18 #include "modules/fetch/DataConsumerHandleUtil.h" 16 #include "modules/fetch/DataConsumerHandleUtil.h"
19 #include "modules/fetch/DataConsumerTee.h" 17 #include "modules/fetch/DataConsumerTee.h"
20 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" 18 #include "modules/fetch/ReadableStreamDataConsumerHandle.h"
21 #include "platform/blob/BlobData.h" 19 #include "platform/blob/BlobData.h"
22 #include "platform/network/EncodedFormData.h" 20 #include "platform/network/EncodedFormData.h"
23 #include <memory> 21 #include <memory>
24 22
25 namespace blink { 23 namespace blink {
26 24
27 namespace {
28
29 bool isTerminating(ScriptState* scriptState)
30 {
31 ExecutionContext* executionContext = scriptState->getExecutionContext();
32 if (!executionContext)
33 return true;
34 if (!executionContext->isWorkerGlobalScope())
35 return false;
36 return toWorkerGlobalScope(executionContext)->scriptController()->isExecutio nTerminating();
37 }
38
39 } // namespace
40
41 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { 25 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo aderClient>, public ActiveDOMObject, public FetchDataLoader::Client {
42 WTF_MAKE_NONCOPYABLE(LoaderClient); 26 WTF_MAKE_NONCOPYABLE(LoaderClient);
43 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); 27 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient);
44 public: 28 public:
45 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F etchDataLoader::Client* client) 29 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F etchDataLoader::Client* client)
46 : ActiveDOMObject(executionContext) 30 : ActiveDOMObject(executionContext)
47 , m_buffer(buffer) 31 , m_buffer(buffer)
48 , m_client(client) 32 , m_client(client)
49 { 33 {
50 suspendIfNeeded(); 34 suspendIfNeeded();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Member<FetchDataLoader::Client> m_client; 82 Member<FetchDataLoader::Client> m_client;
99 }; 83 };
100 84
101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, std::unique_ptr<Fet chDataConsumerHandle> handle) 85 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, std::unique_ptr<Fet chDataConsumerHandle> handle)
102 : UnderlyingSourceBase(scriptState) 86 : UnderlyingSourceBase(scriptState)
103 , m_scriptState(scriptState) 87 , m_scriptState(scriptState)
104 , m_handle(std::move(handle)) 88 , m_handle(std::move(handle))
105 , m_reader(m_handle->obtainFetchDataReader(this)) 89 , m_reader(m_handle->obtainFetchDataReader(this))
106 , m_madeFromReadableStream(false) 90 , m_madeFromReadableStream(false)
107 { 91 {
108 if (isTerminating(scriptState)) {
109 m_reader = nullptr;
110 m_handle = nullptr;
111 return;
112 }
113 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); 92 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
114 if (bodyValue.IsEmpty()) {
115 DCHECK(isTerminating(scriptState));
116 m_reader = nullptr;
117 m_handle = nullptr;
118 return;
119 }
120 DCHECK(bodyValue->IsObject()); 93 DCHECK(bodyValue->IsObject());
121 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); 94 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
122 95
123 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( 96 ScriptValue readableStream = ReadableStreamOperations::createReadableStream(
124 scriptState, this, ReadableStreamOperations::createCountQueuingStrategy( scriptState, 0)); 97 scriptState, this, ReadableStreamOperations::createCountQueuingStrategy( scriptState, 0));
125 if (isTerminating(scriptState)) {
126 m_reader = nullptr;
127 m_handle = nullptr;
128 return;
129 }
130 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), readableStream.v8Value()); 98 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), readableStream.v8Value());
131 } 99 }
132 100
133 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) 101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream)
134 : UnderlyingSourceBase(scriptState) 102 : UnderlyingSourceBase(scriptState)
135 , m_scriptState(scriptState) 103 , m_scriptState(scriptState)
136 , m_madeFromReadableStream(true) 104 , m_madeFromReadableStream(true)
137 { 105 {
138 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); 106 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream));
139 if (isTerminating(scriptState))
140 return;
141 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); 107 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
142 if (bodyValue.IsEmpty()) {
143 DCHECK(isTerminating(scriptState));
144 return;
145 }
146 DCHECK(bodyValue->IsObject()); 108 DCHECK(bodyValue->IsObject());
147 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); 109 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
148 110
149 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), stream.v8Value()); 111 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), stream.v8Value());
150 } 112 }
151 113
152 ScriptValue BodyStreamBuffer::stream() 114 ScriptValue BodyStreamBuffer::stream()
153 { 115 {
154 ScriptState::Scope scope(m_scriptState.get()); 116 ScriptState::Scope scope(m_scriptState.get());
155 if (isTerminating(m_scriptState.get()))
156 return ScriptValue();
157 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); 117 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get());
158 if (bodyValue.IsEmpty()) {
159 DCHECK(isTerminating(m_scriptState.get()));
160 return ScriptValue();
161 }
162 DCHECK(bodyValue->IsObject()); 118 DCHECK(bodyValue->IsObject());
163 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); 119 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
164 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_scri ptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolate()) )); 120 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_scri ptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolate()) ));
165 } 121 }
166 122
167 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons umerHandle::Reader::BlobSizePolicy policy) 123 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons umerHandle::Reader::BlobSizePolicy policy)
168 { 124 {
169 ASSERT(!isStreamLocked()); 125 ASSERT(!isStreamLocked());
170 ASSERT(!isStreamDisturbed()); 126 ASSERT(!isStreamDisturbed());
171 if (isStreamClosed() || isStreamErrored()) 127 if (isStreamClosed() || isStreamErrored())
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle()); 376 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle());
421 } 377 }
422 if (isErrored) 378 if (isErrored)
423 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle()); 379 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle());
424 380
425 DCHECK(handle); 381 DCHECK(handle);
426 return handle; 382 return handle;
427 } 383 }
428 384
429 } // namespace blink 385 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698