OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef SKY_ENGINE_TONIC_DART_CONVERTER_H_ | 5 #ifndef SKY_ENGINE_TONIC_DART_CONVERTER_H_ |
6 #define SKY_ENGINE_TONIC_DART_CONVERTER_H_ | 6 #define SKY_ENGINE_TONIC_DART_CONVERTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "mojo/public/cpp/system/handle.h" | |
9 #include "sky/engine/tonic/dart_state.h" | 10 #include "sky/engine/tonic/dart_state.h" |
10 #include "sky/engine/tonic/dart_string.h" | 11 #include "sky/engine/tonic/dart_string.h" |
11 #include "sky/engine/tonic/dart_string_cache.h" | 12 #include "sky/engine/tonic/dart_string_cache.h" |
12 #include "sky/engine/tonic/dart_value.h" | 13 #include "sky/engine/tonic/dart_value.h" |
13 #include "sky/engine/wtf/text/StringUTF8Adaptor.h" | 14 #include "sky/engine/wtf/text/StringUTF8Adaptor.h" |
14 #include "sky/engine/wtf/text/WTFString.h" | 15 #include "sky/engine/wtf/text/WTFString.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 // DartConvert converts types back and forth from Sky to Dart. The template | 19 // DartConvert converts types back and forth from Sky to Dart. The template |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 static Vector<T> FromArguments(Dart_NativeArguments args, | 260 static Vector<T> FromArguments(Dart_NativeArguments args, |
260 int index, | 261 int index, |
261 Dart_Handle& exception, | 262 Dart_Handle& exception, |
262 bool auto_scope = true) { | 263 bool auto_scope = true) { |
263 // TODO(abarth): What should we do with auto_scope? | 264 // TODO(abarth): What should we do with auto_scope? |
264 return FromDart(Dart_GetNativeArgument(args, index)); | 265 return FromDart(Dart_GetNativeArgument(args, index)); |
265 } | 266 } |
266 }; | 267 }; |
267 | 268 |
268 //////////////////////////////////////////////////////////////////////////////// | 269 //////////////////////////////////////////////////////////////////////////////// |
270 // mojo types | |
271 | |
272 template <typename HandleType> | |
273 struct DartConverter<mojo::ScopedHandleBase<HandleType>> { | |
274 static mojo::ScopedHandleBase<HandleType> FromDart(Dart_Handle handle) { | |
275 uint64_t mojo_handle64 = 0; | |
276 Dart_Handle result = Dart_IntegerToUint64(handle, &mojo_handle64); | |
277 if (Dart_IsError(result) || !mojo_handle64) | |
278 return mojo::ScopedHandleBase<HandleType>(); | |
279 | |
280 HandleType mojo_handle(static_cast<MojoHandle>(mojo_handle64)); | |
281 return mojo::MakeScopedHandle(mojo_handle); | |
282 } | |
283 | |
284 static Dart_Handle ToDart(mojo::ScopedHandleBase<HandleType> mojo_handle) { | |
285 return Dart_NewInteger(static_cast<int64_t>(mojo_handle.release().value())); | |
286 } | |
287 }; | |
abarth-chromium
2015/02/23 22:29:37
Please move this declaration to a separate header
| |
288 | |
289 //////////////////////////////////////////////////////////////////////////////// | |
269 // DartValue | 290 // DartValue |
270 | 291 |
271 template <> | 292 template <> |
272 struct DartConverter<DartValue*> { | 293 struct DartConverter<DartValue*> { |
273 static Dart_Handle ToDart(DartState* state, DartValue* val) { | 294 static Dart_Handle ToDart(DartState* state, DartValue* val) { |
274 return val->dart_value(); | 295 return val->dart_value(); |
275 } | 296 } |
276 | 297 |
277 static void SetReturnValue(Dart_NativeArguments args, DartValue* val) { | 298 static void SetReturnValue(Dart_NativeArguments args, DartValue* val) { |
278 Dart_SetReturnValue(args, val->dart_value()); | 299 Dart_SetReturnValue(args, val->dart_value()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 356 |
336 | 357 |
337 // Alias Dart_NewStringFromCString for less typing. | 358 // Alias Dart_NewStringFromCString for less typing. |
338 inline Dart_Handle ToDart(const char* val) { | 359 inline Dart_Handle ToDart(const char* val) { |
339 return Dart_NewStringFromCString(val); | 360 return Dart_NewStringFromCString(val); |
340 } | 361 } |
341 | 362 |
342 } // namespace blink | 363 } // namespace blink |
343 | 364 |
344 #endif // SKY_ENGINE_TONIC_DART_CONVERTER_H_ | 365 #endif // SKY_ENGINE_TONIC_DART_CONVERTER_H_ |
OLD | NEW |