Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/Dictionary.h

Issue 2285183005: Use StringView in Dictionary and DictionaryHelper. (Closed)
Patch Set: rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/Dictionary.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
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/Nullable.h" 31 #include "bindings/core/v8/Nullable.h"
32 #include "bindings/core/v8/ScriptValue.h"
33 #include "bindings/core/v8/V8Binding.h" 32 #include "bindings/core/v8/V8Binding.h"
34 #include "bindings/core/v8/V8BindingMacros.h"
35 #include "core/CoreExport.h" 33 #include "core/CoreExport.h"
36 #include "wtf/HashMap.h" 34 #include "wtf/HashMap.h"
37 #include "wtf/HashSet.h"
38 #include "wtf/Vector.h" 35 #include "wtf/Vector.h"
39 #include "wtf/text/AtomicString.h" 36 #include "wtf/text/StringView.h"
40 #include "wtf/text/WTFString.h"
41 #include <v8.h> 37 #include <v8.h>
42 38
43 namespace blink { 39 namespace blink {
44 40
45 class ExceptionState; 41 class ExceptionState;
46 class ExecutionContext; 42 class ExecutionContext;
47 43
48 // Dictionary class provides ways to retrieve property values as C++ objects 44 // 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 45 // 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. 46 // because they hold a V8 value without putting it on persistent handles.
51 class CORE_EXPORT Dictionary final { 47 class CORE_EXPORT Dictionary final {
52 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
53 public: 49 public:
54 Dictionary() 50 Dictionary()
55 : m_isolate(nullptr) { } 51 : m_isolate(nullptr) { }
56 Dictionary(v8::Isolate* isolate, const v8::Local<v8::Value>& options) 52 Dictionary(v8::Isolate* isolate, const v8::Local<v8::Value>& options)
57 : m_options(options) 53 : m_options(options)
58 , m_isolate(isolate) 54 , m_isolate(isolate)
59 { 55 {
60 DCHECK(m_isolate); 56 DCHECK(m_isolate);
61 } 57 }
62 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate* isolate, Except ionState&) // DEPRECATED 58 Dictionary(const v8::Local<v8::Value>& options, v8::Isolate* isolate, Except ionState&) // DEPRECATED
63 : Dictionary(isolate, options) { } 59 : Dictionary(isolate, options) { }
64 60
65 Dictionary& operator=(const Dictionary&); 61 Dictionary& operator=(const Dictionary&);
66 62
67 bool isObject() const; 63 bool isObject() const;
68 bool isUndefinedOrNull() const; 64 bool isUndefinedOrNull() const;
69 65
70 bool get(const String&, Dictionary&) const; 66 bool get(const StringView&, Dictionary&) const;
71 bool get(const String&, v8::Local<v8::Value>&) const; 67 bool get(const StringView&, v8::Local<v8::Value>&) const;
72 68
73 v8::Local<v8::Value> v8Value() const { return m_options; } 69 v8::Local<v8::Value> v8Value() const { return m_options; }
74 70
75 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; 71 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const;
76 bool getPropertyNames(Vector<String>&) const; 72 bool getPropertyNames(Vector<String>&) const;
77 73
78 bool hasProperty(const String&) const; 74 bool hasProperty(const StringView&) const;
79 75
80 v8::Isolate* isolate() const { return m_isolate; } 76 v8::Isolate* isolate() const { return m_isolate; }
81 v8::Local<v8::Context> v8Context() const 77 v8::Local<v8::Context> v8Context() const
82 { 78 {
83 ASSERT(m_isolate); 79 ASSERT(m_isolate);
84 return m_isolate->GetCurrentContext(); 80 return m_isolate->GetCurrentContext();
85 } 81 }
86 82
87 bool getKey(const String& key, v8::Local<v8::Value>&) const;
88 DictionaryIterator getIterator(ExecutionContext*) const; 83 DictionaryIterator getIterator(ExecutionContext*) const;
89 84
90 private: 85 private:
91 bool getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Value>& resu lt) const; 86 bool getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Value>& resu lt) const;
92 bool toObject(v8::Local<v8::Object>&) const; 87 bool toObject(v8::Local<v8::Object>&) const;
93 88
94 v8::Local<v8::Value> m_options; 89 v8::Local<v8::Value> m_options;
95 v8::Isolate* m_isolate; 90 v8::Isolate* m_isolate;
96 }; 91 };
97 92
98 template<> 93 template<>
99 struct NativeValueTraits<Dictionary> { 94 struct NativeValueTraits<Dictionary> {
100 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val ue> value, ExceptionState&) 95 static inline Dictionary nativeValue(v8::Isolate* isolate, v8::Local<v8::Val ue> value, ExceptionState&)
101 { 96 {
102 return Dictionary(isolate, value); 97 return Dictionary(isolate, value);
103 } 98 }
104 }; 99 };
105 100
106 // DictionaryHelper is a collection of static methods for getting or 101 // DictionaryHelper is a collection of static methods for getting or
107 // converting a value from Dictionary. 102 // converting a value from Dictionary.
108 struct DictionaryHelper { 103 struct DictionaryHelper {
109 STATIC_ONLY(DictionaryHelper); 104 STATIC_ONLY(DictionaryHelper);
110 template <typename T> 105 template <typename T>
111 static bool get(const Dictionary&, const String& key, T& value); 106 static bool get(const Dictionary&, const StringView& key, T& value);
112 template <typename T> 107 template <typename T>
113 static bool get(const Dictionary&, const String& key, T& value, bool& hasVal ue); 108 static bool get(const Dictionary&, const StringView& key, T& value, bool& ha sValue);
114 template <typename T> 109 template <typename T>
115 static bool get(const Dictionary&, const String& key, T& value, ExceptionSta te&); 110 static bool get(const Dictionary&, const StringView& key, T& value, Exceptio nState&);
116 template <typename T> 111 template <typename T>
117 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const String& key, T& value) 112 static bool getWithUndefinedOrNullCheck(const Dictionary& dictionary, const StringView& key, T& value)
118 { 113 {
119 v8::Local<v8::Value> v8Value; 114 v8::Local<v8::Value> v8Value;
120 if (!dictionary.getKey(key, v8Value) || isUndefinedOrNull(v8Value)) 115 if (!dictionary.get(key, v8Value) || isUndefinedOrNull(v8Value))
121 return false; 116 return false;
122 return DictionaryHelper::get(dictionary, key, value); 117 return DictionaryHelper::get(dictionary, key, value);
123 } 118 }
124 template <template <typename> class PointerType, typename T> 119 template <template <typename> class PointerType, typename T>
125 static bool get(const Dictionary&, const String& key, PointerType<T>& value) ; 120 static bool get(const Dictionary&, const StringView& key, PointerType<T>& va lue);
126 }; 121 };
127 122
128 } // namespace blink 123 } // namespace blink
129 124
130 #endif // Dictionary_h 125 #endif // Dictionary_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/Dictionary.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698