OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/streams/UnderlyingSourceBase.h" |
| 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "core/streams/ReadableStreamController.h" |
| 11 #include <v8.h> |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 ScriptPromise UnderlyingSourceBase::startWrapper(ScriptState* scriptState, Scrip
tValue stream) |
| 16 { |
| 17 // Cannot call start twice (e.g., cannot use the same UnderlyingSourceBase t
o construct multiple streams) |
| 18 ASSERT(!m_controller); |
| 19 |
| 20 // In ReadableStream.js, we special-case externally-controlled streams by ha
ving them pass themselves to start |
| 21 // as the first argument. This allows us to create a ReadableStreamControlle
r. |
| 22 |
| 23 m_controller = new ReadableStreamController(stream); |
| 24 |
| 25 return start(scriptState); |
| 26 } |
| 27 |
| 28 ScriptPromise UnderlyingSourceBase::start(ScriptState* scriptState) |
| 29 { |
| 30 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()
)); |
| 31 } |
| 32 |
| 33 ScriptPromise UnderlyingSourceBase::pull(ScriptState* scriptState) |
| 34 { |
| 35 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()
)); |
| 36 } |
| 37 |
| 38 ScriptPromise UnderlyingSourceBase::cancelWrapper(ScriptState* scriptState, Scri
ptValue reason) |
| 39 { |
| 40 m_controller->noteHasBeenCanceled(); |
| 41 return cancel(scriptState, reason); |
| 42 } |
| 43 |
| 44 ScriptPromise UnderlyingSourceBase::cancel(ScriptState* scriptState, ScriptValue
reason) |
| 45 { |
| 46 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()
)); |
| 47 } |
| 48 |
| 49 bool UnderlyingSourceBase::hasPendingActivity() const |
| 50 { |
| 51 // This will return false within a finite time period _assuming_ that |
| 52 // consumers use the controller to close or error the stream. |
| 53 // Browser-created readable streams should always close or error within a |
| 54 // finite time period, due to timeouts etc. |
| 55 return m_controller && m_controller->isActive(); |
| 56 } |
| 57 |
| 58 void UnderlyingSourceBase::stop() |
| 59 { |
| 60 m_controller->noteHasBeenCanceled(); |
| 61 m_controller.clear(); |
| 62 } |
| 63 |
| 64 DEFINE_TRACE(UnderlyingSourceBase) |
| 65 { |
| 66 ActiveDOMObject::trace(visitor); |
| 67 visitor->trace(m_controller); |
| 68 } |
| 69 |
| 70 } // namespace blink |
OLD | NEW |