OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GIN_DICTIONARY_H_ |
| 6 #define GIN_DICTIONARY_H_ |
| 7 |
| 8 #include "gin/converter.h" |
| 9 |
| 10 namespace gin { |
| 11 |
| 12 class Dictionary { |
| 13 public: |
| 14 explicit Dictionary(v8::Isolate* isolate); |
| 15 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); |
| 16 ~Dictionary(); |
| 17 |
| 18 static Dictionary CreateEmpty(v8::Isolate* isolate); |
| 19 |
| 20 template<typename T> |
| 21 bool Get(const std::string& key, T* out) { |
| 22 v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key)); |
| 23 return ConvertFromV8(val, out); |
| 24 } |
| 25 |
| 26 template<typename T> |
| 27 bool Set(const std::string& key, T val) { |
| 28 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val)); |
| 29 } |
| 30 |
| 31 v8::Isolate* isolate() const { return isolate_; } |
| 32 |
| 33 private: |
| 34 friend struct Converter<Dictionary>; |
| 35 |
| 36 v8::Isolate* isolate_; |
| 37 v8::Handle<v8::Object> object_; |
| 38 }; |
| 39 |
| 40 template<> |
| 41 struct Converter<Dictionary> { |
| 42 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, |
| 43 Dictionary val); |
| 44 static bool FromV8(v8::Handle<v8::Value> val, |
| 45 Dictionary* out); |
| 46 }; |
| 47 |
| 48 } // namespace gin |
| 49 |
| 50 #endif // GIN_DICTIONARY_H_ |
OLD | NEW |