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

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

Issue 2006803006: [Fetch API] Do not call v8 Extra script when the worker is terminating (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 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())));

Powered by Google App Engine
This is Rietveld 408576698