Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: sky/engine/tonic/dart_converter.h

Issue 1170963003: Sky: Add a DartConverterEnum and use that for all our enum needs. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: 360 no scope Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/script/dom_dart_state.cc ('k') | sky/engine/tonic/dart_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sky/engine/tonic/dart_state.h" 9 #include "sky/engine/tonic/dart_state.h"
10 #include "sky/engine/tonic/dart_string.h" 10 #include "sky/engine/tonic/dart_string.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 struct DartConverterInteger { 70 struct DartConverterInteger {
71 static Dart_Handle ToDart(T val) { return Dart_NewInteger(val); } 71 static Dart_Handle ToDart(T val) { return Dart_NewInteger(val); }
72 72
73 static void SetReturnValue(Dart_NativeArguments args, T val) { 73 static void SetReturnValue(Dart_NativeArguments args, T val) {
74 Dart_SetIntegerReturnValue(args, val); 74 Dart_SetIntegerReturnValue(args, val);
75 } 75 }
76 76
77 static T FromDart(Dart_Handle handle) { 77 static T FromDart(Dart_Handle handle) {
78 int64_t result = 0; 78 int64_t result = 0;
79 Dart_IntegerToInt64(handle, &result); 79 Dart_IntegerToInt64(handle, &result);
80 return result; 80 return static_cast<T>(result);
81 } 81 }
82 82
83 static T FromArguments(Dart_NativeArguments args, 83 static T FromArguments(Dart_NativeArguments args,
84 int index, 84 int index,
85 Dart_Handle& exception) { 85 Dart_Handle& exception) {
86 int64_t result = 0; 86 int64_t result = 0;
87 Dart_GetNativeIntegerArgument(args, index, &result); 87 Dart_GetNativeIntegerArgument(args, index, &result);
88 return result; 88 return static_cast<T>(result);
89 } 89 }
90 }; 90 };
91 91
92 template <> 92 template <>
93 struct DartConverter<int> : public DartConverterInteger<int> {}; 93 struct DartConverter<int> : public DartConverterInteger<int> {};
94 94
95 template <> 95 template <>
96 struct DartConverter<unsigned> : public DartConverterInteger<unsigned> {}; 96 struct DartConverter<unsigned> : public DartConverterInteger<unsigned> {};
97 97
98 template <> 98 template <>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 }; 153 };
154 154
155 template <> 155 template <>
156 struct DartConverter<float> : public DartConverterFloatingPoint<float> {}; 156 struct DartConverter<float> : public DartConverterFloatingPoint<float> {};
157 157
158 template <> 158 template <>
159 struct DartConverter<double> : public DartConverterFloatingPoint<double> {}; 159 struct DartConverter<double> : public DartConverterFloatingPoint<double> {};
160 160
161 //////////////////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////////////////
162 // Enums
163
164 template <typename T>
165 struct DartConverterEnum {
166 static T FromArguments(Dart_NativeArguments args,
167 int index,
168 Dart_Handle& exception) {
169 Dart_Handle enum_handle = Dart_GetNativeArgument(args, index);
170 Dart_Handle index_handle =
171 Dart_GetField(enum_handle, DartState::Current()->index_handle());
172
173 uint64_t enum_index = 0;
174 Dart_IntegerToUint64(index_handle, &enum_index);
175 return static_cast<T>(enum_index);
176 }
177 };
178
179 ////////////////////////////////////////////////////////////////////////////////
162 // Strings 180 // Strings
163 181
164 template <> 182 template <>
165 struct DartConverter<String> { 183 struct DartConverter<String> {
166 static Dart_Handle ToDart(DartState* state, const String& val) { 184 static Dart_Handle ToDart(DartState* state, const String& val) {
167 if (val.isEmpty()) 185 if (val.isEmpty())
168 return Dart_EmptyString(); 186 return Dart_EmptyString();
169 return Dart_HandleFromWeakPersistent(state->string_cache().Get(val.impl())); 187 return Dart_HandleFromWeakPersistent(state->string_cache().Get(val.impl()));
170 } 188 }
171 189
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 374
357 375
358 // Alias Dart_NewStringFromCString for less typing. 376 // Alias Dart_NewStringFromCString for less typing.
359 inline Dart_Handle ToDart(const char* val) { 377 inline Dart_Handle ToDart(const char* val) {
360 return Dart_NewStringFromCString(val); 378 return Dart_NewStringFromCString(val);
361 } 379 }
362 380
363 } // namespace blink 381 } // namespace blink
364 382
365 #endif // SKY_ENGINE_TONIC_DART_CONVERTER_H_ 383 #endif // SKY_ENGINE_TONIC_DART_CONVERTER_H_
OLDNEW
« no previous file with comments | « sky/engine/core/script/dom_dart_state.cc ('k') | sky/engine/tonic/dart_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698