| Index: mojo/dart/embedder/mojo_natives.cc
|
| diff --git a/mojo/dart/embedder/mojo_natives.cc b/mojo/dart/embedder/mojo_natives.cc
|
| index 984c054de7b25d526134b55b665e1e89483c2e11..a72788efa17884bd713800a80a753f06ea03f736 100644
|
| --- a/mojo/dart/embedder/mojo_natives.cc
|
| +++ b/mojo/dart/embedder/mojo_natives.cc
|
| @@ -34,7 +34,7 @@ namespace dart {
|
| V(MojoMessagePipe_Create, 1) \
|
| V(MojoMessagePipe_Write, 5) \
|
| V(MojoMessagePipe_Read, 5) \
|
| - V(MojoMessagePipe_QueryAndRead, 2) \
|
| + V(MojoMessagePipe_QueryAndRead, 5) \
|
| V(Mojo_GetTimeTicksNow, 0) \
|
| V(MojoHandle_Close, 1) \
|
| V(MojoHandle_Wait, 3) \
|
| @@ -723,26 +723,16 @@ void MojoMessagePipe_Read(Dart_NativeArguments arguments) {
|
| Dart_SetReturnValue(arguments, list);
|
| }
|
|
|
| -struct MojoWaitManyState {
|
| - MojoWaitManyState() {}
|
| -
|
| - std::vector<uint32_t> handles;
|
| - std::vector<uint32_t> signals;
|
| - std::vector<uint32_t> out_index;
|
| - std::vector<MojoHandleSignalsState> out_signals;
|
| -
|
| - static MojoWaitManyState* GetInstance();
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState);
|
| -};
|
| -
|
| void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) {
|
| int64_t dart_handle;
|
| int64_t flags = 0;
|
| CHECK_INTEGER_ARGUMENT(arguments, 0, &dart_handle, Null);
|
| CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null);
|
|
|
| + Dart_Handle data = Dart_GetNativeArgument(arguments, 2);
|
| + Dart_Handle handles = Dart_GetNativeArgument(arguments, 3);
|
| + Dart_Handle result = Dart_GetNativeArgument(arguments, 4);
|
| +
|
| // Query the number of bytes and handles available.
|
| uint32_t blen = 0;
|
| uint32_t hlen = 0;
|
| @@ -751,53 +741,64 @@ void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) {
|
| nullptr, &hlen, static_cast<MojoReadMessageFlags>(flags));
|
|
|
| if ((res != MOJO_RESULT_OK) && (res != MOJO_RESULT_RESOURCE_EXHAUSTED)) {
|
| - Dart_Handle list = Dart_NewList(3);
|
| - Dart_ListSetAt(list, 0, Dart_NewInteger(res));
|
| - Dart_SetReturnValue(arguments, list);
|
| + Dart_ListSetAt(result, 0, Dart_NewInteger(res));
|
| + Dart_ListSetAt(result, 1, data);
|
| + Dart_ListSetAt(result, 2, handles);
|
| + Dart_ListSetAt(result, 3, Dart_NewInteger(0));
|
| + Dart_ListSetAt(result, 4, Dart_NewInteger(0));
|
| return;
|
| }
|
|
|
| - Dart_Handle data = Dart_Null();
|
| - if (blen > 0) {
|
| - data = Dart_NewTypedData(Dart_TypedData_kByteData, blen);
|
| + MojoDartState* state = MojoDartState::Current();
|
| +
|
| + if ((blen > 0) &&
|
| + (Dart_IsNull(data) || (state->message_data().size() < blen))) {
|
| + state->message_data().resize(blen);
|
| + data = Dart_NewExternalTypedData(Dart_TypedData_kByteData,
|
| + state->message_data().data(), blen);
|
| }
|
|
|
| - Dart_Handle handles = Dart_Null();
|
| - if (hlen > 0) {
|
| - handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen);
|
| + if ((hlen > 0) &&
|
| + (Dart_IsNull(handles) || (state->message_handles().size() < hlen))) {
|
| + state->message_handles().resize(hlen);
|
| + handles = Dart_NewExternalTypedData(Dart_TypedData_kUint32,
|
| + state->message_handles().data(), hlen);
|
| }
|
|
|
| - Dart_TypedData_Type typ;
|
| void* bytes = nullptr;
|
| - intptr_t byte_data_len = 0;
|
| if (blen > 0) {
|
| - Dart_TypedDataAcquireData(data, &typ, &bytes, &byte_data_len);
|
| + bytes = state->message_data().data();
|
| }
|
|
|
| void* handle_bytes = nullptr;
|
| - intptr_t handle_bytes_len = 0;
|
| if (hlen > 0) {
|
| - Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handle_bytes_len);
|
| + handle_bytes = state->message_handles().data();
|
| }
|
|
|
| res = MojoReadMessage(static_cast<MojoHandle>(dart_handle), bytes, &blen,
|
| reinterpret_cast<MojoHandle*>(handle_bytes), &hlen,
|
| static_cast<MojoReadMessageFlags>(flags));
|
|
|
| - if (byte_data_len > 0) {
|
| - Dart_TypedDataReleaseData(data);
|
| - }
|
| + Dart_ListSetAt(result, 0, Dart_NewInteger(res));
|
| + Dart_ListSetAt(result, 1, data);
|
| + Dart_ListSetAt(result, 2, handles);
|
| + Dart_ListSetAt(result, 3, Dart_NewInteger(blen));
|
| + Dart_ListSetAt(result, 4, Dart_NewInteger(hlen));
|
| +}
|
|
|
| - if (handle_bytes_len > 0) {
|
| - Dart_TypedDataReleaseData(handles);
|
| - }
|
| +struct MojoWaitManyState {
|
| + MojoWaitManyState() {}
|
|
|
| - Dart_Handle list = Dart_NewList(3);
|
| - Dart_ListSetAt(list, 0, Dart_NewInteger(res));
|
| - Dart_ListSetAt(list, 1, data);
|
| - Dart_ListSetAt(list, 2, handles);
|
| - Dart_SetReturnValue(arguments, list);
|
| -}
|
| + std::vector<uint32_t> handles;
|
| + std::vector<uint32_t> signals;
|
| + std::vector<uint32_t> out_index;
|
| + std::vector<MojoHandleSignalsState> out_signals;
|
| +
|
| + static MojoWaitManyState* GetInstance();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState);
|
| +};
|
|
|
| // This global is safe because it is only accessed by the single handle watcher
|
| // isolate. If multiple handle watcher isolates are ever needed, it will need
|
|
|