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

Unified Diff: mojo/bindings/js/core.cc

Issue 577733002: Mojo JS bindings: draining a DataPipe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More size_t Created 6 years, 3 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 | « mojo/bindings/js/BUILD.gn ('k') | mojo/bindings/js/drain_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/bindings/js/core.cc
diff --git a/mojo/bindings/js/core.cc b/mojo/bindings/js/core.cc
index ccabe87787d27544e0d8d149a8b211585dcb87fd..9ab2f19865c31fecc8ec938641b08d60b2988474 100644
--- a/mojo/bindings/js/core.cc
+++ b/mojo/bindings/js/core.cc
@@ -16,6 +16,7 @@
#include "gin/per_isolate_data.h"
#include "gin/public/wrapper_info.h"
#include "gin/wrappable.h"
+#include "mojo/bindings/js/drain_data.h"
#include "mojo/bindings/js/handle.h"
namespace mojo {
@@ -221,6 +222,18 @@ gin::Dictionary ReadData(const gin::Arguments& args,
return dictionary;
}
+// Asynchronously read all of the data available for the specified data pipe
+// consumer handle until the remote handle is closed or an error occurs. A
+// Promise is returned whose settled value is an object like this:
+// {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed,
+// then the Promise is rejected, the result will be the actual error code,
+// and the buffer will contain whatever was read before the error occurred.
+// The drainData data pipe handle argument is closed automatically.
+
+v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, mojo::Handle handle) {
+ return (new DrainData(args->isolate(), handle))->GetPromise();
+}
+
gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
} // namespace
@@ -245,6 +258,7 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
.SetMethod("createDataPipe", CreateDataPipe)
.SetMethod("writeData", WriteData)
.SetMethod("readData", ReadData)
+ .SetMethod("drainData", DoDrainData)
.SetValue("RESULT_OK", MOJO_RESULT_OK)
.SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
« no previous file with comments | « mojo/bindings/js/BUILD.gn ('k') | mojo/bindings/js/drain_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698