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

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

Issue 1167343002: Add methods for creating V8 extras-based ReadableStreams from C++ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: That todo is not necessary according to yhirano@ Created 5 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/UnderlyingSourceBase.h ('k') | Source/core/streams/UnderlyingSourceBase.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/streams/UnderlyingSourceBase.cpp
diff --git a/Source/core/streams/UnderlyingSourceBase.cpp b/Source/core/streams/UnderlyingSourceBase.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..51be038877fcdd35c48c50f835c8adbdf2d85f92
--- /dev/null
+++ b/Source/core/streams/UnderlyingSourceBase.cpp
@@ -0,0 +1,59 @@
+// 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/UnderlyingSourceBase.h"
+
+#include "core/streams/ReadableStreamController.h"
+#include <v8.h>
+
+namespace blink {
+
+ScriptPromise UnderlyingSourceBase::startWrapper(ScriptState* scriptState, ScriptValue stream)
+{
+ // Cannot call start twice (e.g., cannot use the same UnderlyingSourceBase to construct multiple streams)
+ ASSERT(!m_controller);
+
+ // In ReadableStream.js, we special-case externally-controlled streams by having them pass themselves to start
+ // as the first argument. This allows us to create a ReadableStreamController.
+
+ m_controller = new ReadableStreamController(stream);
+
+ return start(scriptState);
+}
+
+ScriptPromise UnderlyingSourceBase::start(ScriptState* scriptState)
+{
+ return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()));
+}
+
+ScriptPromise UnderlyingSourceBase::pull(ScriptState* scriptState)
+{
+ return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()));
+}
+
+ScriptPromise UnderlyingSourceBase::cancelWrapper(ScriptState* scriptState, ScriptValue reason)
+{
+ m_controller->noteHasBeenCanceled();
+ return cancel(scriptState, reason);
+}
+
+ScriptPromise UnderlyingSourceBase::cancel(ScriptState* scriptState, ScriptValue reason)
+{
+ return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()));
+}
+
+bool UnderlyingSourceBase::hasPendingActivity() const
+{
+ return m_controller && m_controller->isActive();
+}
+
+
+DEFINE_TRACE(UnderlyingSourceBase)
+{
+ ActiveDOMObject::trace(visitor);
+ visitor->trace(m_controller);
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/streams/UnderlyingSourceBase.h ('k') | Source/core/streams/UnderlyingSourceBase.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698