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 |
11 namespace gin { | 11 namespace gin { |
12 | 12 |
13 // Dictionary is useful when writing bindings for a function that either | 13 // Dictionary is useful when writing bindings for a function that either |
14 // receives an arbitrary JavaScript object as an argument or returns an | 14 // receives an arbitrary JavaScript object as an argument or returns an |
15 // arbitrary JavaScript object as a result. For example, Dictionary is useful | 15 // arbitrary JavaScript object as a result. For example, Dictionary is useful |
16 // when you might use the |dictionary| type in WebIDL: | 16 // when you might use the |dictionary| type in WebIDL: |
17 // | 17 // |
18 // http://heycam.github.io/webidl/#idl-dictionaries | 18 // http://heycam.github.io/webidl/#idl-dictionaries |
19 // | 19 // |
20 // WARNING: You cannot retain a Dictionary object in the heap. The underlying | 20 // WARNING: You cannot retain a Dictionary object in the heap. The underlying |
21 // storage for Dictionary is tied to the closest enclosing | 21 // storage for Dictionary is tied to the closest enclosing |
22 // v8::HandleScope. Generally speaking, you should store a Dictionary | 22 // v8::HandleScope. Generally speaking, you should store a Dictionary |
23 // on the stack. | 23 // on the stack. |
24 // | 24 // |
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(const Dictionary& other); |
29 ~Dictionary(); | 30 ~Dictionary(); |
30 | 31 |
31 static Dictionary CreateEmpty(v8::Isolate* isolate); | 32 static Dictionary CreateEmpty(v8::Isolate* isolate); |
32 | 33 |
33 template<typename T> | 34 template<typename T> |
34 bool Get(const std::string& key, T* out) { | 35 bool Get(const std::string& key, T* out) { |
35 v8::Local<v8::Value> val; | 36 v8::Local<v8::Value> val; |
36 if (!object_->Get(isolate_->GetCurrentContext(), StringToV8(isolate_, key)) | 37 if (!object_->Get(isolate_->GetCurrentContext(), StringToV8(isolate_, key)) |
37 .ToLocal(&val)) { | 38 .ToLocal(&val)) { |
38 return false; | 39 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
66 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 67 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, |
67 Dictionary val); | 68 Dictionary val); |
68 static bool FromV8(v8::Isolate* isolate, | 69 static bool FromV8(v8::Isolate* isolate, |
69 v8::Local<v8::Value> val, | 70 v8::Local<v8::Value> val, |
70 Dictionary* out); | 71 Dictionary* out); |
71 }; | 72 }; |
72 | 73 |
73 } // namespace gin | 74 } // namespace gin |
74 | 75 |
75 #endif // GIN_DICTIONARY_H_ | 76 #endif // GIN_DICTIONARY_H_ |
OLD | NEW |