Index: Source/bindings/core/v8/Dictionary.h |
diff --git a/Source/bindings/core/v8/Dictionary.h b/Source/bindings/core/v8/Dictionary.h |
index 6069bb90b5cbfe75c05773bc9be36905d37fe13b..baf2f769610df29fef04584f2850dd633a7652c7 100644 |
--- a/Source/bindings/core/v8/Dictionary.h |
+++ b/Source/bindings/core/v8/Dictionary.h |
@@ -43,23 +43,8 @@ |
namespace WebCore { |
-class ArrayValue; |
-class DOMError; |
class Element; |
-class LocalDOMWindow; |
-class Gamepad; |
-class MediaStream; |
-class Headers; |
-class IDBKeyRange; |
-class MIDIPort; |
-class MediaKeyError; |
-class Notification; |
class Path2D; |
-class SpeechRecognitionResult; |
-class SpeechRecognitionResultList; |
-class Storage; |
-class TrackBase; |
-class VoidCallback; |
class Dictionary { |
ALLOW_ONLY_INLINE_ALLOCATION(); |
@@ -78,38 +63,8 @@ public: |
bool isObject() const; |
bool isUndefinedOrNull() const; |
- bool get(const String&, bool&) const; |
- bool get(const String&, int32_t&) const; |
- bool get(const String&, double&, bool& hasValue) const; |
- bool get(const String&, double&) const; |
- bool get(const String&, String&) const; |
- bool get(const String&, AtomicString&) const; |
- bool get(const String&, ScriptValue&) const; |
- bool get(const String&, short&) const; |
- bool get(const String&, unsigned short&) const; |
- bool get(const String&, unsigned&) const; |
- bool get(const String&, unsigned long&) const; |
- bool get(const String&, unsigned long long&) const; |
- bool get(const String&, RefPtrWillBeMember<LocalDOMWindow>&) const; |
- bool get(const String&, RefPtrWillBeMember<Storage>&) const; |
- bool get(const String&, MessagePortArray&) const; |
- bool get(const String&, RefPtr<Uint8Array>&) const; |
- bool get(const String&, RefPtr<ArrayBufferView>&) const; |
- bool get(const String&, Member<MIDIPort>&) const; |
- bool get(const String&, RefPtrWillBeMember<MediaKeyError>&) const; |
- bool get(const String&, RefPtrWillBeMember<TrackBase>&) const; |
- bool get(const String&, Member<SpeechRecognitionResult>&) const; |
- bool get(const String&, Member<SpeechRecognitionResultList>&) const; |
- bool get(const String&, Member<Gamepad>&) const; |
- bool get(const String&, Member<MediaStream>&) const; |
- bool get(const String&, RefPtrWillBeMember<EventTarget>&) const; |
- bool get(const String&, HashSet<AtomicString>&) const; |
bool get(const String&, Dictionary&) const; |
- bool get(const String&, Vector<String>&) const; |
- bool get(const String&, ArrayValue&) const; |
- bool get(const String&, RefPtrWillBeMember<DOMError>&) const; |
bool get(const String&, v8::Local<v8::Value>&) const; |
- bool get(const String&, RefPtr<Headers>&) const; |
// Sets properties using default attributes. |
bool set(const String&, const v8::Handle<v8::Value>&); |
@@ -166,26 +121,7 @@ public: |
ConversionContext& m_context; |
}; |
- bool convert(ConversionContext&, const String&, bool&) const; |
- bool convert(ConversionContext&, const String&, double&) const; |
- bool convert(ConversionContext&, const String&, String&) const; |
- bool convert(ConversionContext&, const String&, ScriptValue&) const; |
- |
- template<typename IntegralType> |
- bool convert(ConversionContext&, const String&, IntegralType&) const; |
- template<typename IntegralType> |
- bool convert(ConversionContext&, const String&, Nullable<IntegralType>&) const; |
- |
- bool convert(ConversionContext&, const String&, MessagePortArray&) const; |
- bool convert(ConversionContext&, const String&, HashSet<AtomicString>&) const; |
bool convert(ConversionContext&, const String&, Dictionary&) const; |
- bool convert(ConversionContext&, const String&, Vector<String>&) const; |
- bool convert(ConversionContext&, const String&, ArrayValue&) const; |
- template<template <typename> class PointerType, typename T> |
- bool convert(ConversionContext&, const String&, PointerType<T>&) const; |
- |
- template<typename StringType> |
- bool getStringType(const String&, StringType&) const; |
bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; |
bool getOwnPropertyNames(Vector<String>&) const; |
@@ -196,6 +132,8 @@ public: |
bool hasProperty(const String&) const; |
+ v8::Isolate* isolate() const { return m_isolate; } |
+ |
private: |
bool getKey(const String& key, v8::Local<v8::Value>&) const; |
@@ -211,156 +149,23 @@ struct NativeValueTraits<Dictionary> { |
} |
}; |
-template <typename T> |
-struct IntegralTypeTraits { |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<uint8_t> { |
- static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toUInt8(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "UInt8"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<int8_t> { |
- static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toInt8(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "Int8"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<unsigned short> { |
- static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toUInt16(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "UInt16"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<short> { |
- static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toInt16(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "Int16"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<unsigned> { |
- static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toUInt32(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "UInt32"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<unsigned long> { |
- static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toUInt32(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "UInt32"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<int> { |
- static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toInt32(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "Int32"; } |
+// DictionaryHelper is a collection of static methods for getting or |
+// converting a value from Dictionary. |
+struct DictionaryHelper { |
+ template <typename T> |
+ static bool get(const Dictionary&, const String& key, T& value); |
+ template <typename T> |
+ static bool get(const Dictionary&, const String& key, T& value, bool& hasValue); |
+ template <template <typename> class PointerType, typename T> |
+ static bool get(const Dictionary&, const String& key, PointerType<T>& value); |
+ template <typename T> |
+ static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, T& value); |
+ template <typename T> |
+ static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, Nullable<T>& value); |
+ template <template <typename> class PointerType, typename T> |
+ static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, PointerType<T>& value); |
}; |
-template <> |
-struct IntegralTypeTraits<long> { |
- static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toInt32(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "Int32"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<unsigned long long> { |
- static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toUInt64(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "UInt64"; } |
-}; |
- |
-template <> |
-struct IntegralTypeTraits<long long> { |
- static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) |
- { |
- return toInt64(value, configuration, exceptionState); |
- } |
- static const String typeName() { return "Int64"; } |
-}; |
- |
-template<typename T> bool Dictionary::convert(ConversionContext& context, const String& key, T& value) const |
-{ |
- ConversionContextScope scope(context); |
- |
- v8::Local<v8::Value> v8Value; |
- if (!getKey(key, v8Value)) |
- return true; |
- |
- value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context.exceptionState()); |
- if (context.exceptionState().throwIfNeeded()) |
- return false; |
- |
- return true; |
-} |
- |
-template<typename T> bool Dictionary::convert(ConversionContext& context, const String& key, Nullable<T>& value) const |
-{ |
- ConversionContextScope scope(context); |
- |
- v8::Local<v8::Value> v8Value; |
- if (!getKey(key, v8Value)) |
- return true; |
- |
- if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) { |
- value = Nullable<T>(); |
- return true; |
- } |
- |
- T converted = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context.exceptionState()); |
- |
- if (context.exceptionState().throwIfNeeded()) |
- return false; |
- |
- value = Nullable<T>(converted); |
- return true; |
-} |
- |
-template<template <typename> class PointerType, typename T> bool Dictionary::convert(ConversionContext& context, const String& key, PointerType<T>& value) const |
-{ |
- ConversionContextScope scope(context); |
- |
- if (!get(key, value)) |
- return true; |
- |
- if (value) |
- return true; |
- |
- v8::Local<v8::Value> v8Value; |
- getKey(key, v8Value); |
- if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) |
- return true; |
- |
- context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does not have a " + context.typeName() + " type.")); |
- return false; |
-} |
- |
} |
#endif // Dictionary_h |