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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 uint32_t num_bytes = 0; | 49 uint32_t num_bytes = 0; |
50 uint32_t num_handles = 0; | 50 uint32_t num_handles = 0; |
51 MojoResult result = MojoReadMessage( | 51 MojoResult result = MojoReadMessage( |
52 handle, NULL, &num_bytes, NULL, &num_handles, flags); | 52 handle, NULL, &num_bytes, NULL, &num_handles, flags); |
53 if (result != MOJO_RESULT_RESOURCE_EXHAUSTED) { | 53 if (result != MOJO_RESULT_RESOURCE_EXHAUSTED) { |
54 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); | 54 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); |
55 dictionary.Set("result", result); | 55 dictionary.Set("result", result); |
56 return dictionary; | 56 return dictionary; |
57 } | 57 } |
58 | 58 |
59 v8::Handle<v8::ArrayBuffer> array_buffer = v8::ArrayBuffer::New(num_bytes); | 59 v8::Handle<v8::ArrayBuffer> array_buffer = |
| 60 v8::ArrayBuffer::New(args.isolate(), num_bytes); |
60 std::vector<MojoHandle> handles(num_handles); | 61 std::vector<MojoHandle> handles(num_handles); |
61 | 62 |
62 gin::ArrayBuffer buffer; | 63 gin::ArrayBuffer buffer; |
63 ConvertFromV8(args.isolate(), array_buffer, &buffer); | 64 ConvertFromV8(args.isolate(), array_buffer, &buffer); |
64 CHECK(buffer.num_bytes() == num_bytes); | 65 CHECK(buffer.num_bytes() == num_bytes); |
65 | 66 |
66 result = MojoReadMessage(handle, | 67 result = MojoReadMessage(handle, |
67 buffer.bytes(), | 68 buffer.bytes(), |
68 &num_bytes, | 69 &num_bytes, |
69 handles.empty() ? NULL : handles.data(), | 70 handles.empty() ? NULL : handles.data(), |
(...skipping 15 matching lines...) Expand all Loading... |
85 } // namespace | 86 } // namespace |
86 | 87 |
87 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; | 88 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; |
88 | 89 |
89 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { | 90 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { |
90 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 91 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
91 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 92 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
92 &g_wrapper_info); | 93 &g_wrapper_info); |
93 | 94 |
94 if (templ.IsEmpty()) { | 95 if (templ.IsEmpty()) { |
95 templ = v8::ObjectTemplate::New(); | 96 templ = v8::ObjectTemplate::New(isolate); |
96 | 97 |
97 templ->Set(gin::StringToSymbol(isolate, "close"), | 98 templ->Set(gin::StringToSymbol(isolate, "close"), |
98 gin::CreateFunctionTemplate(isolate, | 99 gin::CreateFunctionTemplate(isolate, |
99 base::Bind(mojo::CloseRaw))); | 100 base::Bind(mojo::CloseRaw))); |
100 templ->Set(gin::StringToSymbol(isolate, "wait"), | 101 templ->Set(gin::StringToSymbol(isolate, "wait"), |
101 gin::CreateFunctionTemplate(isolate, | 102 gin::CreateFunctionTemplate(isolate, |
102 base::Bind(mojo::Wait))); | 103 base::Bind(mojo::Wait))); |
103 templ->Set(gin::StringToSymbol(isolate, "waitMany"), | 104 templ->Set(gin::StringToSymbol(isolate, "waitMany"), |
104 gin::CreateFunctionTemplate(isolate, | 105 gin::CreateFunctionTemplate(isolate, |
105 base::Bind(mojo::WaitMany<std::vector<mojo::Handle>, | 106 base::Bind(mojo::WaitMany<std::vector<mojo::Handle>, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); | 174 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); |
174 | 175 |
175 data->SetObjectTemplate(&g_wrapper_info, templ); | 176 data->SetObjectTemplate(&g_wrapper_info, templ); |
176 } | 177 } |
177 | 178 |
178 return templ; | 179 return templ; |
179 } | 180 } |
180 | 181 |
181 } // namespace js | 182 } // namespace js |
182 } // namespace mojo | 183 } // namespace mojo |
OLD | NEW |