| 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 #ifndef ReadableStreamImpl_h | 5 #ifndef ReadableStreamImpl_h |
| 6 #define ReadableStreamImpl_h | 6 #define ReadableStreamImpl_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 return ScriptValue(scriptState, v8String(scriptState->isolate(), value))
; | 35 return ScriptValue(scriptState, v8String(scriptState->isolate(), value))
; |
| 36 } | 36 } |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 template<> | 39 template<> |
| 40 class ReadableStreamChunkTypeTraits<ArrayBuffer> { | 40 class ReadableStreamChunkTypeTraits<ArrayBuffer> { |
| 41 public: | 41 public: |
| 42 typedef RefPtr<ArrayBuffer> HoldType; | 42 typedef RefPtr<ArrayBuffer> HoldType; |
| 43 typedef PassRefPtr<ArrayBuffer> PassType; | 43 typedef PassRefPtr<ArrayBuffer> PassType; |
| 44 | 44 |
| 45 static size_t size(PassType value) { return value->byteLength(); } | 45 static size_t size(const PassType& value) { return value->byteLength(); } |
| 46 static size_t size(const HoldType& value) { return value->byteLength(); } | 46 static size_t size(const HoldType& value) { return value->byteLength(); } |
| 47 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) | 47 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) |
| 48 { | 48 { |
| 49 return ScriptValue(scriptState, toV8NoInline(value.get(), scriptState->c
ontext()->Global(), scriptState->isolate())); | 49 return ScriptValue(scriptState, toV8NoInline(value.get(), scriptState->c
ontext()->Global(), scriptState->isolate())); |
| 50 } | 50 } |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // ReadableStreamImpl<ChunkTypeTraits> is a ReadableStream subtype. It has a | 53 // ReadableStreamImpl<ChunkTypeTraits> is a ReadableStream subtype. It has a |
| 54 // queue whose type depends on ChunkTypeTraits and it implements queue-related | 54 // queue whose type depends on ChunkTypeTraits and it implements queue-related |
| 55 // ReadableStream pure virtual methods. | 55 // ReadableStream pure virtual methods. |
| 56 template <typename ChunkTypeTraits> | 56 template <typename ChunkTypeTraits> |
| 57 class ReadableStreamImpl : public ReadableStream { | 57 class ReadableStreamImpl : public ReadableStream { |
| 58 public: | 58 public: |
| 59 ReadableStreamImpl(ScriptState* scriptState, UnderlyingSource* source, Excep
tionState* exceptionState) | 59 ReadableStreamImpl(ExecutionContext* executionContext, UnderlyingSource* sou
rce) |
| 60 : ReadableStream(scriptState, source, exceptionState) | 60 : ReadableStream(executionContext, source) |
| 61 , m_totalQueueSize(0) { } | 61 , m_totalQueueSize(0) { } |
| 62 virtual ~ReadableStreamImpl() { } | 62 virtual ~ReadableStreamImpl() { } |
| 63 | 63 |
| 64 // ReadableStream methods | 64 // ReadableStream methods |
| 65 virtual ScriptValue read(ScriptState*, ExceptionState*) OVERRIDE; | 65 virtual ScriptValue read(ScriptState*, ExceptionState&) OVERRIDE; |
| 66 | 66 |
| 67 bool enqueue(typename ChunkTypeTraits::PassType); | 67 bool enqueue(typename ChunkTypeTraits::PassType); |
| 68 | 68 |
| 69 virtual void trace(Visitor* visitor) OVERRIDE | 69 virtual void trace(Visitor* visitor) OVERRIDE |
| 70 { | 70 { |
| 71 ReadableStream::trace(visitor); | 71 ReadableStream::trace(visitor); |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 // ReadableStream methods | 75 // ReadableStream methods |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 { | 89 { |
| 90 size_t size = ChunkTypeTraits::size(chunk); | 90 size_t size = ChunkTypeTraits::size(chunk); |
| 91 if (!enqueuePreliminaryCheck(size)) | 91 if (!enqueuePreliminaryCheck(size)) |
| 92 return false; | 92 return false; |
| 93 m_queue.append(chunk); | 93 m_queue.append(chunk); |
| 94 m_totalQueueSize += size; | 94 m_totalQueueSize += size; |
| 95 return enqueuePostAction(m_totalQueueSize); | 95 return enqueuePostAction(m_totalQueueSize); |
| 96 } | 96 } |
| 97 | 97 |
| 98 template <typename ChunkTypeTraits> | 98 template <typename ChunkTypeTraits> |
| 99 ScriptValue ReadableStreamImpl<ChunkTypeTraits>::read(ScriptState* scriptState,
ExceptionState* exceptionState) | 99 ScriptValue ReadableStreamImpl<ChunkTypeTraits>::read(ScriptState* scriptState,
ExceptionState& exceptionState) |
| 100 { | 100 { |
| 101 readPreliminaryCheck(exceptionState); | 101 readPreliminaryCheck(exceptionState); |
| 102 if (exceptionState->hadException()) | 102 if (exceptionState.hadException()) |
| 103 return ScriptValue(); | 103 return ScriptValue(); |
| 104 ASSERT(state() == Readable); | 104 ASSERT(state() == Readable); |
| 105 ASSERT(!m_queue.isEmpty()); | 105 ASSERT(!m_queue.isEmpty()); |
| 106 typename ChunkTypeTraits::HoldType chunk = m_queue.takeFirst(); | 106 typename ChunkTypeTraits::HoldType chunk = m_queue.takeFirst(); |
| 107 m_totalQueueSize -= ChunkTypeTraits::size(chunk); | 107 m_totalQueueSize -= ChunkTypeTraits::size(chunk); |
| 108 readPostAction(); | 108 readPostAction(); |
| 109 return ChunkTypeTraits::toScriptValue(scriptState, chunk); | 109 return ChunkTypeTraits::toScriptValue(scriptState, chunk); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace blink | 112 } // namespace blink |
| 113 | 113 |
| 114 #endif // ReadableStreamImpl_h | 114 #endif // ReadableStreamImpl_h |
| 115 | 115 |
| OLD | NEW |