Chromium Code Reviews| Index: Source/WebCore/bindings/dart/DartUtilities.h |
| diff --git a/Source/WebCore/bindings/dart/DartUtilities.h b/Source/WebCore/bindings/dart/DartUtilities.h |
| index 1328c49e33da85f0480d214980e2e9b385e6f5c8..5c10ce8c42f4dccbadcce3d1a2171f90e1f05ed6 100644 |
| --- a/Source/WebCore/bindings/dart/DartUtilities.h |
| +++ b/Source/WebCore/bindings/dart/DartUtilities.h |
| @@ -69,6 +69,89 @@ public: |
| static Dart_Handle stringToDartString(const String&); |
| static Dart_Handle stringToDartString(const AtomicString&); |
| + template <class Element> |
| + static Dart_Handle vectorToDartList(const Vector<RefPtr<Element> >& vector) |
| + { |
| + Dart_Handle list = Dart_NewList(vector.size()); |
| + if (Dart_IsError(list)) { |
|
antonm
2012/01/18 15:12:23
nit: single line bodies are not put into {} in Web
Nikolay
2012/01/19 13:27:34
Done.
|
| + return list; |
| + } |
| + for (size_t i = 0; i < vector.size(); i++) { |
| + Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i].get())); |
| + if (Dart_IsError(result)) |
| + return result; |
|
antonm
2012/01/18 15:12:23
nit: indent (last nit regarding webkit-style)
Nikolay
2012/01/19 13:27:34
Done.
|
| + } |
| + return list; |
| + } |
| + |
| + template <class Element> |
| + static Dart_Handle vectorToDartList(const Vector<Element >& vector) |
| + { |
| + // FIXME: create list from vector for primitive types |
| + // without element-by-element copying and conversion. |
| + // Need VM support. |
| + Dart_Handle list = Dart_NewList(vector.size()); |
| + if (Dart_IsError(list)) |
| + return list; |
| + |
| + for (size_t i = 0; i < vector.size(); i++) { |
| + Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i])); |
| + if (Dart_IsError(result)) |
| + return result; |
| + } |
| + return list; |
| + } |
| + |
| + template <class Element> |
| + static void dartListToVector(Dart_Handle list, Vector<Element>& array, Dart_Handle& exception) |
| + { |
| + array.clear(); |
|
antonm
2012/01/18 15:12:23
ASSERT(array.isEmpty())?
Nikolay
2012/01/19 13:27:34
Done.
|
| + if (!Dart_IsList(list)) { |
| + exception = Dart_NewString("Argument is not a list"); |
| + return; |
| + } |
| + // FIXME: create vector from list for primitive types |
| + // without element-by-element copying and conversion. |
| + // Need VM support. |
| + intptr_t length = 0; |
| + Dart_Handle result; |
| + result = Dart_ListLength(list, &length); |
| + if (!checkResult(result, exception)) { |
| + return; |
| + } |
| + |
| + array.resize(length); |
| + for (intptr_t i = 0; i < length; i++) { |
| + Dart_Handle element = Dart_ListGetAt(list, i); |
| + if (!checkResult(element, exception)) |
| + return; |
| + array[i] = toNative<Element>(element); |
| + } |
| + } |
| + |
| + static Dart_Handle errorToException(Dart_Handle error) |
| + { |
| + ASSERT(Dart_IsError(error)); |
| + if (Dart_ErrorHasException(error)) |
| + return Dart_ErrorGetException(error); |
| + else |
| + return Dart_NewString(Dart_GetError(error)); |
| + } |
| + |
| + static bool checkResult(Dart_Handle result, Dart_Handle& exception) |
| + { |
| + if (!Dart_IsError(result)) |
| + return true; |
| + |
| + exception = errorToException(result); |
| + return false; |
| + } |
| + |
| + // If no correct converter for certain type provided - we'll know |
| + // on the linking phase. |
| + template <class Element> |
| + static Element toNative(Dart_Handle); |
| + |
| static int64_t toInteger(Dart_Handle object, Dart_Handle& exception); |
| static int64_t toInteger(Dart_Handle object); |
| static double toDouble(Dart_Handle object, Dart_Handle& exception); |