| 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 #include "gin/gin_export.h" | 9 #include "gin/gin_export.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class GIN_EXPORT Dictionary { | 25 class GIN_EXPORT Dictionary { |
| 26 public: | 26 public: |
| 27 explicit Dictionary(v8::Isolate* isolate); | 27 explicit Dictionary(v8::Isolate* isolate); |
| 28 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); | 28 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); |
| 29 ~Dictionary(); | 29 ~Dictionary(); |
| 30 | 30 |
| 31 static Dictionary CreateEmpty(v8::Isolate* isolate); | 31 static Dictionary CreateEmpty(v8::Isolate* isolate); |
| 32 | 32 |
| 33 template<typename T> | 33 template<typename T> |
| 34 bool Get(const std::string& key, T* out) { | 34 bool Get(const std::string& key, T* out) { |
| 35 v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key)); | 35 v8::Local<v8::Value> val; |
| 36 if (!object_->Get(isolate_->GetCurrentContext(), StringToV8(isolate_, key)) |
| 37 .ToLocal(&val)) |
| 38 return false; |
| 36 return ConvertFromV8(isolate_, val, out); | 39 return ConvertFromV8(isolate_, val, out); |
| 37 } | 40 } |
| 38 | 41 |
| 39 template<typename T> | 42 template<typename T> |
| 40 bool Set(const std::string& key, T val) { | 43 bool Set(const std::string& key, T val) { |
| 41 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val)); | 44 v8::Maybe<bool> result = |
| 45 object_->Set(isolate_->GetCurrentContext(), StringToV8(isolate_, key), |
| 46 ConvertToV8(isolate_, val)); |
| 47 return !result.IsNothing() && result.FromJust(); |
| 42 } | 48 } |
| 43 | 49 |
| 44 v8::Isolate* isolate() const { return isolate_; } | 50 v8::Isolate* isolate() const { return isolate_; } |
| 45 | 51 |
| 46 private: | 52 private: |
| 47 friend struct Converter<Dictionary>; | 53 friend struct Converter<Dictionary>; |
| 48 | 54 |
| 49 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). | 55 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). |
| 50 v8::Isolate* isolate_; | 56 v8::Isolate* isolate_; |
| 51 v8::Handle<v8::Object> object_; | 57 v8::Handle<v8::Object> object_; |
| 52 }; | 58 }; |
| 53 | 59 |
| 54 template<> | 60 template<> |
| 55 struct GIN_EXPORT Converter<Dictionary> { | 61 struct GIN_EXPORT Converter<Dictionary> { |
| 56 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, | 62 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, |
| 57 Dictionary val); | 63 Dictionary val); |
| 58 static bool FromV8(v8::Isolate* isolate, | 64 static bool FromV8(v8::Isolate* isolate, |
| 59 v8::Handle<v8::Value> val, | 65 v8::Handle<v8::Value> val, |
| 60 Dictionary* out); | 66 Dictionary* out); |
| 61 }; | 67 }; |
| 62 | 68 |
| 63 } // namespace gin | 69 } // namespace gin |
| 64 | 70 |
| 65 #endif // GIN_DICTIONARY_H_ | 71 #endif // GIN_DICTIONARY_H_ |
| OLD | NEW |