| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GIN_DICTIONARY_H_ | 5 #ifndef GIN_DICTIONARY_H_ |
| 6 #define GIN_DICTIONARY_H_ | 6 #define GIN_DICTIONARY_H_ |
| 7 | 7 |
| 8 #include "gin/converter.h" | 8 #include "gin/converter.h" |
| 9 | 9 |
| 10 namespace gin { | 10 namespace gin { |
| 11 | 11 |
| 12 class Dictionary { | 12 class Dictionary { |
| 13 public: | 13 public: |
| 14 explicit Dictionary(v8::Isolate* isolate); | 14 explicit Dictionary(v8::Isolate* isolate); |
| 15 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); | 15 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); |
| 16 ~Dictionary(); | 16 ~Dictionary(); |
| 17 | 17 |
| 18 static Dictionary CreateEmpty(v8::Isolate* isolate); | 18 static Dictionary CreateEmpty(v8::Isolate* isolate); |
| 19 | 19 |
| 20 template<typename T> | 20 template<typename T> |
| 21 bool Get(const std::string& key, T* out) { | 21 bool Get(const std::string& key, T* out) { |
| 22 v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key)); | 22 v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key)); |
| 23 return ConvertFromV8(val, out); | 23 return ConvertFromV8(isolate_, val, out); |
| 24 } | 24 } |
| 25 | 25 |
| 26 template<typename T> | 26 template<typename T> |
| 27 bool Set(const std::string& key, T val) { | 27 bool Set(const std::string& key, T val) { |
| 28 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val)); | 28 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 v8::Isolate* isolate() const { return isolate_; } | 31 v8::Isolate* isolate() const { return isolate_; } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 friend struct Converter<Dictionary>; | 34 friend struct Converter<Dictionary>; |
| 35 | 35 |
| 36 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). |
| 36 v8::Isolate* isolate_; | 37 v8::Isolate* isolate_; |
| 37 v8::Handle<v8::Object> object_; | 38 v8::Handle<v8::Object> object_; |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 template<> | 41 template<> |
| 41 struct Converter<Dictionary> { | 42 struct Converter<Dictionary> { |
| 42 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, | 43 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, |
| 43 Dictionary val); | 44 Dictionary val); |
| 44 static bool FromV8(v8::Handle<v8::Value> val, | 45 static bool FromV8(v8::Isolate* isolate, |
| 46 v8::Handle<v8::Value> val, |
| 45 Dictionary* out); | 47 Dictionary* out); |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 } // namespace gin | 50 } // namespace gin |
| 49 | 51 |
| 50 #endif // GIN_DICTIONARY_H_ | 52 #endif // GIN_DICTIONARY_H_ |
| OLD | NEW |