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

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

Issue 1118673002: Implement ReadableStream as a V8 extra (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleanups; make controller a member instead of arg Created 5 years, 7 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/ScriptReadableStreamController.h ('k') | Source/core/streams/ScriptUnderlyingSource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/streams/ScriptReadableStreamController.cpp
diff --git a/Source/core/streams/ScriptReadableStreamController.cpp b/Source/core/streams/ScriptReadableStreamController.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fb1b853e25870e45546690be4d1badc773b507fd
--- /dev/null
+++ b/Source/core/streams/ScriptReadableStreamController.cpp
@@ -0,0 +1,95 @@
+// 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.
+
+#include "config.h"
+#include "core/streams/ScriptReadableStreamController.h"
+
+#include "bindings/core/v8/ToV8.h"
+
+namespace blink {
+
+// TODO probably need the asserts from the spec here
+
+// NOTE: the normal graph is ScriptReadableStreamController -> ScriptReadableStream -> V8 ReadableStream object ->
+// V8 underlying source object -> ScriptUnderlyingSource -> ScriptReadableStream -> ScriptReadableStreamController ....
+// However once you call close() or error() methods of ScriptReadableStreamController, the
+// ScriptReadableStreamController -> ScriptReadableStream link is broken by m_stream.clear().
+
+ScriptReadableStreamController::ScriptReadableStreamController(ScriptValue stream) : m_stream(stream)
+{
+}
+
+void ScriptReadableStreamController::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(undefined, 1, args);
+
+ // TODO crash if result is empty (i.e. an exception)
+
+ m_stream.clear();
+}
+
+double ScriptReadableStreamController::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(undefined, 1, args);
+
+ return result.As<v8::Number>()->Value();
+}
+
+template<typename ChunkType>
+void ScriptReadableStreamController::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(undefined, 2, args);
+
+ // TODO crash if result is empty (i.e. an exception)
+}
+
+template<typename ErrorType>
+void ScriptReadableStreamController::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(undefined, 2, args);
+
+ // TODO crash if result is empty (i.e. an exception)
+
+ m_stream.clear();
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/streams/ScriptReadableStreamController.h ('k') | Source/core/streams/ScriptUnderlyingSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698