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 10 matching lines...) Expand all Loading... |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 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 | 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. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef Dictionary_h | 26 #ifndef Dictionary_h |
27 #define Dictionary_h | 27 #define Dictionary_h |
28 | 28 |
29 #include "bindings/core/v8/DictionaryIterator.h" | 29 #include "bindings/core/v8/DictionaryIterator.h" |
30 #include "bindings/core/v8/ExceptionMessages.h" | 30 #include "bindings/core/v8/ExceptionMessages.h" |
31 #include "bindings/core/v8/ExceptionState.h" | |
32 #include "bindings/core/v8/Nullable.h" | 31 #include "bindings/core/v8/Nullable.h" |
33 #include "bindings/core/v8/ScriptValue.h" | 32 #include "bindings/core/v8/ScriptValue.h" |
34 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8BindingMacros.h" | 34 #include "bindings/core/v8/V8BindingMacros.h" |
36 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
37 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
38 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
39 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
40 #include "wtf/text/AtomicString.h" | 39 #include "wtf/text/AtomicString.h" |
41 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
42 #include <v8.h> | 41 #include <v8.h> |
43 | 42 |
44 namespace blink { | 43 namespace blink { |
45 | 44 |
| 45 class ExceptionState; |
46 class ExecutionContext; | 46 class ExecutionContext; |
47 | 47 |
48 // Dictionary class provides ways to retrieve property values as C++ objects | 48 // Dictionary class provides ways to retrieve property values as C++ objects |
49 // from a V8 object. Instances of this class must not outlive V8's handle scope | 49 // from a V8 object. Instances of this class must not outlive V8's handle scope |
50 // because they hold a V8 value without putting it on persistent handles. | 50 // because they hold a V8 value without putting it on persistent handles. |
51 class CORE_EXPORT Dictionary final { | 51 class CORE_EXPORT Dictionary final { |
52 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 52 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
53 public: | 53 public: |
54 Dictionary(); | 54 Dictionary() |
55 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate*, ExceptionState
&); | 55 : m_isolate(nullptr) { } |
56 ~Dictionary(); | 56 Dictionary(v8::Isolate* isolate, const v8::Local<v8::Value>& options) |
| 57 : m_options(options) |
| 58 , m_isolate(isolate) |
| 59 { |
| 60 DCHECK(m_isolate); |
| 61 } |
| 62 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate* isolate, Except
ionState&) // DEPRECATED |
| 63 : Dictionary(isolate, options) { } |
57 | 64 |
58 Dictionary& operator=(const Dictionary&); | 65 Dictionary& operator=(const Dictionary&); |
59 | 66 |
60 bool isObject() const; | 67 bool isObject() const; |
61 bool isUndefinedOrNull() const; | 68 bool isUndefinedOrNull() const; |
62 | 69 |
63 bool get(const String&, Dictionary&) const; | 70 bool get(const String&, Dictionary&) const; |
64 bool get(const String&, v8::Local<v8::Value>&) const; | 71 bool get(const String&, v8::Local<v8::Value>&) const; |
65 | 72 |
66 v8::Local<v8::Value> v8Value() const { return m_options; } | 73 v8::Local<v8::Value> v8Value() const { return m_options; } |
(...skipping 12 matching lines...) Expand all Loading... |
79 | 86 |
80 bool getKey(const String& key, v8::Local<v8::Value>&) const; | 87 bool getKey(const String& key, v8::Local<v8::Value>&) const; |
81 DictionaryIterator getIterator(ExecutionContext*) const; | 88 DictionaryIterator getIterator(ExecutionContext*) const; |
82 | 89 |
83 private: | 90 private: |
84 bool getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Value>& resu
lt) const; | 91 bool getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Value>& resu
lt) const; |
85 bool toObject(v8::Local<v8::Object>&) const; | 92 bool toObject(v8::Local<v8::Object>&) const; |
86 | 93 |
87 v8::Local<v8::Value> m_options; | 94 v8::Local<v8::Value> m_options; |
88 v8::Isolate* m_isolate; | 95 v8::Isolate* m_isolate; |
89 ExceptionState* m_exceptionState; | |
90 }; | 96 }; |
91 | 97 |
92 template<> | 98 template<> |
93 struct NativeValueTraits<Dictionary> { | 99 struct NativeValueTraits<Dictionary> { |
94 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val
ue> value, ExceptionState& exceptionState) | 100 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val
ue> value, ExceptionState&) |
95 { | 101 { |
96 return Dictionary(value, isolate, exceptionState); | 102 return Dictionary(isolate, value); |
97 } | 103 } |
98 }; | 104 }; |
99 | 105 |
100 // DictionaryHelper is a collection of static methods for getting or | 106 // DictionaryHelper is a collection of static methods for getting or |
101 // converting a value from Dictionary. | 107 // converting a value from Dictionary. |
102 struct DictionaryHelper { | 108 struct DictionaryHelper { |
103 STATIC_ONLY(DictionaryHelper); | 109 STATIC_ONLY(DictionaryHelper); |
104 template <typename T> | 110 template <typename T> |
105 static bool get(const Dictionary&, const String& key, T& value); | 111 static bool get(const Dictionary&, const String& key, T& value); |
106 template <typename T> | 112 template <typename T> |
107 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal
ue); | 113 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal
ue); |
108 template <typename T> | 114 template <typename T> |
109 static bool get(const Dictionary&, const String& key, T& value, ExceptionSta
te&); | 115 static bool get(const Dictionary&, const String& key, T& value, ExceptionSta
te&); |
110 template <typename T> | 116 template <typename T> |
111 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const
String& key, T& value) | 117 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const
String& key, T& value) |
112 { | 118 { |
113 v8::Local<v8::Value> v8Value; | 119 v8::Local<v8::Value> v8Value; |
114 if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) | 120 if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) |
115 return false; | 121 return false; |
116 return DictionaryHelper::get(dictionary, key, value); | 122 return DictionaryHelper::get(dictionary, key, value); |
117 } | 123 } |
118 template <template <typename> class PointerType, typename T> | 124 template <template <typename> class PointerType, typename T> |
119 static bool get(const Dictionary&, const String& key, PointerType<T>& value)
; | 125 static bool get(const Dictionary&, const String& key, PointerType<T>& value)
; |
120 }; | 126 }; |
121 | 127 |
122 } // namespace blink | 128 } // namespace blink |
123 | 129 |
124 #endif // Dictionary_h | 130 #endif // Dictionary_h |
OLD | NEW |