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

Unified Diff: Source/WebCore/bindings/dart/DartUtilities.h

Issue 9231022: WebGL support. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Review feedback. Created 8 years, 11 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
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..fe4f0d47e26b0b88bb21add2e5cc8d4368dc1b25 100644
--- a/Source/WebCore/bindings/dart/DartUtilities.h
+++ b/Source/WebCore/bindings/dart/DartUtilities.h
@@ -69,6 +69,85 @@ 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)
antonm 2012/01/19 14:05:49 nit: please, Vector< RefPtr<Element> >
Nikolay 2012/01/19 15:08:46 Done.
+ {
+ 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;
antonm 2012/01/19 14:05:49 nit: indent, didn't check-style catch it?
Nikolay 2012/01/19 15:08:46 Nope. On 2012/01/19 14:05:49, antonm wrote:
+ }
+ return list;
+ }
+
+ template <class Element>
+ static Dart_Handle vectorToDartList(const Vector<Element >& vector)
antonm 2012/01/19 14:05:49 nit: please, Vector<Element>
Nikolay 2012/01/19 15:08:46 Done.
+ {
+ // 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);
+ }
+ }
+
+ 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);
+
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);

Powered by Google App Engine
This is Rietveld 408576698