| Index: Source/bindings/core/v8/Dictionary.h
|
| diff --git a/Source/bindings/core/v8/Dictionary.h b/Source/bindings/core/v8/Dictionary.h
|
| index 573932f2c83d587d339bb7e0409fb94809438061..2623c2688f43aaecd747727427e013f3b4d3ba86 100644
|
| --- a/Source/bindings/core/v8/Dictionary.h
|
| +++ b/Source/bindings/core/v8/Dictionary.h
|
| @@ -26,119 +26,108 @@
|
| #ifndef Dictionary_h
|
| #define Dictionary_h
|
|
|
| -#include "bindings/core/v8/ExceptionMessages.h"
|
| #include "bindings/core/v8/ExceptionState.h"
|
| -#include "bindings/core/v8/Nullable.h"
|
| -#include "bindings/core/v8/ScriptValue.h"
|
| +#include "bindings/core/v8/PropertyBag.h"
|
| #include "bindings/core/v8/V8Binding.h"
|
| -#include "bindings/core/v8/V8BindingMacros.h"
|
| +#include "bindings/core/v8/V8Element.h"
|
| +#include "bindings/core/v8/V8Path2D.h"
|
| #include "core/dom/MessagePort.h"
|
| #include "core/events/EventListener.h"
|
| -#include "wtf/HashMap.h"
|
| -#include "wtf/HashSet.h"
|
| -#include "wtf/Vector.h"
|
| -#include "wtf/text/AtomicString.h"
|
| +#include "wtf/OwnPtr.h"
|
| #include "wtf/text/WTFString.h"
|
| -#include <v8.h>
|
|
|
| namespace blink {
|
|
|
| -class Element;
|
| -class Path2D;
|
| -
|
| +// NOTE: I don't intend to land this; just to show how we can remove DictionaryHelper.
|
| +// We should remove Dictionary class at all.
|
| class Dictionary {
|
| ALLOW_ONLY_INLINE_ALLOCATION();
|
| public:
|
| - Dictionary();
|
| - Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate*);
|
| - ~Dictionary();
|
| + Dictionary()
|
| + {
|
| + }
|
| +
|
| + Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate* isolate)
|
| + : m_options(options)
|
| + {
|
| + if (!m_options.IsEmpty() && m_options->IsObject()) {
|
| + v8::Handle<v8::Object> v8Object = options->ToObject();
|
| + m_propertyBag = adoptPtr(new PropertyBag(isolate, v8Object, m_exceptionState));
|
| + }
|
| + }
|
|
|
| - Dictionary& operator=(const Dictionary&);
|
| + Dictionary(const Dictionary& rhs)
|
| + {
|
| + m_options = rhs.m_options;
|
| + if (rhs.m_propertyBag)
|
| + m_propertyBag = adoptPtr(new PropertyBag(rhs.m_propertyBag->m_isolate, rhs.m_propertyBag->m_object, m_exceptionState));
|
| + }
|
|
|
| // This is different from the default constructor:
|
| // * isObject() is true when using createEmpty().
|
| // * isUndefinedOrNull() is true when using default constructor.
|
| - static Dictionary createEmpty(v8::Isolate*);
|
| -
|
| - bool isObject() const;
|
| - bool isUndefinedOrNull() const;
|
| -
|
| - bool get(const String&, Dictionary&) const;
|
| - bool get(const String&, v8::Local<v8::Value>&) const;
|
| -
|
| - // Sets properties using default attributes.
|
| - bool set(const String&, const v8::Handle<v8::Value>&);
|
| - bool set(const String&, const String&);
|
| - bool set(const String&, unsigned);
|
| - bool set(const String&, const Dictionary&);
|
| -
|
| - v8::Handle<v8::Value> v8Value() const { return m_options; }
|
| -
|
| - class ConversionContext {
|
| - public:
|
| - ConversionContext(const String& interfaceName, const String& methodName, ExceptionState& exceptionState)
|
| - : m_interfaceName(interfaceName)
|
| - , m_methodName(methodName)
|
| - , m_exceptionState(exceptionState)
|
| - , m_dirty(true)
|
| - {
|
| - resetPerPropertyContext();
|
| - }
|
| -
|
| - const String& interfaceName() const { return m_interfaceName; }
|
| - const String& methodName() const { return m_methodName; }
|
| - bool forConstructor() const { return m_methodName.isEmpty(); }
|
| - ExceptionState& exceptionState() const { return m_exceptionState; }
|
| + static Dictionary createEmpty(v8::Isolate* isolate)
|
| + {
|
| + return Dictionary(v8::Object::New(isolate), isolate);
|
| + }
|
|
|
| - bool isNullable() const { return m_isNullable; }
|
| - String typeName() const { return m_propertyTypeName; }
|
| + ~Dictionary() { }
|
|
|
| - ConversionContext& setConversionType(const String&, bool);
|
| + Dictionary& operator=(const Dictionary& rhs)
|
| + {
|
| + m_options = rhs.m_options;
|
| + if (rhs.m_propertyBag)
|
| + m_propertyBag = adoptPtr(new PropertyBag(rhs.m_propertyBag->m_isolate, rhs.m_propertyBag->m_object, m_exceptionState));
|
| + else
|
| + m_propertyBag.clear();
|
| + return *this;
|
| + }
|
|
|
| - void throwTypeError(const String& detail);
|
| + bool isObject() const
|
| + {
|
| + return !m_options.IsEmpty() && m_options->IsObject();
|
| + }
|
|
|
| - void resetPerPropertyContext();
|
| + bool isUndefinedOrNull() const
|
| + {
|
| + return m_options.IsEmpty() || blink::isUndefinedOrNull(m_options);
|
| + }
|
|
|
| - private:
|
| - const String m_interfaceName;
|
| - const String m_methodName;
|
| - ExceptionState& m_exceptionState;
|
| - bool m_dirty;
|
| + template <typename T>
|
| + bool get(const String& key, T& value) const { return m_propertyBag && m_propertyBag->get(key, value, PropertyBag::IsNotNullable); }
|
|
|
| - bool m_isNullable;
|
| - String m_propertyTypeName;
|
| - };
|
| + template <typename T>
|
| + bool get(const String& key, T& value, bool& hasValue) const { return m_propertyBag && m_propertyBag->get(key, value, hasValue); }
|
| + template <typename T>
|
| + bool getWithUndefinedOrNullCheck(const String& key, T& value) const { return get(key, value); }
|
|
|
| - class ConversionContextScope {
|
| - public:
|
| - ConversionContextScope(ConversionContext& context)
|
| - : m_context(context) { }
|
| - ~ConversionContextScope()
|
| - {
|
| - m_context.resetPerPropertyContext();
|
| - }
|
| - private:
|
| - ConversionContext& m_context;
|
| - };
|
| + // Sets properties using default attributes.
|
| + template <typename T>
|
| + bool set(const String& key, const T& value) { return m_propertyBag && m_propertyBag->set(key, value); }
|
|
|
| - bool convert(ConversionContext&, const String&, Dictionary&) const;
|
| + v8::Handle<v8::Value> v8Value() const
|
| + {
|
| + return m_options;
|
| + }
|
|
|
| + // FIXME: These should be gone.
|
| bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const;
|
| bool getOwnPropertyNames(Vector<String>&) const;
|
|
|
| - bool getWithUndefinedOrNullCheck(const String&, String&) const;
|
| - bool getWithUndefinedOrNullCheck(const String&, RefPtrWillBeMember<Element>&) const;
|
| - bool getWithUndefinedOrNullCheck(const String&, RefPtrWillBeMember<Path2D>&) const;
|
| -
|
| - bool hasProperty(const String&) const;
|
| -
|
| - v8::Isolate* isolate() const { return m_isolate; }
|
| + bool hasProperty(const String& key) const { return m_propertyBag && m_propertyBag->hasProperty(key); }
|
|
|
| private:
|
| - bool getKey(const String& key, v8::Local<v8::Value>&) const;
|
| -
|
| v8::Handle<v8::Value> m_options;
|
| - v8::Isolate* m_isolate;
|
| + TrackExceptionState m_exceptionState;
|
| + OwnPtr<PropertyBag> m_propertyBag;
|
| +};
|
| +
|
| +template <>
|
| +struct V8ValueTraits<Dictionary> {
|
| + static v8::Handle<v8::Value> toV8Value(const Dictionary& value, v8::Handle<v8::Object>, v8::Isolate*)
|
| + {
|
| + return value.v8Value();
|
| + }
|
| };
|
|
|
| template<>
|
| @@ -147,23 +136,13 @@ struct NativeValueTraits<Dictionary> {
|
| {
|
| return Dictionary(value, isolate);
|
| }
|
| -};
|
| -
|
| -// 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);
|
| + static inline Dictionary nativeValueMayFail(v8::Isolate* isolate, const v8::Handle<v8::Value>& value, ExceptionState& exceptionState)
|
| + {
|
| + if (value->IsObject()) {
|
| + return Dictionary(value, isolate);
|
| + }
|
| + return Dictionary();
|
| + }
|
| };
|
|
|
| }
|
|
|