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

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: 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)
74 {
75 Dart_Handle list = Dart_NewList(vector.size());
76 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.
77 return list;
78 }
79 for (size_t i = 0; i < vector.size(); i++) {
80 Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i].g et()));
81 if (Dart_IsError(result))
82 return result;
antonm 2012/01/18 15:12:23 nit: indent (last nit regarding webkit-style)
Nikolay 2012/01/19 13:27:34 Done.
83 }
84 return list;
85 }
86
87 template <class Element>
88 static Dart_Handle vectorToDartList(const Vector<Element >& vector)
89 {
90 // FIXME: create list from vector for primitive types
91 // without element-by-element copying and conversion.
92 // Need VM support.
93 Dart_Handle list = Dart_NewList(vector.size());
94 if (Dart_IsError(list))
95 return list;
96
97 for (size_t i = 0; i < vector.size(); i++) {
98 Dart_Handle result = Dart_ListSetAt(list, i, toDartValue(vector[i])) ;
99 if (Dart_IsError(result))
100 return result;
101 }
102 return list;
103 }
104
105 template <class Element>
106 static void dartListToVector(Dart_Handle list, Vector<Element>& array, Dart_ Handle& exception)
107 {
108 array.clear();
antonm 2012/01/18 15:12:23 ASSERT(array.isEmpty())?
Nikolay 2012/01/19 13:27:34 Done.
109 if (!Dart_IsList(list)) {
110 exception = Dart_NewString("Argument is not a list");
111 return;
112 }
113 // FIXME: create vector from list for primitive types
114 // without element-by-element copying and conversion.
115 // Need VM support.
116 intptr_t length = 0;
117 Dart_Handle result;
118 result = Dart_ListLength(list, &length);
119 if (!checkResult(result, exception)) {
120 return;
121 }
122
123 array.resize(length);
124 for (intptr_t i = 0; i < length; i++) {
125 Dart_Handle element = Dart_ListGetAt(list, i);
126 if (!checkResult(element, exception))
127 return;
128 array[i] = toNative<Element>(element);
129 }
130 }
131
132 static Dart_Handle errorToException(Dart_Handle error)
133 {
134 ASSERT(Dart_IsError(error));
135 if (Dart_ErrorHasException(error))
136 return Dart_ErrorGetException(error);
137 else
138 return Dart_NewString(Dart_GetError(error));
139 }
140
141 static bool checkResult(Dart_Handle result, Dart_Handle& exception)
142 {
143 if (!Dart_IsError(result))
144 return true;
145
146 exception = errorToException(result);
147 return false;
148 }
149
150 // If no correct converter for certain type provided - we'll know
151 // on the linking phase.
152 template <class Element>
153 static Element toNative(Dart_Handle);
154
72 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception); 155 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception);
73 static int64_t toInteger(Dart_Handle object); 156 static int64_t toInteger(Dart_Handle object);
74 static double toDouble(Dart_Handle object, Dart_Handle& exception); 157 static double toDouble(Dart_Handle object, Dart_Handle& exception);
75 static double toDouble(Dart_Handle object); 158 static double toDouble(Dart_Handle object);
76 static bool toBool(Dart_Handle object, Dart_Handle& exception); 159 static bool toBool(Dart_Handle object, Dart_Handle& exception);
77 static bool toBool(Dart_Handle object); 160 static bool toBool(Dart_Handle object);
78 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception); 161 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception);
79 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception); 162 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception);
80 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception); 163 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception);
81 164
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 public: 228 public:
146 DartApiScope() { Dart_EnterScope(); } 229 DartApiScope() { Dart_EnterScope(); }
147 ~DartApiScope() { Dart_ExitScope(); } 230 ~DartApiScope() { Dart_ExitScope(); }
148 }; 231 };
149 232
150 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception()); 233 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception());
151 234
152 } // namespace WebCore 235 } // namespace WebCore
153 236
154 #endif // DartUtilities_h 237 #endif // DartUtilities_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698