Chromium Code Reviews| 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::Local<v8::Object> object); | 28 Dictionary(v8::Isolate* isolate, v8::Local<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::Local<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)) | |
|
jochen (gone - plz use gerrit)
2015/05/27 14:43:26
nit add {}
bashi
2015/05/29 02:04:02
Done.
| |
| 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::Local<v8::Value> v8_value; |
| 45 if (!TryConvertToV8(isolate_, val, &v8_value)) | |
| 46 return false; | |
| 47 v8::Maybe<bool> result = | |
| 48 object_->Set(isolate_->GetCurrentContext(), StringToV8(isolate_, key), | |
| 49 v8_value); | |
| 50 return !result.IsNothing() && result.FromJust(); | |
| 42 } | 51 } |
| 43 | 52 |
| 44 v8::Isolate* isolate() const { return isolate_; } | 53 v8::Isolate* isolate() const { return isolate_; } |
| 45 | 54 |
| 46 private: | 55 private: |
| 47 friend struct Converter<Dictionary>; | 56 friend struct Converter<Dictionary>; |
| 48 | 57 |
| 49 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). | 58 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). |
| 50 v8::Isolate* isolate_; | 59 v8::Isolate* isolate_; |
| 51 v8::Local<v8::Object> object_; | 60 v8::Local<v8::Object> object_; |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 template<> | 63 template<> |
| 55 struct GIN_EXPORT Converter<Dictionary> { | 64 struct GIN_EXPORT Converter<Dictionary> { |
| 56 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 65 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
| 57 Dictionary val); | 66 Dictionary val); |
| 58 static bool FromV8(v8::Isolate* isolate, | 67 static bool FromV8(v8::Isolate* isolate, |
| 59 v8::Local<v8::Value> val, | 68 v8::Local<v8::Value> val, |
| 60 Dictionary* out); | 69 Dictionary* out); |
| 61 }; | 70 }; |
| 62 | 71 |
| 63 } // namespace gin | 72 } // namespace gin |
| 64 | 73 |
| 65 #endif // GIN_DICTIONARY_H_ | 74 #endif // GIN_DICTIONARY_H_ |
| OLD | NEW |