Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 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/ExceptionMessages.h" | 29 #include "bindings/core/v8/ExceptionMessages.h" |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
| 31 #include "bindings/core/v8/Nullable.h" | 31 #include "bindings/core/v8/Nullable.h" |
| 32 #include "bindings/core/v8/ScriptState.h" | |
| 32 #include "bindings/core/v8/ScriptValue.h" | 33 #include "bindings/core/v8/ScriptValue.h" |
| 33 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "bindings/core/v8/V8BindingMacros.h" | 35 #include "bindings/core/v8/V8BindingMacros.h" |
| 35 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 36 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
| 37 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 38 #include "wtf/text/AtomicString.h" | 39 #include "wtf/text/AtomicString.h" |
| 39 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
| 40 #include <v8.h> | 41 #include <v8.h> |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 // Dictionary class provides ways to retrieve property values as C++ objects | 45 // Dictionary class provides ways to retrieve property values as C++ objects |
| 45 // from a V8 object. Instances of this class must not outlive V8's handle scope | 46 // from a V8 object. Instances of this class must not outlive V8's handle scope |
| 46 // because they hold a V8 value without putting it on persistent handles. | 47 // because they hold a V8 value without putting it on persistent handles. |
| 47 class Dictionary { | 48 class Dictionary final : public ScriptState::Observer { |
|
haraken
2015/03/03 05:12:15
ScriptState::Observer is just intended to be used
bashi
2015/03/03 05:56:28
I see.
| |
| 48 ALLOW_ONLY_INLINE_ALLOCATION(); | 49 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 49 public: | 50 public: |
| 50 Dictionary(); | 51 Dictionary(); |
| 51 Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate*, ExceptionStat e&); | 52 Dictionary(const v8::Handle<v8::Value>& options, v8::Isolate*, ExceptionStat e&); |
| 52 ~Dictionary(); | 53 virtual ~Dictionary(); |
| 53 | 54 |
| 54 Dictionary& operator=(const Dictionary&); | 55 Dictionary& operator=(const Dictionary&); |
| 55 | 56 |
| 56 // This is different from the default constructor: | 57 // This is different from the default constructor: |
| 57 // * isObject() is true when using createEmpty(). | 58 // * isObject() is true when using createEmpty(). |
| 58 // * isUndefinedOrNull() is true when using default constructor. | 59 // * isUndefinedOrNull() is true when using default constructor. |
| 59 static Dictionary createEmpty(v8::Isolate*); | 60 static Dictionary createEmpty(v8::Isolate*); |
| 60 | 61 |
| 61 bool isObject() const; | 62 bool isObject() const; |
| 62 bool isUndefinedOrNull() const; | 63 bool isUndefinedOrNull() const; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 bool convert(ConversionContext&, const String&, Dictionary&) const; | 116 bool convert(ConversionContext&, const String&, Dictionary&) const; |
| 116 | 117 |
| 117 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; | 118 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; |
| 118 bool getPropertyNames(Vector<String>&) const; | 119 bool getPropertyNames(Vector<String>&) const; |
| 119 | 120 |
| 120 bool hasProperty(const String&) const; | 121 bool hasProperty(const String&) const; |
| 121 | 122 |
| 122 v8::Isolate* isolate() const { return m_isolate; } | 123 v8::Isolate* isolate() const { return m_isolate; } |
| 124 // Used by DictionaryHelper. This context could be an empty handle and | |
| 125 // should be used only for V8 APIs which return MaybeLocal<T>. | |
| 126 v8::Local<v8::Context> context() const { return m_context; } | |
| 123 | 127 |
| 124 bool getKey(const String& key, v8::Local<v8::Value>&) const; | 128 bool getKey(const String& key, v8::Local<v8::Value>&) const; |
| 125 | 129 |
| 126 private: | 130 private: |
| 131 // ScriptState::Observer implementation | |
| 132 virtual void willDisposeScriptState(ScriptState*) override; | |
| 133 | |
| 134 void subscribeScriptStateDisposal(); | |
| 135 void unsubscribeScriptStateDisposal(); | |
| 136 | |
| 127 v8::Handle<v8::Value> m_options; | 137 v8::Handle<v8::Value> m_options; |
| 138 v8::Local<v8::Context> m_context; | |
|
bashi
2015/03/03 04:25:05
Should we hold ScriptState instead of v8::Local<v8
haraken
2015/03/03 05:12:15
A big YES. If a DOM object needs to keep some scri
bashi
2015/03/03 05:56:28
Yeah, relying on RefPtr looks much better, and wil
haraken
2015/03/03 06:12:14
I'm sorry for not being clear.
Using GetCurrentCo
| |
| 128 v8::Isolate* m_isolate; | 139 v8::Isolate* m_isolate; |
| 129 ExceptionState* m_exceptionState; | 140 ExceptionState* m_exceptionState; |
| 130 }; | 141 }; |
| 131 | 142 |
| 132 template<> | 143 template<> |
| 133 struct NativeValueTraits<Dictionary> { | 144 struct NativeValueTraits<Dictionary> { |
| 134 static inline Dictionary nativeValue(const v8::Handle<v8::Value>& value, v8: :Isolate* isolate, ExceptionState& exceptionState) | 145 static inline Dictionary nativeValue(const v8::Handle<v8::Value>& value, v8: :Isolate* isolate, ExceptionState& exceptionState) |
| 135 { | 146 { |
| 136 return Dictionary(value, isolate, exceptionState); | 147 return Dictionary(value, isolate, exceptionState); |
| 137 } | 148 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 160 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, T& value); | 171 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, T& value); |
| 161 template <typename T> | 172 template <typename T> |
| 162 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, Nullable<T>& value); | 173 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, Nullable<T>& value); |
| 163 template <template <typename> class PointerType, typename T> | 174 template <template <typename> class PointerType, typename T> |
| 164 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, PointerType<T>& value); | 175 static bool convert(const Dictionary&, Dictionary::ConversionContext&, const String& key, PointerType<T>& value); |
| 165 }; | 176 }; |
| 166 | 177 |
| 167 } | 178 } |
| 168 | 179 |
| 169 #endif // Dictionary_h | 180 #endif // Dictionary_h |
| OLD | NEW |