OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "config.h" |
| 6 #include "core/streams/ScriptReadableStreamController.h" |
| 7 |
| 8 #include "bindings/core/v8/ToV8.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 // TODO probably need the asserts from the spec here |
| 13 |
| 14 // NOTE: the normal graph is ScriptReadableStreamController -> ScriptReadableStr
eam -> V8 ReadableStream object -> |
| 15 // V8 underlying source object -> ScriptUnderlyingSource -> ScriptReadableStream
-> ScriptReadableStreamController .... |
| 16 // However once you call close() or error() methods of ScriptReadableStreamContr
oller, the |
| 17 // ScriptReadableStreamController -> ScriptReadableStream link is broken by m_st
ream.clear(). |
| 18 |
| 19 ScriptReadableStreamController::ScriptReadableStreamController(ScriptValue strea
m) : m_stream(stream) |
| 20 { |
| 21 } |
| 22 |
| 23 void ScriptReadableStreamController::close() |
| 24 { |
| 25 if (m_stream.isEmpty()) |
| 26 return; |
| 27 |
| 28 ScriptState::Scope scope(m_stream.scriptState()); |
| 29 |
| 30 auto func = m_stream.scriptState()->getFromExtrasExports("CloseReadableStrea
m").v8Value().As<v8::Function>(); |
| 31 |
| 32 auto undefined = v8::Undefined(m_stream.isolate()); |
| 33 v8::Local<v8::Value> args[] = { m_stream.v8Value() }; |
| 34 auto result = func->Call(undefined, 1, args); |
| 35 |
| 36 // TODO crash if result is empty (i.e. an exception) |
| 37 |
| 38 m_stream.clear(); |
| 39 } |
| 40 |
| 41 double ScriptReadableStreamController::desiredSize() const |
| 42 { |
| 43 if (m_stream.isEmpty()) |
| 44 return 0; |
| 45 |
| 46 ScriptState::Scope scope(m_stream.scriptState()); |
| 47 |
| 48 auto func = m_stream.scriptState()->getFromExtrasExports("GetReadableStreamD
esiredSize").v8Value().As<v8::Function>(); |
| 49 |
| 50 auto undefined = v8::Undefined(m_stream.isolate()); |
| 51 v8::Local<v8::Value> args[] = { m_stream.v8Value() }; |
| 52 auto result = func->Call(undefined, 1, args); |
| 53 |
| 54 return result.As<v8::Number>()->Value(); |
| 55 } |
| 56 |
| 57 template<typename ChunkType> |
| 58 void ScriptReadableStreamController::enqueue(ChunkType chunk) const |
| 59 { |
| 60 if (m_stream.isEmpty()) |
| 61 return; |
| 62 |
| 63 ScriptState::Scope scope(m_stream.scriptState()); |
| 64 |
| 65 auto func = m_stream.scriptState()->getFromExtrasExports("EnqueueInReadableS
tream").v8Value().As<v8::Function>(); |
| 66 |
| 67 auto chunkForV8 = toV8(chunk, m_stream.context()->Global(), m_stream.isolate
()); |
| 68 auto undefined = v8::Undefined(m_stream.isolate()); |
| 69 v8::Local<v8::Value> args[] = { m_stream.v8Value(), chunkForV8 }; |
| 70 auto result = func->Call(undefined, 2, args); |
| 71 |
| 72 // TODO crash if result is empty (i.e. an exception) |
| 73 } |
| 74 |
| 75 template<typename ErrorType> |
| 76 void ScriptReadableStreamController::error(ErrorType e) |
| 77 { |
| 78 if (m_stream.isEmpty()) |
| 79 return; |
| 80 |
| 81 ScriptState::Scope scope(m_stream.scriptState()); |
| 82 |
| 83 auto func = m_stream.scriptState()->getFromExtrasExports("ErrorReadableStrea
m").v8Value().As<v8::Function>(); |
| 84 |
| 85 auto errorForV8 = toV8(e, m_stream.context()->Global(), m_stream.isolate()); |
| 86 auto undefined = v8::Undefined(m_stream.isolate()); |
| 87 v8::Local<v8::Value> args[] = { m_stream.v8Value(), errorForV8 }; |
| 88 auto result = func->Call(undefined, 2, args); |
| 89 |
| 90 // TODO crash if result is empty (i.e. an exception) |
| 91 |
| 92 m_stream.clear(); |
| 93 } |
| 94 |
| 95 } // namespace blink |
OLD | NEW |