Chromium Code Reviews| 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" |
| 11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/dom/ExecutionContext.h" | 14 #include "core/dom/ExecutionContext.h" |
| 15 #include "core/streams/ExclusiveStreamReader.h" | 15 #include "core/streams/ReadableStreamReader.h" |
| 16 #include "core/streams/UnderlyingSource.h" | 16 #include "core/streams/UnderlyingSource.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class ConstUndefined : public ScriptFunction { | 22 class ConstUndefined : public ScriptFunction { |
| 23 public: | 23 public: |
| 24 static v8::Handle<v8::Function> create(ScriptState* scriptState) | 24 static v8::Handle<v8::Function> create(ScriptState* scriptState) |
| 25 { | 25 { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 m_ready->reset(); | 164 m_ready->reset(); |
| 165 m_state = Waiting; | 165 m_state = Waiting; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 callPullIfNeeded(); | 168 callPullIfNeeded(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 ScriptValue ReadableStream::read(ScriptState* scriptState, ExceptionState& excep tionState) | 171 ScriptValue ReadableStream::read(ScriptState* scriptState, ExceptionState& excep tionState) |
| 172 { | 172 { |
| 173 if (m_reader) { | 173 if (m_reader) { |
| 174 exceptionState.throwTypeError("this stream is locked to an ExclusiveStre amReader"); | 174 exceptionState.throwTypeError("this stream is locked to an ReadableStrea mReader"); |
|
tyoshino (SeeGerritForStatus)
2015/03/17 05:14:39
an -> a
yhirano
2015/03/17 05:24:16
Done.
| |
| 175 return ScriptValue(); | 175 return ScriptValue(); |
| 176 } | 176 } |
| 177 return readInternal(scriptState, exceptionState); | 177 return readInternal(scriptState, exceptionState); |
| 178 } | 178 } |
| 179 | 179 |
| 180 ScriptPromise ReadableStream::ready(ScriptState* scriptState) | 180 ScriptPromise ReadableStream::ready(ScriptState* scriptState) |
| 181 { | 181 { |
| 182 if (m_reader) { | 182 if (m_reader) { |
| 183 return m_reader->released(scriptState).then(ResolveWithReady::create(scr iptState, this)); | 183 return m_reader->released(scriptState).then(ResolveWithReady::create(scr iptState, this)); |
| 184 } | 184 } |
| 185 | 185 |
| 186 if (m_state == Waiting) { | 186 if (m_state == Waiting) { |
| 187 return readyInternal(scriptState).then(ResolveWithReady::create(scriptSt ate, this)); | 187 return readyInternal(scriptState).then(ResolveWithReady::create(scriptSt ate, this)); |
| 188 } | 188 } |
| 189 return readyInternal(scriptState); | 189 return readyInternal(scriptState); |
| 190 } | 190 } |
| 191 | 191 |
| 192 ScriptPromise ReadableStream::readyInternal(ScriptState* scriptState) | 192 ScriptPromise ReadableStream::readyInternal(ScriptState* scriptState) |
| 193 { | 193 { |
| 194 return m_ready->promise(scriptState->world()); | 194 return m_ready->promise(scriptState->world()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 ScriptPromise ReadableStream::cancel(ScriptState* scriptState, ScriptValue reaso n) | 197 ScriptPromise ReadableStream::cancel(ScriptState* scriptState, ScriptValue reaso n) |
| 198 { | 198 { |
| 199 if (m_reader) | 199 if (m_reader) |
| 200 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "this stream is locked to an ExclusiveStreamReader") ); | 200 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "this stream is locked to an ReadableStreamReader")) ; |
|
tyoshino (SeeGerritForStatus)
2015/03/17 05:14:40
an -> a
yhirano
2015/03/17 05:24:16
Done.
| |
| 201 if (m_state == Closed) | 201 if (m_state == Closed) |
| 202 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te())); | 202 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te())); |
| 203 if (m_state == Errored) | 203 if (m_state == Errored) |
| 204 return ScriptPromise::rejectWithDOMException(scriptState, m_exception); | 204 return ScriptPromise::rejectWithDOMException(scriptState, m_exception); |
| 205 | 205 |
| 206 ASSERT(m_state == Readable || m_state == Waiting); | 206 ASSERT(m_state == Readable || m_state == Waiting); |
| 207 if (m_state == Waiting) | 207 if (m_state == Waiting) |
| 208 m_ready->resolve(ToV8UndefinedGenerator()); | 208 m_ready->resolve(ToV8UndefinedGenerator()); |
| 209 clearQueue(); | 209 clearQueue(); |
| 210 m_closed->resolve(ToV8UndefinedGenerator()); | 210 m_closed->resolve(ToV8UndefinedGenerator()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 break; | 242 break; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 void ReadableStream::didSourceStart() | 246 void ReadableStream::didSourceStart() |
| 247 { | 247 { |
| 248 m_isStarted = true; | 248 m_isStarted = true; |
| 249 callPullIfNeeded(); | 249 callPullIfNeeded(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 ExclusiveStreamReader* ReadableStream::getReader(ExceptionState& exceptionState) | 252 ReadableStreamReader* ReadableStream::getReader(ExceptionState& exceptionState) |
| 253 { | 253 { |
| 254 if (m_state == Closed) { | 254 if (m_state == Closed) { |
| 255 exceptionState.throwTypeError("this stream is already closed"); | 255 exceptionState.throwTypeError("this stream is already closed"); |
| 256 return nullptr; | 256 return nullptr; |
| 257 } | 257 } |
| 258 if (m_state == Errored) { | 258 if (m_state == Errored) { |
| 259 exceptionState.throwDOMException(m_exception->code(), m_exception->messa ge()); | 259 exceptionState.throwDOMException(m_exception->code(), m_exception->messa ge()); |
| 260 return nullptr; | 260 return nullptr; |
| 261 } | 261 } |
| 262 if (m_reader) { | 262 if (m_reader) { |
| 263 exceptionState.throwTypeError("already locked to an ExclusiveStreamReade r"); | 263 exceptionState.throwTypeError("already locked to an ReadableStreamReader "); |
|
tyoshino (SeeGerritForStatus)
2015/03/17 05:14:39
an -> a
yhirano
2015/03/17 05:24:16
Done.
| |
| 264 return nullptr; | 264 return nullptr; |
| 265 } | 265 } |
| 266 return new ExclusiveStreamReader(this); | 266 return new ReadableStreamReader(this); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void ReadableStream::setReader(ExclusiveStreamReader* reader) | 269 void ReadableStream::setReader(ReadableStreamReader* reader) |
| 270 { | 270 { |
| 271 ASSERT((reader && !m_reader) || (!reader && m_reader)); | 271 ASSERT((reader && !m_reader) || (!reader && m_reader)); |
| 272 m_reader = reader; | 272 m_reader = reader; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void ReadableStream::callPullIfNeeded() | 275 void ReadableStream::callPullIfNeeded() |
| 276 { | 276 { |
| 277 if (m_isPulling || m_isDraining || !m_isStarted || m_state == Closed || m_st ate == Errored) | 277 if (m_isPulling || m_isDraining || !m_isStarted || m_state == Closed || m_st ate == Errored) |
| 278 return; | 278 return; |
| 279 | 279 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 case Closed: | 316 case Closed: |
| 317 return "closed"; | 317 return "closed"; |
| 318 case Errored: | 318 case Errored: |
| 319 return "errored"; | 319 return "errored"; |
| 320 } | 320 } |
| 321 ASSERT(false); | 321 ASSERT(false); |
| 322 return String(); | 322 return String(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace blink | 325 } // namespace blink |
| OLD | NEW |