| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 resetPerPropertyContext(); | 110 resetPerPropertyContext(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 const String& interfaceName() const { return m_interfaceName; } | 113 const String& interfaceName() const { return m_interfaceName; } |
| 114 const String& methodName() const { return m_methodName; } | 114 const String& methodName() const { return m_methodName; } |
| 115 bool forConstructor() const { return m_methodName.isEmpty(); } | 115 bool forConstructor() const { return m_methodName.isEmpty(); } |
| 116 ExceptionState& exceptionState() const { return m_exceptionState; } | 116 ExceptionState& exceptionState() const { return m_exceptionState; } |
| 117 | 117 |
| 118 bool isNullable() const { return m_isNullable; } | 118 bool isNullable() const { return m_isNullable; } |
| 119 String typeName() const { return m_propertyTypeName; } | 119 String typeName() const { return m_propertyTypeName; } |
| 120 IntegerConversionConfiguration numberConversion() const { return m_numbe
rConversion; } | |
| 121 | 120 |
| 122 ConversionContext& withAttributes(bool, IntegerConversionConfiguration,
const String&); | 121 ConversionContext& setConversionType(const String&, bool); |
| 123 ConversionContext& withAttributes(bool, IntegerConversionConfiguration); | |
| 124 ConversionContext& withAttributes(bool, const String&); | |
| 125 ConversionContext& withAttributes(bool); | |
| 126 ConversionContext& withAttributes(const String&); | |
| 127 | 122 |
| 128 void throwTypeError(const String& detail); | 123 void throwTypeError(const String& detail); |
| 129 | 124 |
| 130 void resetPerPropertyContext(); | 125 void resetPerPropertyContext(); |
| 131 | 126 |
| 132 private: | 127 private: |
| 133 const String m_interfaceName; | 128 const String m_interfaceName; |
| 134 const String m_methodName; | 129 const String m_methodName; |
| 135 ExceptionState& m_exceptionState; | 130 ExceptionState& m_exceptionState; |
| 136 bool m_dirty; | 131 bool m_dirty; |
| 137 | 132 |
| 138 bool m_isNullable; | 133 bool m_isNullable; |
| 139 String m_propertyTypeName; | 134 String m_propertyTypeName; |
| 140 IntegerConversionConfiguration m_numberConversion; | |
| 141 }; | 135 }; |
| 142 | 136 |
| 143 class ConversionContextScope { | 137 class ConversionContextScope { |
| 144 public: | 138 public: |
| 145 ConversionContextScope(ConversionContext& context) | 139 ConversionContextScope(ConversionContext& context) |
| 146 : m_context(context) { } | 140 : m_context(context) { } |
| 147 ~ConversionContextScope() | 141 ~ConversionContextScope() |
| 148 { | 142 { |
| 149 m_context.resetPerPropertyContext(); | 143 m_context.resetPerPropertyContext(); |
| 150 } | 144 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 285 |
| 292 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 |
| 293 { | 287 { |
| 294 ConversionContextScope scope(context); | 288 ConversionContextScope scope(context); |
| 295 | 289 |
| 296 v8::Local<v8::Value> v8Value; | 290 v8::Local<v8::Value> v8Value; |
| 297 if (!getKey(key, v8Value)) | 291 if (!getKey(key, v8Value)) |
| 298 return true; | 292 return true; |
| 299 | 293 |
| 300 bool ok = false; | 294 bool ok = false; |
| 301 value = IntegralTypeTraits<T>::toIntegral(v8Value, context.numberConversion(
), ok); | 295 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, ok); |
| 302 if (!ok) { | 296 if (ok) |
| 303 V8TRYCATCH_RETURN(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(),
false); | 297 return true; |
| 304 if (v8Number.IsEmpty()) { | 298 |
| 305 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key,
"does not have type " + IntegralTypeTraits<T>::typeName() + ".")); | 299 V8TRYCATCH_RETURN(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), fals
e); |
| 306 } else { | 300 ASSERT(v8Number.IsEmpty()); |
| 307 ASSERT(context.numberConversion() == EnforceRange); | 301 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have type " + IntegralTypeTraits<T>::typeName() + ".")); |
| 308 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key,
"is not a finite number.")); | 302 return false; |
| 309 } | |
| 310 return false; | |
| 311 } | |
| 312 return true; | |
| 313 } | 303 } |
| 314 | 304 |
| 315 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 |
| 316 { | 306 { |
| 317 ConversionContextScope scope(context); | 307 ConversionContextScope scope(context); |
| 318 | 308 |
| 319 if (!get(key, value)) | 309 if (!get(key, value)) |
| 320 return true; | 310 return true; |
| 321 | 311 |
| 322 if (!value) { | 312 if (value) |
| 323 v8::Local<v8::Value> v8Value; | 313 return true; |
| 324 getKey(key, v8Value); | 314 |
| 325 if (!(context.isNullable() && WebCore::isUndefinedOrNull(v8Value))) { | 315 v8::Local<v8::Value> v8Value; |
| 326 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key,
"does not have " + (context.typeName().isEmpty() ? String("the expected type.")
: ("a " + context.typeName() + " type.")))); | 316 getKey(key, v8Value); |
| 327 return false; | 317 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) |
| 328 } | 318 return true; |
| 329 } | 319 |
| 330 return true; | 320 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); |
| 321 return false; |
| 331 } | 322 } |
| 332 | 323 |
| 333 } | 324 } |
| 334 | 325 |
| 335 #endif // Dictionary_h | 326 #endif // Dictionary_h |
| OLD | NEW |