| 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 "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/object_template_builder.h" |
| 14 #include "gin/per_isolate_data.h" | 15 #include "gin/per_isolate_data.h" |
| 15 #include "gin/public/wrapper_info.h" | 16 #include "gin/public/wrapper_info.h" |
| 16 #include "mojo/public/bindings/js/handle.h" | 17 #include "mojo/public/bindings/js/handle.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace js { | 20 namespace js { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { | 24 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } // namespace | 87 } // namespace |
| 87 | 88 |
| 88 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; | 89 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; |
| 89 | 90 |
| 90 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { | 91 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { |
| 91 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 92 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 92 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 93 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 93 &g_wrapper_info); | 94 &g_wrapper_info); |
| 94 | 95 |
| 95 if (templ.IsEmpty()) { | 96 if (templ.IsEmpty()) { |
| 96 templ = v8::ObjectTemplate::New(isolate); | 97 templ = gin::ObjectTemplateBuilder(isolate) |
| 98 .SetMethod("close", mojo::CloseRaw) |
| 99 .SetMethod("wait", mojo::Wait) |
| 100 .SetMethod("waitMany", mojo::WaitMany<std::vector<mojo::Handle>, |
| 101 std::vector<MojoWaitFlags> >) |
| 102 .SetMethod("createMessagePipe", CreateMessagePipe) |
| 103 .SetMethod("writeMessage", WriteMessage) |
| 104 .SetMethod("readMessage", ReadMessage) |
| 97 | 105 |
| 98 templ->Set(gin::StringToSymbol(isolate, "close"), | 106 // TODO(vtl): Change name of "kInvalidHandle", now that there's no such |
| 99 gin::CreateFunctionTemplate(isolate, | 107 // C++ constant? |
| 100 base::Bind(mojo::CloseRaw))); | 108 .SetValue("kInvalidHandle", mojo::Handle()) |
| 101 templ->Set(gin::StringToSymbol(isolate, "wait"), | |
| 102 gin::CreateFunctionTemplate(isolate, | |
| 103 base::Bind(mojo::Wait))); | |
| 104 templ->Set(gin::StringToSymbol(isolate, "waitMany"), | |
| 105 gin::CreateFunctionTemplate(isolate, | |
| 106 base::Bind(mojo::WaitMany<std::vector<mojo::Handle>, | |
| 107 std::vector<MojoWaitFlags> >))); | |
| 108 templ->Set(gin::StringToSymbol(isolate, "createMessagePipe"), | |
| 109 gin::CreateFunctionTemplate(isolate, | |
| 110 base::Bind(CreateMessagePipe))); | |
| 111 templ->Set(gin::StringToSymbol(isolate, "writeMessage"), | |
| 112 gin::CreateFunctionTemplate(isolate, | |
| 113 base::Bind(WriteMessage))); | |
| 114 templ->Set(gin::StringToSymbol(isolate, "readMessage"), | |
| 115 gin::CreateFunctionTemplate(isolate, | |
| 116 base::Bind(ReadMessage))); | |
| 117 | 109 |
| 118 // TODO(vtl): Change name of "kInvalidHandle", now that there's no such C++ | 110 .SetValue("RESULT_OK", MOJO_RESULT_OK) |
| 119 // constant? | 111 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) |
| 120 templ->Set(gin::StringToSymbol(isolate, "kInvalidHandle"), | 112 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) |
| 121 gin::ConvertToV8(isolate, mojo::Handle())); | 113 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) |
| 114 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) |
| 115 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) |
| 116 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) |
| 117 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) |
| 118 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED) |
| 119 .SetValue("RESULT_FAILED_PRECONDITION", MOJO_RESULT_FAILED_PRECONDITION) |
| 120 .SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED) |
| 121 .SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE) |
| 122 .SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED) |
| 123 .SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL) |
| 124 .SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE) |
| 125 .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS) |
| 122 | 126 |
| 123 templ->Set(gin::StringToSymbol(isolate, "RESULT_OK"), | 127 .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE) |
| 124 gin::ConvertToV8(isolate, MOJO_RESULT_OK)); | |
| 125 templ->Set(gin::StringToSymbol(isolate, "RESULT_CANCELLED"), | |
| 126 gin::ConvertToV8(isolate, MOJO_RESULT_CANCELLED)); | |
| 127 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNKNOWN"), | |
| 128 gin::ConvertToV8(isolate, MOJO_RESULT_UNKNOWN)); | |
| 129 templ->Set(gin::StringToSymbol(isolate, "RESULT_INVALID_ARGUMENT"), | |
| 130 gin::ConvertToV8(isolate, MOJO_RESULT_INVALID_ARGUMENT)); | |
| 131 templ->Set(gin::StringToSymbol(isolate, "RESULT_DEADLINE_EXCEEDED"), | |
| 132 gin::ConvertToV8(isolate, MOJO_RESULT_DEADLINE_EXCEEDED)); | |
| 133 templ->Set(gin::StringToSymbol(isolate, "RESULT_NOT_FOUND"), | |
| 134 gin::ConvertToV8(isolate, MOJO_RESULT_NOT_FOUND)); | |
| 135 templ->Set(gin::StringToSymbol(isolate, "RESULT_ALREADY_EXISTS"), | |
| 136 gin::ConvertToV8(isolate, MOJO_RESULT_ALREADY_EXISTS)); | |
| 137 templ->Set(gin::StringToSymbol(isolate, "RESULT_PERMISSION_DENIED"), | |
| 138 gin::ConvertToV8(isolate, MOJO_RESULT_PERMISSION_DENIED)); | |
| 139 templ->Set(gin::StringToSymbol(isolate, "RESULT_RESOURCE_EXHAUSTED"), | |
| 140 gin::ConvertToV8(isolate, MOJO_RESULT_RESOURCE_EXHAUSTED)); | |
| 141 templ->Set(gin::StringToSymbol(isolate, "RESULT_FAILED_PRECONDITION"), | |
| 142 gin::ConvertToV8(isolate, MOJO_RESULT_FAILED_PRECONDITION)); | |
| 143 templ->Set(gin::StringToSymbol(isolate, "RESULT_ABORTED"), | |
| 144 gin::ConvertToV8(isolate, MOJO_RESULT_ABORTED)); | |
| 145 templ->Set(gin::StringToSymbol(isolate, "RESULT_OUT_OF_RANGE"), | |
| 146 gin::ConvertToV8(isolate, MOJO_RESULT_OUT_OF_RANGE)); | |
| 147 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNIMPLEMENTED"), | |
| 148 gin::ConvertToV8(isolate, MOJO_RESULT_UNIMPLEMENTED)); | |
| 149 templ->Set(gin::StringToSymbol(isolate, "RESULT_INTERNAL"), | |
| 150 gin::ConvertToV8(isolate, MOJO_RESULT_INTERNAL)); | |
| 151 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNAVAILABLE"), | |
| 152 gin::ConvertToV8(isolate, MOJO_RESULT_UNAVAILABLE)); | |
| 153 templ->Set(gin::StringToSymbol(isolate, "RESULT_DATA_LOSS"), | |
| 154 gin::ConvertToV8(isolate, MOJO_RESULT_DATA_LOSS)); | |
| 155 | 128 |
| 156 templ->Set(gin::StringToSymbol(isolate, "DEADLINE_INDEFINITE"), | 129 .SetValue("WAIT_FLAG_NONE", MOJO_WAIT_FLAG_NONE) |
| 157 gin::ConvertToV8(isolate, MOJO_DEADLINE_INDEFINITE)); | 130 .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE) |
| 131 .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE) |
| 132 .SetValue("WAIT_FLAG_EVERYTHING", MOJO_WAIT_FLAG_EVERYTHING) |
| 158 | 133 |
| 159 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_NONE"), | 134 .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE) |
| 160 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_NONE)); | |
| 161 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 162 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 163 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 164 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 165 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_EVERYTHING"), | |
| 166 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_EVERYTHING)); | |
| 167 | 135 |
| 168 templ->Set(gin::StringToSymbol(isolate, "WRITE_MESSAGE_FLAG_NONE"), | 136 .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE) |
| 169 gin::ConvertToV8(isolate, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 137 .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD", |
| 170 | 138 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD) |
| 171 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_NONE"), | 139 .Build(); |
| 172 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 173 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_MAY_DISCARD"), | |
| 174 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); | |
| 175 | 140 |
| 176 data->SetObjectTemplate(&g_wrapper_info, templ); | 141 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 177 } | 142 } |
| 178 | 143 |
| 179 return templ; | 144 return templ; |
| 180 } | 145 } |
| 181 | 146 |
| 182 } // namespace js | 147 } // namespace js |
| 183 } // namespace mojo | 148 } // namespace mojo |
| OLD | NEW |