| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_DICTIONARY_H_ | |
| 27 #define SKY_ENGINE_BINDINGS_CORE_V8_DICTIONARY_H_ | |
| 28 | |
| 29 #include "sky/engine/bindings/core/v8/ExceptionMessages.h" | |
| 30 #include "sky/engine/bindings/core/v8/ExceptionState.h" | |
| 31 #include "sky/engine/bindings/core/v8/Nullable.h" | |
| 32 #include "sky/engine/bindings/core/v8/ScriptValue.h" | |
| 33 #include "sky/engine/bindings/core/v8/V8Binding.h" | |
| 34 #include "sky/engine/bindings/core/v8/V8BindingMacros.h" | |
| 35 #include "sky/engine/core/events/EventListener.h" | |
| 36 #include "sky/engine/wtf/HashMap.h" | |
| 37 #include "sky/engine/wtf/HashSet.h" | |
| 38 #include "sky/engine/wtf/Vector.h" | |
| 39 #include "sky/engine/wtf/text/AtomicString.h" | |
| 40 #include "sky/engine/wtf/text/WTFString.h" | |
| 41 #include "v8/include/v8.h" | |
| 42 | |
| 43 namespace blink { | |
| 44 | |
| 45 class Element; | |
| 46 class Path2D; | |
| 47 | |
| 48 class Dictionary { | |
| 49 ALLOW_ONLY_INLINE_ALLOCATION(); | |
| 50 public: | |
| 51 Dictionary(); | |
| 52 Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate*); | |
| 53 ~Dictionary(); | |
| 54 | |
| 55 Dictionary& operator=(const Dictionary&); | |
| 56 | |
| 57 // This is different from the default constructor: | |
| 58 // * isObject() is true when using createEmpty(). | |
| 59 // * isUndefinedOrNull() is true when using default constructor. | |
| 60 static Dictionary createEmpty(v8::Isolate*); | |
| 61 | |
| 62 bool isObject() const; | |
| 63 bool isUndefinedOrNull() const; | |
| 64 | |
| 65 bool get(const String&, Dictionary&) const; | |
| 66 bool get(const String&, v8::Local<v8::Value>&) const; | |
| 67 | |
| 68 // Sets properties using default attributes. | |
| 69 bool set(const String&, const v8::Handle<v8::Value>&); | |
| 70 bool set(const String&, const String&); | |
| 71 bool set(const String&, unsigned); | |
| 72 bool set(const String&, const Dictionary&); | |
| 73 | |
| 74 v8::Handle<v8::Value> v8Value() const { return m_options; } | |
| 75 | |
| 76 class ConversionContext { | |
| 77 public: | |
| 78 ConversionContext(const String& interfaceName, const String& methodName,
ExceptionState& exceptionState) | |
| 79 : m_interfaceName(interfaceName) | |
| 80 , m_methodName(methodName) | |
| 81 , m_exceptionState(exceptionState) | |
| 82 , m_dirty(true) | |
| 83 { | |
| 84 resetPerPropertyContext(); | |
| 85 } | |
| 86 | |
| 87 const String& interfaceName() const { return m_interfaceName; } | |
| 88 const String& methodName() const { return m_methodName; } | |
| 89 bool forConstructor() const { return m_methodName.isEmpty(); } | |
| 90 ExceptionState& exceptionState() const { return m_exceptionState; } | |
| 91 | |
| 92 bool isNullable() const { return m_isNullable; } | |
| 93 String typeName() const { return m_propertyTypeName; } | |
| 94 | |
| 95 ConversionContext& setConversionType(const String&, bool); | |
| 96 | |
| 97 void throwTypeError(const String& detail); | |
| 98 | |
| 99 void resetPerPropertyContext(); | |
| 100 | |
| 101 private: | |
| 102 const String m_interfaceName; | |
| 103 const String m_methodName; | |
| 104 ExceptionState& m_exceptionState; | |
| 105 bool m_dirty; | |
| 106 | |
| 107 bool m_isNullable; | |
| 108 String m_propertyTypeName; | |
| 109 }; | |
| 110 | |
| 111 class ConversionContextScope { | |
| 112 public: | |
| 113 ConversionContextScope(ConversionContext& context) | |
| 114 : m_context(context) { } | |
| 115 ~ConversionContextScope() | |
| 116 { | |
| 117 m_context.resetPerPropertyContext(); | |
| 118 } | |
| 119 private: | |
| 120 ConversionContext& m_context; | |
| 121 }; | |
| 122 | |
| 123 bool convert(ConversionContext&, const String&, Dictionary&) const; | |
| 124 | |
| 125 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; | |
| 126 bool getOwnPropertyNames(Vector<String>&) const; | |
| 127 | |
| 128 bool getWithUndefinedOrNullCheck(const String&, String&) const; | |
| 129 bool getWithUndefinedOrNullCheck(const String&, RefPtr<Element>&) const; | |
| 130 bool getWithUndefinedOrNullCheck(const String&, RefPtr<Path2D>&) const; | |
| 131 | |
| 132 bool hasProperty(const String&) const; | |
| 133 | |
| 134 v8::Isolate* isolate() const { return m_isolate; } | |
| 135 | |
| 136 private: | |
| 137 bool getKey(const String& key, v8::Local<v8::Value>&) const; | |
| 138 | |
| 139 v8::Handle<v8::Value> m_options; | |
| 140 v8::Isolate* m_isolate; | |
| 141 }; | |
| 142 | |
| 143 template<> | |
| 144 struct NativeValueTraits<Dictionary> { | |
| 145 static inline Dictionary nativeValue(const v8::Handle<v8::Value>& value, v8:
:Isolate* isolate) | |
| 146 { | |
| 147 return Dictionary(value, isolate); | |
| 148 } | |
| 149 }; | |
| 150 | |
| 151 // DictionaryHelper is a collection of static methods for getting or | |
| 152 // converting a value from Dictionary. | |
| 153 struct DictionaryHelper { | |
| 154 template <typename T> | |
| 155 static bool get(const Dictionary&, const String& key, T& value); | |
| 156 template <typename T> | |
| 157 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal
ue); | |
| 158 template <template <typename> class PointerType, typename T> | |
| 159 static bool get(const Dictionary&, const String& key, PointerType<T>& value)
; | |
| 160 template <typename T> | |
| 161 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const
String& key, T& value); | |
| 162 template <typename T> | |
| 163 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const
String& key, Nullable<T>& value); | |
| 164 template <template <typename> class PointerType, typename T> | |
| 165 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const
String& key, PointerType<T>& value); | |
| 166 }; | |
| 167 | |
| 168 } | |
| 169 | |
| 170 #endif // SKY_ENGINE_BINDINGS_CORE_V8_DICTIONARY_H_ | |
| OLD | NEW |