| 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..ceddb6832482cd92f7c7a8924c795c8ef4ff9489 100644
|
| --- a/Source/WebCore/bindings/dart/DartUtilities.h
|
| +++ b/Source/WebCore/bindings/dart/DartUtilities.h
|
| @@ -69,12 +69,90 @@ 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))
|
| + 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;
|
| + }
|
| + 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)
|
| + {
|
| + ASSERT(array.isEmpty());
|
| + 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, exception);
|
| + if (exception)
|
| + return;
|
| + }
|
| + }
|
| +
|
| + static Dart_Handle errorToException(Dart_Handle error)
|
| + {
|
| + ASSERT(Dart_IsError(error));
|
| + if (Dart_ErrorHasException(error))
|
| + return Dart_ErrorGetException(error);
|
| + 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, Dart_Handle& exception);
|
| +
|
| 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);
|
| - static double toDouble(Dart_Handle object);
|
| static bool toBool(Dart_Handle object, Dart_Handle& exception);
|
| - static bool toBool(Dart_Handle object);
|
| static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Handle& exception);
|
| static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle& exception);
|
| static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_Handle& exception);
|
|
|