Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/public/bindings/js/core.h" | 5 #include "mojo/public/bindings/js/core.h" |
| 6 | 6 |
| 7 #include "gin/arguments.h" | 7 #include "gin/arguments.h" |
| 8 #include "gin/array_buffer.h" | 8 #include "gin/array_buffer.h" |
| 9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 10 #include "gin/dictionary.h" | 10 #include "gin/dictionary.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 dictionary.Set("handle1", handle_1); | 76 dictionary.Set("handle1", handle_1); |
| 77 args.Return(dictionary); | 77 args.Return(dictionary); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void WriteMessage(const v8::FunctionCallbackInfo<v8::Value>& info) { | 80 void WriteMessage(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 81 gin::Arguments args(info); | 81 gin::Arguments args(info); |
| 82 | 82 |
| 83 mojo::Handle handle = mojo::kInvalidHandle; | 83 mojo::Handle handle = mojo::kInvalidHandle; |
| 84 gin::ArrayBufferView buffer(args.isolate()); | 84 gin::ArrayBufferView buffer(args.isolate()); |
| 85 std::vector<mojo::Handle> handles; | 85 std::vector<mojo::Handle> handles; |
| 86 MojoWaitFlags flags = MOJO_WAIT_FLAG_NONE; | 86 MojoWriteMessageFlags flags = MOJO_WRITE_MESSAGE_FLAG_NONE; |
| 87 | 87 |
| 88 if (!args.GetNext(&handle) || | 88 if (!args.GetNext(&handle) || |
| 89 !args.GetNext(&buffer) || | 89 !args.GetNext(&buffer) || |
| 90 !args.GetNext(&handles) || | 90 !args.GetNext(&handles) || |
| 91 !args.GetNext(&flags)) { | 91 !args.GetNext(&flags)) { |
| 92 return args.ThrowError(); | 92 return args.ThrowError(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 args.Return(mojo::WriteMessage(handle, buffer.bytes(), buffer.num_bytes(), | 95 args.Return(mojo::WriteMessage(handle, buffer.bytes(), buffer.num_bytes(), |
| 96 handles.data(), handles.size(), flags)); | 96 handles.data(), handles.size(), flags)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ReadMessage(const v8::FunctionCallbackInfo<v8::Value>& info) { | 99 void ReadMessage(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 100 gin::Arguments args(info); | 100 gin::Arguments args(info); |
| 101 | 101 |
| 102 mojo::Handle handle = mojo::kInvalidHandle; | 102 mojo::Handle handle = mojo::kInvalidHandle; |
| 103 gin::ArrayBufferView buffer(args.isolate()); | 103 gin::ArrayBufferView buffer(args.isolate()); |
| 104 uint32_t num_handles = 0; | 104 uint32_t num_handles = 0; |
| 105 MojoWaitFlags flags = MOJO_WAIT_FLAG_NONE; | 105 MojoReadMessageFlags flags = MOJO_READ_MESSAGE_FLAG_NONE; |
| 106 | 106 |
| 107 if (!args.GetNext(&handle) || | 107 if (!args.GetNext(&handle) || |
| 108 !args.GetNext(&buffer) || | 108 !args.GetNext(&buffer) || |
| 109 !args.GetNext(&num_handles) || | 109 !args.GetNext(&num_handles) || |
| 110 !args.GetNext(&flags)) { | 110 !args.GetNext(&flags)) { |
| 111 return args.ThrowError(); | 111 return args.ThrowError(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 uint32_t num_bytes = buffer.num_bytes(); | 114 uint32_t num_bytes = buffer.num_bytes(); |
| 115 std::vector<mojo::Handle> handles(num_handles); | 115 std::vector<mojo::Handle> handles(num_handles); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 144 v8::FunctionTemplate::New(Wait)); | 144 v8::FunctionTemplate::New(Wait)); |
| 145 templ->Set(gin::StringToSymbol(isolate, "waitMany"), | 145 templ->Set(gin::StringToSymbol(isolate, "waitMany"), |
| 146 v8::FunctionTemplate::New(WaitMany)); | 146 v8::FunctionTemplate::New(WaitMany)); |
| 147 templ->Set(gin::StringToSymbol(isolate, "createMessagePipe"), | 147 templ->Set(gin::StringToSymbol(isolate, "createMessagePipe"), |
| 148 v8::FunctionTemplate::New(CreateMessagePipe)); | 148 v8::FunctionTemplate::New(CreateMessagePipe)); |
| 149 templ->Set(gin::StringToSymbol(isolate, "writeMessage"), | 149 templ->Set(gin::StringToSymbol(isolate, "writeMessage"), |
| 150 v8::FunctionTemplate::New(WriteMessage)); | 150 v8::FunctionTemplate::New(WriteMessage)); |
| 151 templ->Set(gin::StringToSymbol(isolate, "readMessage"), | 151 templ->Set(gin::StringToSymbol(isolate, "readMessage"), |
| 152 v8::FunctionTemplate::New(ReadMessage)); | 152 v8::FunctionTemplate::New(ReadMessage)); |
| 153 | 153 |
| 154 templ->Set(gin::StringToSymbol(isolate, "RESULT_OK"), | |
|
Aaron Boodman
2013/11/12 01:56:16
Hm. That's unsatisfying.
| |
| 155 gin::ConvertToV8(isolate, MOJO_RESULT_OK)); | |
| 156 templ->Set(gin::StringToSymbol(isolate, "RESULT_CANCELLED"), | |
| 157 gin::ConvertToV8(isolate, MOJO_RESULT_CANCELLED)); | |
| 158 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNKNOWN"), | |
| 159 gin::ConvertToV8(isolate, MOJO_RESULT_UNKNOWN)); | |
| 160 templ->Set(gin::StringToSymbol(isolate, "RESULT_INVALID_ARGUMENT"), | |
| 161 gin::ConvertToV8(isolate, MOJO_RESULT_INVALID_ARGUMENT)); | |
| 162 templ->Set(gin::StringToSymbol(isolate, "RESULT_DEADLINE_EXCEEDED"), | |
| 163 gin::ConvertToV8(isolate, MOJO_RESULT_DEADLINE_EXCEEDED)); | |
| 164 templ->Set(gin::StringToSymbol(isolate, "RESULT_NOT_FOUND"), | |
| 165 gin::ConvertToV8(isolate, MOJO_RESULT_NOT_FOUND)); | |
| 166 templ->Set(gin::StringToSymbol(isolate, "RESULT_ALREADY_EXISTS"), | |
| 167 gin::ConvertToV8(isolate, MOJO_RESULT_ALREADY_EXISTS)); | |
| 168 templ->Set(gin::StringToSymbol(isolate, "RESULT_PERMISSION_DENIED"), | |
| 169 gin::ConvertToV8(isolate, MOJO_RESULT_PERMISSION_DENIED)); | |
| 170 templ->Set(gin::StringToSymbol(isolate, "RESULT_RESOURCE_EXHAUSTED"), | |
| 171 gin::ConvertToV8(isolate, MOJO_RESULT_RESOURCE_EXHAUSTED)); | |
| 172 templ->Set(gin::StringToSymbol(isolate, "RESULT_FAILED_PRECONDITION"), | |
| 173 gin::ConvertToV8(isolate, MOJO_RESULT_FAILED_PRECONDITION)); | |
| 174 templ->Set(gin::StringToSymbol(isolate, "RESULT_ABORTED"), | |
| 175 gin::ConvertToV8(isolate, MOJO_RESULT_ABORTED)); | |
| 176 templ->Set(gin::StringToSymbol(isolate, "RESULT_OUT_OF_RANGE"), | |
| 177 gin::ConvertToV8(isolate, MOJO_RESULT_OUT_OF_RANGE)); | |
| 178 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNIMPLEMENTED"), | |
| 179 gin::ConvertToV8(isolate, MOJO_RESULT_UNIMPLEMENTED)); | |
| 180 templ->Set(gin::StringToSymbol(isolate, "RESULT_INTERNAL"), | |
| 181 gin::ConvertToV8(isolate, MOJO_RESULT_INTERNAL)); | |
| 182 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNAVAILABLE"), | |
| 183 gin::ConvertToV8(isolate, MOJO_RESULT_UNAVAILABLE)); | |
| 184 templ->Set(gin::StringToSymbol(isolate, "RESULT_DATA_LOSS"), | |
| 185 gin::ConvertToV8(isolate, MOJO_RESULT_DATA_LOSS)); | |
| 186 | |
| 187 templ->Set(gin::StringToSymbol(isolate, "DEADLINE_INDEFINITE"), | |
| 188 gin::ConvertToV8(isolate, MOJO_DEADLINE_INDEFINITE)); | |
| 189 | |
| 190 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_NONE"), | |
| 191 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_NONE)); | |
| 192 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 193 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 194 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 195 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 196 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_EVERYTHING"), | |
| 197 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_EVERYTHING)); | |
| 198 | |
| 199 templ->Set(gin::StringToSymbol(isolate, "WRITE_MESSAGE_FLAG_NONE"), | |
| 200 gin::ConvertToV8(isolate, MOJO_WRITE_MESSAGE_FLAG_NONE)); | |
| 201 | |
| 202 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_NONE"), | |
| 203 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 204 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_MAY_DISCARD"), | |
| 205 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); | |
| 206 | |
| 154 data->SetObjectTemplate(&g_core_wrapper_info, templ); | 207 data->SetObjectTemplate(&g_core_wrapper_info, templ); |
| 155 } | 208 } |
| 156 | 209 |
| 157 return templ; | 210 return templ; |
| 158 } | 211 } |
| 159 | 212 |
| 160 } // namespace js | 213 } // namespace js |
| 161 } // namespace mojo | 214 } // namespace mojo |
| OLD | NEW |