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

Unified Diff: third_party/WebKit/Source/core/streams/ReadableStreamController.h

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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/streams/ReadableStreamOperations.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/streams/ReadableStreamController.h
diff --git a/third_party/WebKit/Source/core/streams/ReadableStreamController.h b/third_party/WebKit/Source/core/streams/ReadableStreamController.h
index 647f6c300b26b2b25f2f73e666b183ba559fca9b..21edc0cefabfd9e74f7af09051734743ac4d7822 100644
--- a/third_party/WebKit/Source/core/streams/ReadableStreamController.h
+++ b/third_party/WebKit/Source/core/streams/ReadableStreamController.h
@@ -9,7 +9,9 @@
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8ScriptRunner.h"
+#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "core/CoreExport.h"
+#include "core/workers/WorkerGlobalScope.h"
#include "platform/heap/Handle.h"
#include "wtf/RefPtr.h"
#include <v8.h>
@@ -43,6 +45,10 @@ public:
void close()
{
+ if (isTerminating(m_scriptState.get())) {
+ m_jsController.clear();
+ return;
+ }
ScriptState* scriptState = m_scriptState.get();
ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
v8::Isolate* isolate = scriptState->isolate();
@@ -52,13 +58,17 @@ public:
return;
v8::Local<v8::Value> args[] = { controller };
- V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultControllerClose", args);
-
+ v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState, "ReadableStreamDefaultControllerClose", args);
m_jsController.clear();
+ if (isTerminating(m_scriptState.get()))
+ return;
+ v8CallOrCrash(result);
}
double desiredSize() const
{
+ if (isTerminating(m_scriptState.get()))
+ return 0;
ScriptState* scriptState = m_scriptState.get();
ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
v8::Isolate* isolate = scriptState->isolate();
@@ -68,14 +78,18 @@ public:
return 0;
v8::Local<v8::Value> args[] = { controller };
- v8::Local<v8::Value> result = V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultControllerGetDesiredSize", args);
+ v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState, "ReadableStreamDefaultControllerGetDesiredSize", args);
+ if (isTerminating(m_scriptState.get()))
+ return 0;
- return result.As<v8::Number>()->Value();
+ return v8CallOrCrash(result).As<v8::Number>()->Value();
}
template <typename ChunkType>
void enqueue(ChunkType chunk) const
{
+ if (isTerminating(m_scriptState.get()))
+ return;
ScriptState* scriptState = m_scriptState.get();
ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
v8::Isolate* isolate = scriptState->isolate();
@@ -86,12 +100,19 @@ public:
v8::Local<v8::Value> jsChunk = toV8(chunk, scriptState);
v8::Local<v8::Value> args[] = { controller, jsChunk };
- V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultControllerEnqueue", args);
+ v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState, "ReadableStreamDefaultControllerEnqueue", args);
+ if (isTerminating(m_scriptState.get()))
+ return;
+ v8CallOrCrash(result);
}
template <typename ErrorType>
void error(ErrorType error)
{
+ if (isTerminating(m_scriptState.get())) {
+ m_jsController.clear();
+ return;
+ }
ScriptState* scriptState = m_scriptState.get();
ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
v8::Isolate* isolate = scriptState->isolate();
@@ -102,9 +123,11 @@ public:
v8::Local<v8::Value> jsError = toV8(error, scriptState);
v8::Local<v8::Value> args[] = { controller, jsError };
- V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultControllerError", args);
-
+ v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState, "ReadableStreamDefaultControllerError", args);
m_jsController.clear();
+ if (isTerminating(m_scriptState.get()))
+ return;
+ v8CallOrCrash(result);
}
private:
@@ -113,6 +136,16 @@ private:
weakInfo.GetParameter()->clear();
}
+ static bool isTerminating(ScriptState* scriptState)
+ {
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ if (!executionContext)
+ return true;
+ if (!executionContext->isWorkerGlobalScope())
+ return false;
+ return toWorkerGlobalScope(executionContext)->scriptController()->isExecutionTerminating();
+ }
+
RefPtr<ScriptState> m_scriptState;
ScopedPersistent<v8::Value> m_jsController;
};
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/streams/ReadableStreamOperations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698