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

Side by Side Diff: third_party/WebKit/Source/core/streams/ReadableStreamController.h

Issue 2312413003: Remove isTerminating checks from fetch API + streams code (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef ReadableStreamController_h 5 #ifndef ReadableStreamController_h
6 #define ReadableStreamController_h 6 #define ReadableStreamController_h
7 7
8 #include "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "bindings/core/v8/ToV8.h" 10 #include "bindings/core/v8/ToV8.h"
11 #include "bindings/core/v8/V8ScriptRunner.h" 11 #include "bindings/core/v8/V8ScriptRunner.h"
12 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
13 #include "core/CoreExport.h" 12 #include "core/CoreExport.h"
14 #include "core/workers/WorkerGlobalScope.h"
15 #include "platform/heap/Handle.h" 13 #include "platform/heap/Handle.h"
16 #include "wtf/RefPtr.h" 14 #include "wtf/RefPtr.h"
17 #include <v8.h> 15 #include <v8.h>
18 16
19 namespace blink { 17 namespace blink {
20 18
21 // TODO(tyoshino): Rename this to ReadableStreamDefaultControllerWrapper. 19 // TODO(tyoshino): Rename this to ReadableStreamDefaultControllerWrapper.
22 class CORE_EXPORT ReadableStreamController final : public GarbageCollectedFinali zed<ReadableStreamController> { 20 class CORE_EXPORT ReadableStreamController final : public GarbageCollectedFinali zed<ReadableStreamController> {
23 public: 21 public:
24 DEFINE_INLINE_TRACE() {} 22 DEFINE_INLINE_TRACE() {}
(...skipping 13 matching lines...) Expand all
38 m_jsController.clear(); 36 m_jsController.clear();
39 } 37 }
40 38
41 bool isActive() const 39 bool isActive() const
42 { 40 {
43 return !m_jsController.isEmpty(); 41 return !m_jsController.isEmpty();
44 } 42 }
45 43
46 void close() 44 void close()
47 { 45 {
48 if (isTerminating(m_scriptState.get())) {
49 m_jsController.clear();
50 return;
51 }
52 ScriptState* scriptState = m_scriptState.get(); 46 ScriptState* scriptState = m_scriptState.get();
53 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated 47 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
54 v8::Isolate* isolate = scriptState->isolate(); 48 v8::Isolate* isolate = scriptState->isolate();
55 49
56 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate); 50 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate);
57 if (controller.IsEmpty()) 51 if (controller.IsEmpty())
58 return; 52 return;
59 53
60 v8::Local<v8::Value> args[] = { controller }; 54 v8::Local<v8::Value> args[] = { controller };
61 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerClose", args); 55 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerClose", args);
62 m_jsController.clear(); 56 m_jsController.clear();
63 if (isTerminating(m_scriptState.get()))
64 return;
65 result.ToLocalChecked(); 57 result.ToLocalChecked();
66 } 58 }
67 59
68 double desiredSize() const 60 double desiredSize() const
69 { 61 {
70 if (isTerminating(m_scriptState.get()))
71 return 0;
72 ScriptState* scriptState = m_scriptState.get(); 62 ScriptState* scriptState = m_scriptState.get();
73 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated 63 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
74 v8::Isolate* isolate = scriptState->isolate(); 64 v8::Isolate* isolate = scriptState->isolate();
75 65
76 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate); 66 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate);
77 if (controller.IsEmpty()) 67 if (controller.IsEmpty())
78 return 0; 68 return 0;
79 69
80 v8::Local<v8::Value> args[] = { controller }; 70 v8::Local<v8::Value> args[] = { controller };
81 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerGetDesiredSize", args); 71 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerGetDesiredSize", args);
82 if (isTerminating(m_scriptState.get()))
83 return 0;
84 72
85 return result.ToLocalChecked().As<v8::Number>()->Value(); 73 return result.ToLocalChecked().As<v8::Number>()->Value();
86 } 74 }
87 75
88 template <typename ChunkType> 76 template <typename ChunkType>
89 void enqueue(ChunkType chunk) const 77 void enqueue(ChunkType chunk) const
90 { 78 {
91 if (isTerminating(m_scriptState.get()))
92 return;
93 ScriptState* scriptState = m_scriptState.get(); 79 ScriptState* scriptState = m_scriptState.get();
94 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated 80 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
95 v8::Isolate* isolate = scriptState->isolate(); 81 v8::Isolate* isolate = scriptState->isolate();
96 82
97 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate); 83 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate);
98 if (controller.IsEmpty()) 84 if (controller.IsEmpty())
99 return; 85 return;
100 86
101 v8::Local<v8::Value> jsChunk = toV8(chunk, scriptState); 87 v8::Local<v8::Value> jsChunk = toV8(chunk, scriptState);
102 v8::Local<v8::Value> args[] = { controller, jsChunk }; 88 v8::Local<v8::Value> args[] = { controller, jsChunk };
103 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerEnqueue", args); 89 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerEnqueue", args);
104 if (isTerminating(m_scriptState.get()))
105 return;
106 result.ToLocalChecked(); 90 result.ToLocalChecked();
107 } 91 }
108 92
109 template <typename ErrorType> 93 template <typename ErrorType>
110 void error(ErrorType error) 94 void error(ErrorType error)
111 { 95 {
112 if (isTerminating(m_scriptState.get())) {
113 m_jsController.clear();
114 return;
115 }
116 ScriptState* scriptState = m_scriptState.get(); 96 ScriptState* scriptState = m_scriptState.get();
117 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated 97 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated
118 v8::Isolate* isolate = scriptState->isolate(); 98 v8::Isolate* isolate = scriptState->isolate();
119 99
120 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate); 100 v8::Local<v8::Value> controller = m_jsController.newLocal(isolate);
121 if (controller.IsEmpty()) 101 if (controller.IsEmpty())
122 return; 102 return;
123 103
124 v8::Local<v8::Value> jsError = toV8(error, scriptState); 104 v8::Local<v8::Value> jsError = toV8(error, scriptState);
125 v8::Local<v8::Value> args[] = { controller, jsError }; 105 v8::Local<v8::Value> args[] = { controller, jsError };
126 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerError", args); 106 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(scriptState , "ReadableStreamDefaultControllerError", args);
127 m_jsController.clear(); 107 m_jsController.clear();
128 if (isTerminating(m_scriptState.get()))
129 return;
130 result.ToLocalChecked(); 108 result.ToLocalChecked();
131 } 109 }
132 110
133 private: 111 private:
134 static bool isTerminating(ScriptState* scriptState)
135 {
136 ExecutionContext* executionContext = scriptState->getExecutionContext();
137 if (!executionContext)
138 return true;
139 if (!executionContext->isWorkerGlobalScope())
140 return false;
141 return toWorkerGlobalScope(executionContext)->scriptController()->isExec utionTerminating();
142 }
143
144 RefPtr<ScriptState> m_scriptState; 112 RefPtr<ScriptState> m_scriptState;
145 ScopedPersistent<v8::Value> m_jsController; 113 ScopedPersistent<v8::Value> m_jsController;
146 }; 114 };
147 115
148 } // namespace blink 116 } // namespace blink
149 117
150 #endif // ReadableStreamController_h 118 #endif // ReadableStreamController_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698