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