Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: gin/dictionary.h

Issue 1112923003: Replace Handle<> with Local in remaining gin/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gin/converter_unittest.cc ('k') | gin/dictionary.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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::Handle<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::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key)); 35 v8::Local<v8::Value> val = object_->Get(StringToV8(isolate_, key));
36 return ConvertFromV8(isolate_, val, out); 36 return ConvertFromV8(isolate_, val, out);
37 } 37 }
38 38
39 template<typename T> 39 template<typename T>
40 bool Set(const std::string& key, T val) { 40 bool Set(const std::string& key, T val) {
41 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val)); 41 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val));
42 } 42 }
43 43
44 v8::Isolate* isolate() const { return isolate_; } 44 v8::Isolate* isolate() const { return isolate_; }
45 45
46 private: 46 private:
47 friend struct Converter<Dictionary>; 47 friend struct Converter<Dictionary>;
48 48
49 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get(). 49 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get().
50 v8::Isolate* isolate_; 50 v8::Isolate* isolate_;
51 v8::Handle<v8::Object> object_; 51 v8::Local<v8::Object> object_;
52 }; 52 };
53 53
54 template<> 54 template<>
55 struct GIN_EXPORT Converter<Dictionary> { 55 struct GIN_EXPORT Converter<Dictionary> {
56 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 56 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
57 Dictionary val); 57 Dictionary val);
58 static bool FromV8(v8::Isolate* isolate, 58 static bool FromV8(v8::Isolate* isolate,
59 v8::Handle<v8::Value> val, 59 v8::Local<v8::Value> val,
60 Dictionary* out); 60 Dictionary* out);
61 }; 61 };
62 62
63 } // namespace gin 63 } // namespace gin
64 64
65 #endif // GIN_DICTIONARY_H_ 65 #endif // GIN_DICTIONARY_H_
OLDNEW
« no previous file with comments | « gin/converter_unittest.cc ('k') | gin/dictionary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698