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

Unified Diff: Source/platform/streams/WebStreams.cpp

Issue 924713002: [WIP] ReadableStream V8 extension (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More complete implementation Created 5 years, 8 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/platform/streams/ReadableStream.js ('k') | Source/platform/streams/js2c.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/streams/WebStreams.cpp
diff --git a/Source/platform/streams/WebStreams.cpp b/Source/platform/streams/WebStreams.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..98453908f89882e2fd3feb575bd321809649a97f
--- /dev/null
+++ b/Source/platform/streams/WebStreams.cpp
@@ -0,0 +1,93 @@
+// 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 "public/platform/WebStreams.h"
+
+#include "wtf/Assertions.h"
+
+// TODO(domenic): auto-run js2c.py ReadableStream.js ReadableStream.cpp blink kStreamsExtensionCode using GYP
+// Also check to make sure this (ab)use of #include is kosher.
+// Also should we include the build products in the checkout? Probably not?
+#include "./ReadableStream.cpp"
+
+// TODO(domenic): presubmit checks don't like include order here ("Alphabetical sorting problem.")
+
+namespace blink {
+
+const char kStreamsExtensionName[] = "blink/streams";
+
+class StreamsExtensionImpl : public v8::Extension {
+ public:
+ StreamsExtensionImpl() : v8::Extension(kStreamsExtensionName, kStreamsExtensionCode) { }
+
+ private:
+ v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Handle<v8::String> name) override
+ {
+
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "SET_PRIVATE"))) {
+ return v8::FunctionTemplate::New(isolate, SetPrivate);
+ }
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "GET_PRIVATE"))) {
+ return v8::FunctionTemplate::New(isolate, GetPrivate);
+ }
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "HAS_PRIVATE"))) {
+ return v8::FunctionTemplate::New(isolate, HasPrivate);
+ }
+
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static void GetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info)
+ {
+ ASSERT(info.Length() == 2 && info[0]->IsObject() && info[1]->IsString());
+
+ auto isolate = info.GetIsolate();
+ v8::HandleScope scope(isolate);
+ auto object = info[0].As<v8::Object>();
+ auto name = info[1].As<v8::String>();
+
+ auto privateSymbol = v8::Private::ForApi(isolate, name);
+ auto value = object->GetPrivate(privateSymbol);
+
+ info.GetReturnValue().Set(value);
+ }
+
+ static void HasPrivate(const v8::FunctionCallbackInfo<v8::Value>& info)
+ {
+ ASSERT(info.Length() == 2 && info[0]->IsObject() && info[1]->IsString());
+
+ auto isolate = info.GetIsolate();
+ v8::HandleScope scope(isolate);
+ auto object = info[0].As<v8::Object>();
+ auto name = info[1].As<v8::String>();
+
+ auto privateSymbol = v8::Private::ForApi(isolate, name);
+ auto value = object->HasPrivate(privateSymbol);
+
+ info.GetReturnValue().Set(value);
+ }
+
+ static void SetPrivate(const v8::FunctionCallbackInfo<v8::Value>& info)
+ {
+ ASSERT(info.Length() == 3 && info[0]->IsObject() && info[1]->IsString());
+
+ auto isolate = info.GetIsolate();
+ v8::HandleScope scope(isolate);
+ auto object = info[0].As<v8::Object>();
+ auto name = info[1].As<v8::String>();
+ auto value = info[2];
+
+ auto privateSymbol = v8::Private::ForApi(isolate, name);
+ object->SetPrivate(privateSymbol, value);
+ }
+};
+
+v8::Extension* WebStreams::CreateV8Extension()
+{
+ return new StreamsExtensionImpl();
+}
+
+} // namespace blink
« no previous file with comments | « Source/platform/streams/ReadableStream.js ('k') | Source/platform/streams/js2c.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698