OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return Dictionary(value, isolate); | 192 return Dictionary(value, isolate); |
193 } | 193 } |
194 }; | 194 }; |
195 | 195 |
196 template <typename T> | 196 template <typename T> |
197 struct IntegralTypeTraits { | 197 struct IntegralTypeTraits { |
198 }; | 198 }; |
199 | 199 |
200 template <> | 200 template <> |
201 struct IntegralTypeTraits<uint8_t> { | 201 struct IntegralTypeTraits<uint8_t> { |
202 static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, bool& ok) | 202 static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
203 { | 203 { |
204 return toUInt8(value, configuration, ok); | 204 return toUInt8(value, configuration, exceptionState); |
205 } | 205 } |
206 static const String typeName() { return "UInt8"; } | 206 static const String typeName() { return "UInt8"; } |
207 }; | 207 }; |
208 | 208 |
209 template <> | 209 template <> |
210 struct IntegralTypeTraits<int8_t> { | 210 struct IntegralTypeTraits<int8_t> { |
211 static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversi
onConfiguration configuration, bool& ok) | 211 static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversi
onConfiguration configuration, ExceptionState& exceptionState) |
212 { | 212 { |
213 return toInt8(value, configuration, ok); | 213 return toInt8(value, configuration, exceptionState); |
214 } | 214 } |
215 static const String typeName() { return "Int8"; } | 215 static const String typeName() { return "Int8"; } |
216 }; | 216 }; |
217 | 217 |
218 template <> | 218 template <> |
219 struct IntegralTypeTraits<unsigned short> { | 219 struct IntegralTypeTraits<unsigned short> { |
220 static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, bool& ok) | 220 static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) |
221 { | 221 { |
222 return toUInt16(value, configuration, ok); | 222 return toUInt16(value, configuration, exceptionState); |
223 } | 223 } |
224 static const String typeName() { return "UInt16"; } | 224 static const String typeName() { return "UInt16"; } |
225 }; | 225 }; |
226 | 226 |
227 template <> | 227 template <> |
228 struct IntegralTypeTraits<short> { | 228 struct IntegralTypeTraits<short> { |
229 static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, bool& ok) | 229 static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
230 { | 230 { |
231 return toInt16(value, configuration, ok); | 231 return toInt16(value, configuration, exceptionState); |
232 } | 232 } |
233 static const String typeName() { return "Int16"; } | 233 static const String typeName() { return "Int16"; } |
234 }; | 234 }; |
235 | 235 |
236 template <> | 236 template <> |
237 struct IntegralTypeTraits<unsigned> { | 237 struct IntegralTypeTraits<unsigned> { |
238 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, bool& ok) | 238 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) |
239 { | 239 { |
240 return toUInt32(value, configuration, ok); | 240 return toUInt32(value, configuration, exceptionState); |
241 } | 241 } |
242 static const String typeName() { return "UInt32"; } | 242 static const String typeName() { return "UInt32"; } |
243 }; | 243 }; |
244 | 244 |
245 template <> | 245 template <> |
246 struct IntegralTypeTraits<unsigned long> { | 246 struct IntegralTypeTraits<unsigned long> { |
247 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, bool& ok) | 247 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) |
248 { | 248 { |
249 return toUInt32(value, configuration, ok); | 249 return toUInt32(value, configuration, exceptionState); |
250 } | 250 } |
251 static const String typeName() { return "UInt32"; } | 251 static const String typeName() { return "UInt32"; } |
252 }; | 252 }; |
253 | 253 |
254 template <> | 254 template <> |
255 struct IntegralTypeTraits<int> { | 255 struct IntegralTypeTraits<int> { |
256 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, bool& ok) | 256 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
257 { | 257 { |
258 return toInt32(value, configuration, ok); | 258 return toInt32(value, configuration, exceptionState); |
259 } | 259 } |
260 static const String typeName() { return "Int32"; } | 260 static const String typeName() { return "Int32"; } |
261 }; | 261 }; |
262 | 262 |
263 template <> | 263 template <> |
264 struct IntegralTypeTraits<long> { | 264 struct IntegralTypeTraits<long> { |
265 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, bool& ok) | 265 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
266 { | 266 { |
267 return toInt32(value, configuration, ok); | 267 return toInt32(value, configuration, exceptionState); |
268 } | 268 } |
269 static const String typeName() { return "Int32"; } | 269 static const String typeName() { return "Int32"; } |
270 }; | 270 }; |
271 | 271 |
272 template <> | 272 template <> |
273 struct IntegralTypeTraits<unsigned long long> { | 273 struct IntegralTypeTraits<unsigned long long> { |
274 static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, Int
egerConversionConfiguration configuration, bool& ok) | 274 static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, Int
egerConversionConfiguration configuration, ExceptionState& exceptionState) |
275 { | 275 { |
276 return toUInt64(value, configuration, ok); | 276 return toUInt64(value, configuration, exceptionState); |
277 } | 277 } |
278 static const String typeName() { return "UInt64"; } | 278 static const String typeName() { return "UInt64"; } |
279 }; | 279 }; |
280 | 280 |
281 template <> | 281 template <> |
282 struct IntegralTypeTraits<long long> { | 282 struct IntegralTypeTraits<long long> { |
283 static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConve
rsionConfiguration configuration, bool& ok) | 283 static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConve
rsionConfiguration configuration, ExceptionState& exceptionState) |
284 { | 284 { |
285 return toInt64(value, configuration, ok); | 285 return toInt64(value, configuration, exceptionState); |
286 } | 286 } |
287 static const String typeName() { return "Int64"; } | 287 static const String typeName() { return "Int64"; } |
288 }; | 288 }; |
289 | 289 |
290 template<typename T> bool Dictionary::convert(ConversionContext& context, const
String& key, T& value) const | 290 template<typename T> bool Dictionary::convert(ConversionContext& context, const
String& key, T& value) const |
291 { | 291 { |
292 ConversionContextScope scope(context); | 292 ConversionContextScope scope(context); |
293 | 293 |
294 v8::Local<v8::Value> v8Value; | 294 v8::Local<v8::Value> v8Value; |
295 if (!getKey(key, v8Value)) | 295 if (!getKey(key, v8Value)) |
296 return true; | 296 return true; |
297 | 297 |
298 bool ok = false; | 298 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context
.exceptionState()); |
299 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, ok); | 299 if (context.exceptionState().throwIfNeeded()) |
300 if (ok) | 300 return false; |
301 return true; | |
302 | 301 |
303 V8TRYCATCH_RETURN(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), fals
e); | 302 return true; |
304 ASSERT(v8Number.IsEmpty()); | |
305 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have type " + IntegralTypeTraits<T>::typeName() + ".")); | |
306 return false; | |
307 } | 303 } |
308 | 304 |
309 template<typename T> bool Dictionary::convert(ConversionContext& context, const
String& key, RefPtr<T>& value) const | 305 template<typename T> bool Dictionary::convert(ConversionContext& context, const
String& key, RefPtr<T>& value) const |
310 { | 306 { |
311 ConversionContextScope scope(context); | 307 ConversionContextScope scope(context); |
312 | 308 |
313 if (!get(key, value)) | 309 if (!get(key, value)) |
314 return true; | 310 return true; |
315 | 311 |
316 if (value) | 312 if (value) |
317 return true; | 313 return true; |
318 | 314 |
319 v8::Local<v8::Value> v8Value; | 315 v8::Local<v8::Value> v8Value; |
320 getKey(key, v8Value); | 316 getKey(key, v8Value); |
321 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) | 317 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) |
322 return true; | 318 return true; |
323 | 319 |
324 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); | 320 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); |
325 return false; | 321 return false; |
326 } | 322 } |
327 | 323 |
328 } | 324 } |
329 | 325 |
330 #endif // Dictionary_h | 326 #endif // Dictionary_h |
OLD | NEW |