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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011, Google Inc. 1 // Copyright 2011, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 static String dartStringToString(Dart_Handle object) 62 static String dartStringToString(Dart_Handle object)
63 { 63 {
64 Dart_Handle exception = 0; 64 Dart_Handle exception = 0;
65 RefPtr<StringImpl> impl = toStringImpl(object, ConvertNone, exception); 65 RefPtr<StringImpl> impl = toStringImpl(object, ConvertNone, exception);
66 ASSERT(!exception); 66 ASSERT(!exception);
67 return String(impl.release()); 67 return String(impl.release());
68 } 68 }
69 static Dart_Handle stringToDartString(const String&); 69 static Dart_Handle stringToDartString(const String&);
70 static Dart_Handle stringToDartString(const AtomicString&); 70 static Dart_Handle stringToDartString(const AtomicString&);
71 71
72 template <class Element>
73 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.
74 {
75 Dart_Handle list = Dart_NewList(vector.size());
76 if (Dart_IsError(list))
77 return list;
78 for (size_t i = 0; i < vector.size(); i++) {
79 Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i].g et()));
80 if (Dart_IsError(result))
81 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:
82 }
83 return list;
84 }
85
86 template <class Element>
87 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.
88 {
89 // FIXME: create list from vector for primitive types
90 // without element-by-element copying and conversion.
91 // Need VM support.
92 Dart_Handle list = Dart_NewList(vector.size());
93 if (Dart_IsError(list))
94 return list;
95
96 for (size_t i = 0; i < vector.size(); i++) {
97 Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i])) ;
98 if (Dart_IsError(result))
99 return result;
100 }
101 return list;
102 }
103
104 template <class Element>
105 static void dartListToVector(Dart_Handle list, Vector<Element>& array, Dart_ Handle& exception)
106 {
107 ASSERT(array.isEmpty());
108 if (!Dart_IsList(list)) {
109 exception = Dart_NewString("Argument is not a list");
110 return;
111 }
112 // FIXME: create vector from list for primitive types
113 // without element-by-element copying and conversion.
114 // Need VM support.
115 intptr_t length = 0;
116 Dart_Handle result;
117 result = Dart_ListLength(list, &length);
118 if (!checkResult(result, exception))
119 return;
120 array.resize(length);
121 for (intptr_t i = 0; i < length; i++) {
122 Dart_Handle element = Dart_ListGetAt(list, i);
123 if (!checkResult(element, exception))
124 return;
125 array[i] = toNative<Element>(element);
126 }
127 }
128
129 static Dart_Handle errorToException(Dart_Handle error)
130 {
131 ASSERT(Dart_IsError(error));
132 if (Dart_ErrorHasException(error))
133 return Dart_ErrorGetException(error);
134 return Dart_NewString(Dart_GetError(error));
135 }
136
137 static bool checkResult(Dart_Handle result, Dart_Handle& exception)
138 {
139 if (!Dart_IsError(result))
140 return true;
141
142 exception = errorToException(result);
143 return false;
144 }
145
146 // If no correct converter for certain type provided - we'll know
147 // on the linking phase.
148 template <class Element>
149 static Element toNative(Dart_Handle);
150
72 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception); 151 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception);
73 static int64_t toInteger(Dart_Handle object); 152 static int64_t toInteger(Dart_Handle object);
74 static double toDouble(Dart_Handle object, Dart_Handle& exception); 153 static double toDouble(Dart_Handle object, Dart_Handle& exception);
75 static double toDouble(Dart_Handle object); 154 static double toDouble(Dart_Handle object);
76 static bool toBool(Dart_Handle object, Dart_Handle& exception); 155 static bool toBool(Dart_Handle object, Dart_Handle& exception);
77 static bool toBool(Dart_Handle object); 156 static bool toBool(Dart_Handle object);
78 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception); 157 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception);
79 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception); 158 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception);
80 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception); 159 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception);
81 160
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 public: 224 public:
146 DartApiScope() { Dart_EnterScope(); } 225 DartApiScope() { Dart_EnterScope(); }
147 ~DartApiScope() { Dart_ExitScope(); } 226 ~DartApiScope() { Dart_ExitScope(); }
148 }; 227 };
149 228
150 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception()); 229 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception());
151 230
152 } // namespace WebCore 231 } // namespace WebCore
153 232
154 #endif // DartUtilities_h 233 #endif // DartUtilities_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698