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

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: Final version. 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))
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;
82 }
83 return list;
84 }
85
86 template <class Element>
87 static Dart_Handle vectorToDartList(const Vector<Element>& vector)
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 // If no correct converter for certain type provided - we'll know
105 // on the linking phase.
106 template <class Element>
107 static Element toWebGLArrayElement(Dart_Handle, Dart_Handle& exception);
108
109 template <class Element>
110 static void dartListToVector(Dart_Handle list, Vector<Element>& array, Dart_ Handle& exception)
111 {
112 ASSERT(array.isEmpty());
113 if (!Dart_IsList(list)) {
114 exception = Dart_NewString("Argument is not a list");
115 return;
116 }
117 // FIXME: create vector from list for primitive types
118 // without element-by-element copying and conversion.
119 // Need VM support.
120 intptr_t length = 0;
121 Dart_Handle result;
122 result = Dart_ListLength(list, &length);
123 if (!checkResult(result, exception))
124 return;
125 array.resize(length);
126 for (intptr_t i = 0; i < length; i++) {
127 Dart_Handle element = Dart_ListGetAt(list, i);
128 if (!checkResult(element, exception))
129 return;
130 array[i] = toWebGLArrayElement<Element>(element, exception);
131 if (exception)
132 return;
133 }
134 }
135
136 static Dart_Handle errorToException(Dart_Handle error)
137 {
138 ASSERT(Dart_IsError(error));
139 if (Dart_ErrorHasException(error))
140 return Dart_ErrorGetException(error);
141 return Dart_NewString(Dart_GetError(error));
142 }
143
144 static bool checkResult(Dart_Handle result, Dart_Handle& exception)
145 {
146 if (!Dart_IsError(result))
147 return true;
148
149 exception = errorToException(result);
150 return false;
151 }
152
72 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception); 153 static int64_t toInteger(Dart_Handle object, Dart_Handle& exception);
73 static int64_t toInteger(Dart_Handle object);
74 static double toDouble(Dart_Handle object, Dart_Handle& exception); 154 static double toDouble(Dart_Handle object, Dart_Handle& exception);
75 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);
78 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception); 156 static PassRefPtr<EventListener> toEventListener(Dart_Handle object, Dart_Ha ndle& exception);
79 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception); 157 static PassRefPtr<EventTarget> toEventTarget(Dart_Handle object, Dart_Handle & exception);
80 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception); 158 static void toMessagePortArray(Dart_Handle object, MessagePortArray&, Dart_H andle& exception);
81 159
82 static PassRefPtr<SerializedScriptValue> toSerializedScriptValue(Dart_Handle object, Dart_Handle& exception); 160 static PassRefPtr<SerializedScriptValue> toSerializedScriptValue(Dart_Handle object, Dart_Handle& exception);
83 static Dart_Handle fromSerializedScriptValue(SerializedScriptValue*); 161 static Dart_Handle fromSerializedScriptValue(SerializedScriptValue*);
84 162
85 static void registerIsolateContext(Dart_Isolate, ScriptExecutionContext*); 163 static void registerIsolateContext(Dart_Isolate, ScriptExecutionContext*);
86 static ScriptExecutionContext* isolateContext(Dart_Isolate); 164 static ScriptExecutionContext* isolateContext(Dart_Isolate);
87 static void unregisterIsolateContext(Dart_Isolate); 165 static void unregisterIsolateContext(Dart_Isolate);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 public: 223 public:
146 DartApiScope() { Dart_EnterScope(); } 224 DartApiScope() { Dart_EnterScope(); }
147 ~DartApiScope() { Dart_ExitScope(); } 225 ~DartApiScope() { Dart_ExitScope(); }
148 }; 226 };
149 227
150 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception()); 228 #define DART_UNIMPLEMENTED() Dart_ThrowException(DartUtilities::notImplementedEx ception());
151 229
152 } // namespace WebCore 230 } // namespace WebCore
153 231
154 #endif // DartUtilities_h 232 #endif // DartUtilities_h
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/dart/DartDOMWrapper.h ('k') | Source/WebCore/bindings/dart/DartUtilities.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698