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

Side by Side Diff: mojo/edk/js/core.cc

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 5 years, 11 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/edk/embedder/embedder_unittest.cc ('k') | mojo/edk/js/tests/sample_service_tests.js » ('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/edk/js/core.h" 5 #include "mojo/edk/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"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace { 25 namespace {
26 26
27 MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) { 27 MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) {
28 if (!handle->get().is_valid()) 28 if (!handle->get().is_valid())
29 return MOJO_RESULT_INVALID_ARGUMENT; 29 return MOJO_RESULT_INVALID_ARGUMENT;
30 handle->Close(); 30 handle->Close();
31 return MOJO_RESULT_OK; 31 return MOJO_RESULT_OK;
32 } 32 }
33 33
34 MojoResult WaitHandle(mojo::Handle handle, 34 gin::Dictionary WaitHandle(const gin::Arguments& args,
35 MojoHandleSignals signals, 35 mojo::Handle handle,
36 MojoDeadline deadline) { 36 MojoHandleSignals signals,
37 return MojoWait(handle.value(), signals, deadline); 37 MojoDeadline deadline) {
38 v8::Isolate* isolate = args.isolate();
39 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate);
40
41 MojoHandleSignalsState signals_state;
42 MojoResult result = mojo::Wait(handle, signals, deadline, &signals_state);
43 dictionary.Set("result", result);
44
45 mojo::WaitManyResult wmv(result, 0);
46 if (!wmv.AreSignalsStatesValid()) {
47 dictionary.Set("signalsState", v8::Null(isolate).As<v8::Value>());
48 } else {
49 gin::Dictionary signalsStateDict = gin::Dictionary::CreateEmpty(isolate);
50 signalsStateDict.Set("satisfiedSignals", signals_state.satisfied_signals);
51 signalsStateDict.Set("satisfiableSignals",
52 signals_state.satisfiable_signals);
53 dictionary.Set("signalsState", signalsStateDict);
54 }
55
56 return dictionary;
38 } 57 }
39 58
40 MojoResult WaitMany( 59 gin::Dictionary WaitMany(const gin::Arguments& args,
41 const std::vector<mojo::Handle>& handles, 60 const std::vector<mojo::Handle>& handles,
42 const std::vector<MojoHandleSignals>& signals, 61 const std::vector<MojoHandleSignals>& signals,
43 MojoDeadline deadline) { 62 MojoDeadline deadline) {
44 return mojo::WaitMany(handles, signals, deadline); 63 v8::Isolate* isolate = args.isolate();
64 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate);
65
66 std::vector<MojoHandleSignalsState> signals_states(signals.size());
67 mojo::WaitManyResult wmv =
68 mojo::WaitMany(handles, signals, deadline, &signals_states);
69 dictionary.Set("result", wmv.result);
70 if (wmv.IsIndexValid()) {
71 dictionary.Set("index", wmv.index);
72 } else {
73 dictionary.Set("index", v8::Null(isolate).As<v8::Value>());
74 }
75 if (wmv.AreSignalsStatesValid()) {
76 std::vector<gin::Dictionary> vec;
77 for (size_t i = 0; i < handles.size(); ++i) {
78 gin::Dictionary signalsStateDict = gin::Dictionary::CreateEmpty(isolate);
79 signalsStateDict.Set("satisfiedSignals",
80 signals_states[i].satisfied_signals);
81 signalsStateDict.Set("satisfiableSignals",
82 signals_states[i].satisfiable_signals);
83 vec.push_back(signalsStateDict);
84 }
85 dictionary.Set("signalsState", vec);
86 } else {
87 dictionary.Set("signalsState", v8::Null(isolate).As<v8::Value>());
88 }
89
90 return dictionary;
45 } 91 }
46 92
47 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { 93 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) {
48 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 94 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
49 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT); 95 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
50 96
51 MojoHandle handle0 = MOJO_HANDLE_INVALID; 97 MojoHandle handle0 = MOJO_HANDLE_INVALID;
52 MojoHandle handle1 = MOJO_HANDLE_INVALID; 98 MojoHandle handle1 = MOJO_HANDLE_INVALID;
53 MojoResult result = MOJO_RESULT_OK; 99 MojoResult result = MOJO_RESULT_OK;
54 100
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed, 274 // {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed,
229 // then the Promise is rejected, the result will be the actual error code, 275 // 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. 276 // and the buffer will contain whatever was read before the error occurred.
231 // The drainData data pipe handle argument is closed automatically. 277 // The drainData data pipe handle argument is closed automatically.
232 278
233 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, 279 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args,
234 gin::Handle<HandleWrapper> handle) { 280 gin::Handle<HandleWrapper> handle) {
235 return (new DrainData(args->isolate(), handle->release()))->GetPromise(); 281 return (new DrainData(args->isolate(), handle->release()))->GetPromise();
236 } 282 }
237 283
284 bool IsHandle(gin::Arguments* args, v8::Handle<v8::Value> val) {
285 gin::Handle<mojo::js::HandleWrapper> ignore_handle;
286 return gin::Converter<gin::Handle<mojo::js::HandleWrapper>>::FromV8(
287 args->isolate(), val, &ignore_handle);
288 }
289
290
238 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 291 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
239 292
240 } // namespace 293 } // namespace
241 294
242 const char Core::kModuleName[] = "mojo/public/js/core"; 295 const char Core::kModuleName[] = "mojo/public/js/core";
243 296
244 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { 297 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
245 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 298 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
246 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( 299 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
247 &g_wrapper_info); 300 &g_wrapper_info);
248 301
249 if (templ.IsEmpty()) { 302 if (templ.IsEmpty()) {
250 templ = 303 templ =
251 gin::ObjectTemplateBuilder(isolate) 304 gin::ObjectTemplateBuilder(isolate)
252 // TODO(mpcomplete): Should these just be methods on the JS Handle 305 // TODO(mpcomplete): Should these just be methods on the JS Handle
253 // object? 306 // object?
254 .SetMethod("close", CloseHandle) 307 .SetMethod("close", CloseHandle)
255 .SetMethod("wait", WaitHandle) 308 .SetMethod("wait", WaitHandle)
256 .SetMethod("waitMany", WaitMany) 309 .SetMethod("waitMany", WaitMany)
257 .SetMethod("createMessagePipe", CreateMessagePipe) 310 .SetMethod("createMessagePipe", CreateMessagePipe)
258 .SetMethod("writeMessage", WriteMessage) 311 .SetMethod("writeMessage", WriteMessage)
259 .SetMethod("readMessage", ReadMessage) 312 .SetMethod("readMessage", ReadMessage)
260 .SetMethod("createDataPipe", CreateDataPipe) 313 .SetMethod("createDataPipe", CreateDataPipe)
261 .SetMethod("writeData", WriteData) 314 .SetMethod("writeData", WriteData)
262 .SetMethod("readData", ReadData) 315 .SetMethod("readData", ReadData)
263 .SetMethod("drainData", DoDrainData) 316 .SetMethod("drainData", DoDrainData)
317 .SetMethod("isHandle", IsHandle)
264 318
265 .SetValue("RESULT_OK", MOJO_RESULT_OK) 319 .SetValue("RESULT_OK", MOJO_RESULT_OK)
266 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) 320 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
267 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) 321 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
268 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) 322 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
269 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) 323 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
270 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) 324 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
271 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) 325 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
272 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) 326 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
273 .SetValue("RESULT_RESOURCE_EXHAUSTED", 327 .SetValue("RESULT_RESOURCE_EXHAUSTED",
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 .Build(); 372 .Build();
319 373
320 data->SetObjectTemplate(&g_wrapper_info, templ); 374 data->SetObjectTemplate(&g_wrapper_info, templ);
321 } 375 }
322 376
323 return templ->NewInstance(); 377 return templ->NewInstance();
324 } 378 }
325 379
326 } // namespace js 380 } // namespace js
327 } // namespace mojo 381 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder_unittest.cc ('k') | mojo/edk/js/tests/sample_service_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698