Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1784)

Unified Diff: Source/core/streams/ReadableStream.cpp

Issue 407453002: ReadableStream initial implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/streams/ReadableStream.h ('k') | Source/core/streams/ReadableStreamTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/streams/ReadableStream.cpp
diff --git a/Source/core/streams/ReadableStream.cpp b/Source/core/streams/ReadableStream.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..03762f66d2b08769f670a2d6a4f712c84c10696d
--- /dev/null
+++ b/Source/core/streams/ReadableStream.cpp
@@ -0,0 +1,84 @@
+// Copyright 2014 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.
+
+#include "config.h"
+#include "core/streams/ReadableStream.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptFunction.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "core/streams/UnderlyingSource.h"
+
+namespace blink {
+
+class ReadableStream::OnStarted : public ScriptFunction {
+public:
+ OnStarted(v8::Isolate* isolate, ReadableStream* stream)
+ : ScriptFunction(isolate)
+ , m_stream(stream) { }
+ virtual ScriptValue call(ScriptValue value) OVERRIDE
+ {
+ m_stream->onStarted();
+ return value;
+ }
+
+private:
+ Persistent<ReadableStream> m_stream;
+};
+
+class ReadableStream::OnStartFailed : public ScriptFunction {
+public:
+ OnStartFailed(v8::Isolate* isolate, ReadableStream* stream)
+ : ScriptFunction(isolate)
+ , m_stream(stream) { }
+ virtual ScriptValue call(ScriptValue value) OVERRIDE
+ {
+ m_stream->error(value);
+ return value;
+ }
+
+private:
+ Persistent<ReadableStream> m_stream;
+};
+
+ReadableStream::ReadableStream(ScriptState* scriptState, UnderlyingSource* source, ExceptionState* exceptionState)
+ : m_scriptState(scriptState)
+ , m_source(source)
+ , m_isStarted(false)
+ , m_isDraining(false)
+ , m_isPulling(false)
+ , m_state(Waiting)
+{
+ ScriptPromise promise = source->startSource(exceptionState);
+ promise.then(adoptPtr(new OnStarted(scriptState->isolate(), this)), adoptPtr(new OnStartFailed(scriptState->isolate(), this)));
+}
+
+ReadableStream::~ReadableStream()
+{
+}
+
+bool ReadableStream::enqueueInternal(ScriptValue chunk)
+{
+ // FIXME: Implemnt this method.
+ return false;
+}
+
+void ReadableStream::error(ScriptValue error)
+{
+ // FIXME: Implement this function correctly.
+ m_state = Errored;
+}
+
+void ReadableStream::onStarted()
+{
+ m_isStarted = true;
+}
+
+void ReadableStream::trace(Visitor* visitor)
+{
+ visitor->trace(m_source);
+}
+
+} // namespace blink
+
« no previous file with comments | « Source/core/streams/ReadableStream.h ('k') | Source/core/streams/ReadableStreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698