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

Side by Side 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, 2 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/bindings/js/core.h" 5 #include "mojo/bindings/js/core.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "gin/arguments.h" 9 #include "gin/arguments.h"
10 #include "gin/array_buffer.h" 10 #include "gin/array_buffer.h"
11 #include "gin/converter.h" 11 #include "gin/converter.h"
12 #include "gin/dictionary.h" 12 #include "gin/dictionary.h"
13 #include "gin/function_template.h" 13 #include "gin/function_template.h"
14 #include "gin/handle.h" 14 #include "gin/handle.h"
15 #include "gin/object_template_builder.h" 15 #include "gin/object_template_builder.h"
16 #include "gin/per_isolate_data.h" 16 #include "gin/per_isolate_data.h"
17 #include "gin/public/wrapper_info.h" 17 #include "gin/public/wrapper_info.h"
18 #include "gin/wrappable.h" 18 #include "gin/wrappable.h"
19 #include "mojo/bindings/js/drain_data.h"
19 #include "mojo/bindings/js/handle.h" 20 #include "mojo/bindings/js/handle.h"
20 21
21 namespace mojo { 22 namespace mojo {
22 namespace js { 23 namespace js {
23 24
24 namespace { 25 namespace {
25 26
26 MojoResult CloseHandle(gin::Handle<gin::HandleWrapper> handle) { 27 MojoResult CloseHandle(gin::Handle<gin::HandleWrapper> handle) {
27 if (!handle->get().is_valid()) 28 if (!handle->get().is_valid())
28 return MOJO_RESULT_INVALID_ARGUMENT; 29 return MOJO_RESULT_INVALID_ARGUMENT;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 215
215 result = MojoReadData(handle.value(), buffer.bytes(), &num_bytes, flags); 216 result = MojoReadData(handle.value(), buffer.bytes(), &num_bytes, flags);
216 CHECK_EQ(num_bytes, buffer.num_bytes()); 217 CHECK_EQ(num_bytes, buffer.num_bytes());
217 218
218 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 219 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
219 dictionary.Set("result", result); 220 dictionary.Set("result", result);
220 dictionary.Set("buffer", array_buffer); 221 dictionary.Set("buffer", array_buffer);
221 return dictionary; 222 return dictionary;
222 } 223 }
223 224
225 // Asynchronously read all of the data available for the specified data pipe
226 // consumer handle until the remote handle is closed or an error occurs. A
227 // Promise is returned whose settled value is an object like this:
228 // {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed,
229 // then the Promise is rejected, the result will be the actual error code,
230 // and the buffer will contain whatever was read before the error occurred.
231 // The drainData data pipe handle argument is closed automatically.
232
233 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, mojo::Handle handle) {
234 return (new DrainData(args->isolate(), handle))->GetPromise();
235 }
236
224 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 237 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
225 238
226 } // namespace 239 } // namespace
227 240
228 const char Core::kModuleName[] = "mojo/public/js/bindings/core"; 241 const char Core::kModuleName[] = "mojo/public/js/bindings/core";
229 242
230 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { 243 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
231 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 244 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
232 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( 245 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
233 &g_wrapper_info); 246 &g_wrapper_info);
234 247
235 if (templ.IsEmpty()) { 248 if (templ.IsEmpty()) {
236 templ = gin::ObjectTemplateBuilder(isolate) 249 templ = gin::ObjectTemplateBuilder(isolate)
237 // TODO(mpcomplete): Should these just be methods on the JS Handle 250 // TODO(mpcomplete): Should these just be methods on the JS Handle
238 // object? 251 // object?
239 .SetMethod("close", CloseHandle) 252 .SetMethod("close", CloseHandle)
240 .SetMethod("wait", WaitHandle) 253 .SetMethod("wait", WaitHandle)
241 .SetMethod("waitMany", WaitMany) 254 .SetMethod("waitMany", WaitMany)
242 .SetMethod("createMessagePipe", CreateMessagePipe) 255 .SetMethod("createMessagePipe", CreateMessagePipe)
243 .SetMethod("writeMessage", WriteMessage) 256 .SetMethod("writeMessage", WriteMessage)
244 .SetMethod("readMessage", ReadMessage) 257 .SetMethod("readMessage", ReadMessage)
245 .SetMethod("createDataPipe", CreateDataPipe) 258 .SetMethod("createDataPipe", CreateDataPipe)
246 .SetMethod("writeData", WriteData) 259 .SetMethod("writeData", WriteData)
247 .SetMethod("readData", ReadData) 260 .SetMethod("readData", ReadData)
261 .SetMethod("drainData", DoDrainData)
248 262
249 .SetValue("RESULT_OK", MOJO_RESULT_OK) 263 .SetValue("RESULT_OK", MOJO_RESULT_OK)
250 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) 264 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
251 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) 265 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
252 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) 266 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
253 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) 267 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
254 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) 268 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
255 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) 269 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
256 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) 270 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
257 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED) 271 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 .Build(); 311 .Build();
298 312
299 data->SetObjectTemplate(&g_wrapper_info, templ); 313 data->SetObjectTemplate(&g_wrapper_info, templ);
300 } 314 }
301 315
302 return templ->NewInstance(); 316 return templ->NewInstance();
303 } 317 }
304 318
305 } // namespace js 319 } // namespace js
306 } // namespace mojo 320 } // namespace mojo
OLDNEW
« 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