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

Side by Side Diff: Source/WebCore/bindings/dart/DartUtilities.cpp

Issue 9231022: WebGL support. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Review 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 struct IntegerTrait { 120 struct IntegerTrait {
121 typedef int64_t nativeType; 121 typedef int64_t nativeType;
122 static Dart_Handle convert(Dart_Handle object, int64_t* value) 122 static Dart_Handle convert(Dart_Handle object, int64_t* value)
123 { 123 {
124 return Dart_IntegerToInt64(object, value); 124 return Dart_IntegerToInt64(object, value);
125 // FIXME: support bigints. 125 // FIXME: support bigints.
126 } 126 }
127 }; 127 };
128 128
129 template <>
130 double DartUtilities::toNative<double>(Dart_Handle object, Dart_Handle& exceptio n)
antonm 2012/01/19 15:33:13 why not ParameterAdapter?
Nikolay 2012/01/20 11:38:37 Because it's not a parameter, and I wanted more ex
131 {
132 return DartUtilities::toDouble(object, exception);
133 }
134
135 template <>
136 float DartUtilities::toNative<float>(Dart_Handle object, Dart_Handle& exception)
137 {
138 return DartUtilities::toDouble(object, exception);
139 }
140
141 template <>
142 int8_t DartUtilities::toNative<int8_t>(Dart_Handle object, Dart_Handle& exceptio n)
143 {
144 return DartUtilities::toInteger(object, exception);
145 }
146
147 template <>
148 int16_t DartUtilities::toNative<int16_t>(Dart_Handle object, Dart_Handle& except ion)
149 {
150 return DartUtilities::toInteger(object, exception);
151 }
152
153 template <>
154 int32_t DartUtilities::toNative<int32_t>(Dart_Handle object, Dart_Handle& except ion)
155 {
156 return DartUtilities::toInteger(object, exception);
157 }
158
159 template <>
160 int64_t DartUtilities::toNative<int64_t>(Dart_Handle object, Dart_Handle& except ion)
161 {
162 return DartUtilities::toInteger(object, exception);
163 }
164
165 template <>
166 uint8_t DartUtilities::toNative<uint8_t>(Dart_Handle object, Dart_Handle& except ion)
167 {
168 return DartUtilities::toInteger(object, exception);
169 }
170
171 template <>
172 uint16_t DartUtilities::toNative<uint16_t>(Dart_Handle object, Dart_Handle& exce ption)
173 {
174 return DartUtilities::toInteger(object, exception);
175 }
176
177 template <>
178 uint32_t DartUtilities::toNative<uint32_t>(Dart_Handle object, Dart_Handle& exce ption)
179 {
180 return DartUtilities::toInteger(object, exception);
181 }
182
129 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) 183 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception)
130 { 184 {
131 return convert<IntegerTrait>(object, exception); 185 return convert<IntegerTrait>(object, exception);
132 } 186 }
133 187
134 int64_t DartUtilities::toInteger(Dart_Handle object)
135 {
136 Dart_Handle exception = 0;
137 int64_t value = DartUtilities::toInteger(object, exception);
138 ASSERT(!exception);
139 return value;
140 }
141
142 struct DoubleTrait { 188 struct DoubleTrait {
143 typedef double nativeType; 189 typedef double nativeType;
144 static Dart_Handle convert(Dart_Handle object, double* value) 190 static Dart_Handle convert(Dart_Handle object, double* value)
145 { 191 {
146 if (!Dart_IsNumber(object)) 192 if (!Dart_IsNumber(object))
147 return Dart_Error("the object !is Number"); 193 return Dart_Error("the object !is Number");
148 194
149 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0); 195 if (!Dart_IsDouble(object)) {
150 if (Dart_IsError(object)) 196 object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0 );
151 return object; 197 if (Dart_IsError(object))
198 return object;
199 }
152 200
153 return Dart_DoubleValue(object, value); 201 return Dart_DoubleValue(object, value);
154 } 202 }
155 }; 203 };
156 204
157 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception) 205 double DartUtilities::toDouble(Dart_Handle object, Dart_Handle& exception)
158 { 206 {
159 return convert<DoubleTrait>(object, exception); 207 return convert<DoubleTrait>(object, exception);
160 } 208 }
161 209
162 double DartUtilities::toDouble(Dart_Handle object)
163 {
164 Dart_Handle exception = 0;
165 double value = DartUtilities::toDouble(object, exception);
166 ASSERT(!exception);
167 return value;
168 }
169
170 struct BoolTrait { 210 struct BoolTrait {
171 typedef bool nativeType; 211 typedef bool nativeType;
172 static Dart_Handle convert(Dart_Handle object, bool* value) { return Dart_Bo oleanValue(object, value); } 212 static Dart_Handle convert(Dart_Handle object, bool* value) { return Dart_Bo oleanValue(object, value); }
173 }; 213 };
174 214
175 bool DartUtilities::toBool(Dart_Handle object, Dart_Handle& exception) 215 bool DartUtilities::toBool(Dart_Handle object, Dart_Handle& exception)
176 { 216 {
177 return convert<BoolTrait>(object, exception); 217 return convert<BoolTrait>(object, exception);
178 } 218 }
179 219
180 bool DartUtilities::toBool(Dart_Handle object)
181 {
182 Dart_Handle exception = 0;
183 bool value = DartUtilities::toBool(object, exception);
184 ASSERT(!exception);
185 return value;
186 }
187
188 PassRefPtr<EventListener> DartUtilities::toEventListener(Dart_Handle object, Dar t_Handle& exception) 220 PassRefPtr<EventListener> DartUtilities::toEventListener(Dart_Handle object, Dar t_Handle& exception)
189 { 221 {
190 if (Dart_IsNull(object)) { 222 if (Dart_IsNull(object)) {
191 exception = Dart_NewString("Null passed where Dart closure is expected") ; 223 exception = Dart_NewString("Null passed where Dart closure is expected") ;
192 return 0; 224 return 0;
193 } 225 }
194 226
195 if (!Dart_IsClosure(object)) { 227 if (!Dart_IsClosure(object)) {
196 exception = Dart_NewString("Not a Dart closure passed"); 228 exception = Dart_NewString("Not a Dart closure passed");
197 return 0; 229 return 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return DartNode::toNative(object, exception); 271 return DartNode::toNative(object, exception);
240 } 272 }
241 273
242 // FIXME: this function requires better testing. Currently blocking as new Messa geChannel hasn't been implemented yet. 274 // FIXME: this function requires better testing. Currently blocking as new Messa geChannel hasn't been implemented yet.
243 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port Array, Dart_Handle& exception) 275 void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port Array, Dart_Handle& exception)
244 { 276 {
245 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar yName)); 277 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar yName));
246 ASSERT(!Dart_IsError(dom)); 278 ASSERT(!Dart_IsError(dom));
247 279
248 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne wString("convertToList"), 1, &value); 280 Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_Ne wString("convertToList"), 1, &value);
249 if (Dart_IsError(asList)) { 281 if (!checkResult(asList, exception))
250 DartUtilities::reportProblem(DartUtilities::scriptExecutionContext(), as List);
251 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_E RR);
252 return; 282 return;
253 }
254 ASSERT(Dart_IsList(asList)); 283 ASSERT(Dart_IsList(asList));
255 284
256 intptr_t length = 0; 285 intptr_t length = 0;
257 Dart_ListLength(asList, &length); 286 Dart_ListLength(asList, &length);
258 portArray.resize(length); 287 portArray.resize(length);
259 for (int i = 0; i < length; i++) { 288 for (int i = 0; i < length; i++) {
260 Dart_Handle element = Dart_ListGetAt(asList, i); 289 Dart_Handle element = Dart_ListGetAt(asList, i);
261 if (Dart_IsError(element)) { 290 if (!checkResult(element, exception))
262 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA TE_ERR);
263 return; 291 return;
264 }
265 292
266 MessagePort* messagePort = DartMessagePort::toNative(element, exception) .get(); 293 MessagePort* messagePort = DartMessagePort::toNative(element, exception) .get();
267 if (exception) { 294 if (exception)
268 exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STA TE_ERR);
269 return; 295 return;
270 }
271 296
272 ASSERT(messagePort); 297 ASSERT(messagePort);
273 portArray[i] = messagePort; 298 portArray[i] = messagePort;
274 } 299 }
275 } 300 }
276 301
277 class DartDOMData { 302 class DartDOMData {
278 public: 303 public:
279 DartDOMData() 304 DartDOMData()
280 : m_scriptExecutionContext(0) 305 : m_scriptExecutionContext(0)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 errorMessage += String("\nError converting stack trace to a string: ") + Dart_GetError(stacktrace); 498 errorMessage += String("\nError converting stack trace to a string: ") + Dart_GetError(stacktrace);
474 else 499 else
475 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin gToString(stacktrace); 500 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin gToString(stacktrace);
476 } 501 }
477 502
478 if (context && context->isDocument()) 503 if (context && context->isDocument())
479 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe r, sourceFile, callStack); 504 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe r, sourceFile, callStack);
480 } 505 }
481 506
482 } 507 }
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/dart/DartUtilities.h ('k') | Source/WebCore/bindings/dart/custom/DartArrayBufferCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698