| Index: Source/core/streams/ReadableStreamController.h
|
| diff --git a/Source/core/streams/ReadableStreamController.h b/Source/core/streams/ReadableStreamController.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0720edf37dbf6cce92329a4ba751be1072c06958
|
| --- /dev/null
|
| +++ b/Source/core/streams/ReadableStreamController.h
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef ReadableStreamController_h
|
| +#define ReadableStreamController_h
|
| +
|
| +#include "bindings/core/v8/ScriptValue.h"
|
| +#include "bindings/core/v8/ToV8.h"
|
| +#include "core/CoreExport.h"
|
| +#include <v8.h>
|
| +
|
| +namespace blink {
|
| +
|
| +class CORE_EXPORT ReadableStreamController {
|
| +public:
|
| + explicit ReadableStreamController(ScriptValue stream) : m_stream(stream)
|
| + {
|
| + }
|
| +
|
| + void close()
|
| + {
|
| + if (m_stream.isEmpty())
|
| + return;
|
| +
|
| + ScriptState::Scope scope(m_stream.scriptState());
|
| +
|
| + auto func = m_stream.scriptState()->getFromExtrasExports("CloseReadableStream").v8Value().As<v8::Function>();
|
| +
|
| + auto undefined = v8::Undefined(m_stream.isolate());
|
| + v8::Local<v8::Value> args[] = { m_stream.v8Value() };
|
| + auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
|
| +
|
| + ASSERT(!result.IsEmpty());
|
| + m_stream.clear();
|
| + }
|
| +
|
| + double desiredSize() const
|
| + {
|
| + if (m_stream.isEmpty())
|
| + return 0;
|
| +
|
| + ScriptState::Scope scope(m_stream.scriptState());
|
| +
|
| + auto func = m_stream.scriptState()->getFromExtrasExports("GetReadableStreamDesiredSize").v8Value()
|
| + .As<v8::Function>();
|
| +
|
| + auto undefined = v8::Undefined(m_stream.isolate());
|
| + v8::Local<v8::Value> args[] = { m_stream.v8Value() };
|
| + auto result = func->Call(m_stream.context(), undefined, arraysize(args), args).ToLocalChecked();
|
| +
|
| + return result.As<v8::Number>()->Value();
|
| + }
|
| +
|
| + template<typename ChunkType>
|
| + void enqueue(ChunkType chunk) const
|
| + {
|
| + if (m_stream.isEmpty())
|
| + return;
|
| +
|
| + ScriptState::Scope scope(m_stream.scriptState());
|
| +
|
| + auto func = m_stream.scriptState()->getFromExtrasExports("EnqueueInReadableStream").v8Value()
|
| + .As<v8::Function>();
|
| +
|
| + auto chunkForV8 = toV8(chunk, m_stream.context()->Global(), m_stream.isolate());
|
| + auto undefined = v8::Undefined(m_stream.isolate());
|
| + v8::Local<v8::Value> args[] = { m_stream.v8Value(), chunkForV8 };
|
| +
|
| + auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
|
| +
|
| + ASSERT(!result.IsEmpty());
|
| + }
|
| +
|
| + template<typename ErrorType>
|
| + void error(ErrorType e)
|
| + {
|
| + if (m_stream.isEmpty())
|
| + return;
|
| +
|
| + ScriptState::Scope scope(m_stream.scriptState());
|
| +
|
| + auto func = m_stream.scriptState()->getFromExtrasExports("ErrorReadableStream").v8Value().As<v8::Function>();
|
| +
|
| + auto errorForV8 = toV8(e, m_stream.context()->Global(), m_stream.isolate());
|
| + auto undefined = v8::Undefined(m_stream.isolate());
|
| + v8::Local<v8::Value> args[] = { m_stream.v8Value(), errorForV8 };
|
| + auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
|
| +
|
| + ASSERT(!result.IsEmpty());
|
| + m_stream.clear();
|
| + }
|
| +
|
| +private:
|
| + ScriptValue m_stream;
|
| +};
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif // ReadableStreamController_h
|
|
|