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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/tonic/dart_converter.h
diff --git a/sky/engine/tonic/dart_converter.h b/sky/engine/tonic/dart_converter.h
index 055a82b7efa3e5f1203147a6245cda59570658f3..b27c8b8952921c385df3bea79594b5b8d18a2801 100644
--- a/sky/engine/tonic/dart_converter.h
+++ b/sky/engine/tonic/dart_converter.h
@@ -77,7 +77,7 @@ struct DartConverterInteger {
static T FromDart(Dart_Handle handle) {
int64_t result = 0;
Dart_IntegerToInt64(handle, &result);
- return result;
+ return static_cast<T>(result);
}
static T FromArguments(Dart_NativeArguments args,
@@ -85,7 +85,7 @@ struct DartConverterInteger {
Dart_Handle& exception) {
int64_t result = 0;
Dart_GetNativeIntegerArgument(args, index, &result);
- return result;
+ return static_cast<T>(result);
}
};
@@ -159,6 +159,24 @@ template <>
struct DartConverter<double> : public DartConverterFloatingPoint<double> {};
////////////////////////////////////////////////////////////////////////////////
+// Enums
+
+template <typename T>
+struct DartConverterEnum {
+ static T FromArguments(Dart_NativeArguments args,
+ int index,
+ Dart_Handle& exception) {
+ Dart_Handle enum_handle = Dart_GetNativeArgument(args, index);
+ Dart_Handle index_handle =
+ Dart_GetField(enum_handle, DartState::Current()->index_handle());
+
+ uint64_t enum_index = 0;
+ Dart_IntegerToUint64(index_handle, &enum_index);
+ return static_cast<T>(enum_index);
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
// Strings
template <>
« 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