| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) { | 31 MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) { |
| 32 if (!handle->get().is_valid()) | 32 if (!handle->get().is_valid()) |
| 33 return MOJO_RESULT_INVALID_ARGUMENT; | 33 return MOJO_RESULT_INVALID_ARGUMENT; |
| 34 handle->Close(); | 34 handle->Close(); |
| 35 return MOJO_RESULT_OK; | 35 return MOJO_RESULT_OK; |
| 36 } | 36 } |
| 37 | 37 |
| 38 gin::Dictionary QueryHandleSignalsState(const gin::Arguments& args, | |
| 39 mojo::Handle handle) { | |
| 40 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); | |
| 41 if (!handle.is_valid()) { | |
| 42 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT); | |
| 43 } else { | |
| 44 HandleSignalsState state = handle.QuerySignalsState(); | |
| 45 dictionary.Set("result", MOJO_RESULT_OK); | |
| 46 dictionary.Set("satisfiedSignals", state.satisfied_signals); | |
| 47 dictionary.Set("satisfiableSignals", state.satisfiable_signals); | |
| 48 } | |
| 49 return dictionary; | |
| 50 } | |
| 51 | |
| 52 gin::Dictionary WaitHandle(const gin::Arguments& args, | 38 gin::Dictionary WaitHandle(const gin::Arguments& args, |
| 53 mojo::Handle handle, | 39 mojo::Handle handle, |
| 54 MojoHandleSignals signals, | 40 MojoHandleSignals signals, |
| 55 MojoDeadline deadline) { | 41 MojoDeadline deadline) { |
| 56 v8::Isolate* isolate = args.isolate(); | 42 v8::Isolate* isolate = args.isolate(); |
| 57 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate); | 43 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate); |
| 58 | 44 |
| 59 MojoHandleSignalsState signals_state; | 45 MojoHandleSignalsState signals_state; |
| 60 MojoResult result = mojo::Wait(handle, signals, deadline, &signals_state); | 46 MojoResult result = mojo::Wait(handle, signals, deadline, &signals_state); |
| 61 dictionary.Set("result", result); | 47 dictionary.Set("result", result); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 381 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 396 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 382 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 397 &g_wrapper_info); | 383 &g_wrapper_info); |
| 398 | 384 |
| 399 if (templ.IsEmpty()) { | 385 if (templ.IsEmpty()) { |
| 400 templ = | 386 templ = |
| 401 gin::ObjectTemplateBuilder(isolate) | 387 gin::ObjectTemplateBuilder(isolate) |
| 402 // TODO(mpcomplete): Should these just be methods on the JS Handle | 388 // TODO(mpcomplete): Should these just be methods on the JS Handle |
| 403 // object? | 389 // object? |
| 404 .SetMethod("close", CloseHandle) | 390 .SetMethod("close", CloseHandle) |
| 405 .SetMethod("queryHandleSignalsState", QueryHandleSignalsState) | |
| 406 .SetMethod("wait", WaitHandle) | 391 .SetMethod("wait", WaitHandle) |
| 407 .SetMethod("waitMany", WaitMany) | 392 .SetMethod("waitMany", WaitMany) |
| 408 .SetMethod("createMessagePipe", CreateMessagePipe) | 393 .SetMethod("createMessagePipe", CreateMessagePipe) |
| 409 .SetMethod("writeMessage", WriteMessage) | 394 .SetMethod("writeMessage", WriteMessage) |
| 410 .SetMethod("readMessage", ReadMessage) | 395 .SetMethod("readMessage", ReadMessage) |
| 411 .SetMethod("createDataPipe", CreateDataPipe) | 396 .SetMethod("createDataPipe", CreateDataPipe) |
| 412 .SetMethod("writeData", WriteData) | 397 .SetMethod("writeData", WriteData) |
| 413 .SetMethod("readData", ReadData) | 398 .SetMethod("readData", ReadData) |
| 414 .SetMethod("drainData", DoDrainData) | 399 .SetMethod("drainData", DoDrainData) |
| 415 .SetMethod("isHandle", IsHandle) | 400 .SetMethod("isHandle", IsHandle) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 468 |
| 484 data->SetObjectTemplate(&g_wrapper_info, templ); | 469 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 485 } | 470 } |
| 486 | 471 |
| 487 return templ->NewInstance(); | 472 return templ->NewInstance(); |
| 488 } | 473 } |
| 489 | 474 |
| 490 } // namespace js | 475 } // namespace js |
| 491 } // namespace edk | 476 } // namespace edk |
| 492 } // namespace mojo | 477 } // namespace mojo |
| OLD | NEW |