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

Unified Diff: Source/core/streams/ReadableStream2.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/ReadableStream2.h ('k') | Source/core/streams/ReadableStream2.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/streams/ReadableStream2.cpp
diff --git a/Source/core/streams/ReadableStream2.cpp b/Source/core/streams/ReadableStream2.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ec960ddeb40c031fca3139240fe037b49bdf74e2
--- /dev/null
+++ b/Source/core/streams/ReadableStream2.cpp
@@ -0,0 +1,54 @@
+// 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/ReadableStream2.h"
+
+#include "bindings/core/v8/ToV8.h"
+#include "bindings/core/v8/V8RecursionScope.h"
+#include "core/streams/UnderlyingSourceBase.h"
+#include <v8.h>
+
+namespace blink {
+
+namespace JSStreams {
+
+ScriptValue createReadableStream(ScriptState* scriptState, UnderlyingSourceBase* underlyingSource, ScriptValue strategy)
+{
+ ScriptState::Scope scope(scriptState);
+ auto global = scriptState->context()->Global();
+ auto isolate = scriptState->isolate();
+
+ auto jsUnderlyingSource = toV8(underlyingSource, global, isolate);
+ auto jsStrategy = strategy.v8Value();
+
+ auto sentinel = scriptState->getFromExtrasExports("createWithExternalControllerSentinel").v8Value();
+ auto constructor = scriptState->getFromExtrasExports("ReadableStream").v8Value().As<v8::Function>();
+
+ v8::Local<v8::Value> args[] = { jsUnderlyingSource, jsStrategy, sentinel };
+
+ V8RecursionScope::MicrotaskSuppression mtsScope(isolate);
+ auto jsStream = constructor->NewInstance(arraysize(args), args);
+
+ return ScriptValue(scriptState, jsStream);
+}
+
+ScriptValue createCountQueuingStrategy(ScriptState* scriptState, size_t highWaterMark)
+{
+ ScriptState::Scope scope(scriptState);
+ auto isolate = scriptState->isolate();
+
+ auto constructor = scriptState->getFromExtrasExports("BuiltInCountQueuingStrategy").v8Value().As<v8::Function>();
+
+ v8::Local<v8::Value> args[] = { v8::Number::New(isolate, highWaterMark) };
+
+ V8RecursionScope::MicrotaskSuppression mtsScope(isolate);
+ auto jsStrategy = constructor->NewInstance(arraysize(args), args);
+
+ return ScriptValue(scriptState, jsStrategy);
+}
+
+} // namespace JSStreams
+
+} // namespace blink
« no previous file with comments | « Source/core/streams/ReadableStream2.h ('k') | Source/core/streams/ReadableStream2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698