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 d402f5960793376bf611efb430c5bd3badd05979..107f4e380d098f493db1c7ca39a3260a0cb14a84 100644 |
--- a/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp |
+++ b/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp |
@@ -6,11 +6,13 @@ |
#include "bindings/core/v8/ScriptState.h" |
#include "bindings/core/v8/V8HiddenValue.h" |
+#include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
#include "core/dom/DOMArrayBuffer.h" |
#include "core/dom/DOMTypedArray.h" |
#include "core/dom/ExceptionCode.h" |
#include "core/streams/ReadableStreamController.h" |
#include "core/streams/ReadableStreamOperations.h" |
+#include "core/workers/WorkerGlobalScope.h" |
#include "modules/fetch/Body.h" |
#include "modules/fetch/DataConsumerHandleUtil.h" |
#include "modules/fetch/DataConsumerTee.h" |
@@ -21,6 +23,20 @@ |
namespace blink { |
+namespace { |
+ |
+bool isTerminating(ScriptState* scriptState) |
+{ |
+ ExecutionContext* executionContext = scriptState->getExecutionContext(); |
+ if (!executionContext) |
+ return true; |
+ if (!executionContext->isWorkerGlobalScope()) |
+ return false; |
+ return toWorkerGlobalScope(executionContext)->scriptController()->isExecutionTerminating(); |
+} |
+ |
+} // namespace |
+ |
class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<LoaderClient>, public ActiveDOMObject, public FetchDataLoader::Client { |
WTF_MAKE_NONCOPYABLE(LoaderClient); |
USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
@@ -90,8 +106,13 @@ BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat |
{ |
if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
ScriptState::Scope scope(scriptState); |
+ if (isTerminating(scriptState)) |
+ return; |
v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
- ASSERT(!bodyValue.IsEmpty()); |
+ if (bodyValue.IsEmpty()) { |
+ DCHECK(isTerminating(scriptState)); |
+ return; |
+ } |
ASSERT(bodyValue->IsObject()); |
v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
@@ -112,8 +133,13 @@ BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) |
ScriptState::Scope scope(scriptState); |
DCHECK(RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()); |
DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); |
+ if (isTerminating(scriptState)) |
+ return; |
v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
- DCHECK(!bodyValue.IsEmpty()); |
+ if (bodyValue.IsEmpty()) { |
+ DCHECK(isTerminating(scriptState)); |
+ return; |
+ } |
DCHECK(bodyValue->IsObject()); |
v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
@@ -124,8 +150,13 @@ ScriptValue BodyStreamBuffer::stream() |
{ |
ScriptState::Scope scope(m_scriptState.get()); |
if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
+ if (isTerminating(m_scriptState.get())) |
+ return ScriptValue(); |
v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); |
- ASSERT(!bodyValue.IsEmpty()); |
+ if (bodyValue.IsEmpty()) { |
+ DCHECK(isTerminating(m_scriptState.get())); |
+ return ScriptValue(); |
+ } |
ASSERT(bodyValue->IsObject()); |
v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_scriptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolate()))); |