OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 #include "core/streams/ReadableStream.h" | 6 #include "core/streams/ReadableStream.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (m_state == Closed) | 104 if (m_state == Closed) |
105 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); | 105 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); |
106 if (m_state == Errored) | 106 if (m_state == Errored) |
107 return ScriptPromise::rejectWithDOMException(scriptState, m_exception); | 107 return ScriptPromise::rejectWithDOMException(scriptState, m_exception); |
108 | 108 |
109 return cancelInternal(scriptState, reason); | 109 return cancelInternal(scriptState, reason); |
110 } | 110 } |
111 | 111 |
112 ScriptPromise ReadableStream::cancelInternal(ScriptState* scriptState, ScriptVal
ue reason) | 112 ScriptPromise ReadableStream::cancelInternal(ScriptState* scriptState, ScriptVal
ue reason) |
113 { | 113 { |
| 114 setIsDisturbed(); |
114 closeInternal(); | 115 closeInternal(); |
115 return m_source->cancelSource(scriptState, reason).then(ConstUndefined::crea
te(scriptState)); | 116 return m_source->cancelSource(scriptState, reason).then(ConstUndefined::crea
te(scriptState)); |
116 } | 117 } |
117 | 118 |
118 void ReadableStream::error(DOMException* exception) | 119 void ReadableStream::error(DOMException* exception) |
119 { | 120 { |
120 if (m_state != ReadableStream::Readable) | 121 if (m_state != ReadableStream::Readable) |
121 return; | 122 return; |
122 | 123 |
123 m_exception = exception; | 124 m_exception = exception; |
124 clearQueue(); | 125 clearQueue(); |
125 rejectAllPendingReads(m_exception); | 126 rejectAllPendingReads(m_exception); |
126 m_state = Errored; | 127 m_state = Errored; |
127 if (m_reader) | 128 if (m_reader) |
128 m_reader->releaseLock(); | 129 m_reader->error(); |
129 } | 130 } |
130 | 131 |
131 void ReadableStream::didSourceStart() | 132 void ReadableStream::didSourceStart() |
132 { | 133 { |
133 m_isStarted = true; | 134 m_isStarted = true; |
134 callPullIfNeeded(); | 135 callPullIfNeeded(); |
135 } | 136 } |
136 | 137 |
137 ReadableStreamReader* ReadableStream::getReader(ExecutionContext* executionConte
xt, ExceptionState& exceptionState) | 138 ReadableStreamReader* ReadableStream::getReader(ExecutionContext* executionConte
xt, ExceptionState& exceptionState) |
138 { | 139 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 m_source->pullSource(); | 173 m_source->pullSource(); |
173 } | 174 } |
174 | 175 |
175 void ReadableStream::closeInternal() | 176 void ReadableStream::closeInternal() |
176 { | 177 { |
177 ASSERT(m_state == Readable); | 178 ASSERT(m_state == Readable); |
178 m_state = Closed; | 179 m_state = Closed; |
179 resolveAllPendingReadsAsDone(); | 180 resolveAllPendingReadsAsDone(); |
180 clearQueue(); | 181 clearQueue(); |
181 if (m_reader) | 182 if (m_reader) |
182 m_reader->releaseLock(); | 183 m_reader->close(); |
183 } | 184 } |
184 | 185 |
185 DEFINE_TRACE(ReadableStream) | 186 DEFINE_TRACE(ReadableStream) |
186 { | 187 { |
187 visitor->trace(m_source); | 188 visitor->trace(m_source); |
188 visitor->trace(m_exception); | 189 visitor->trace(m_exception); |
189 visitor->trace(m_reader); | 190 visitor->trace(m_reader); |
190 } | 191 } |
191 | 192 |
192 } // namespace blink | 193 } // namespace blink |
OLD | NEW |