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

Side by Side Diff: gin/converter.h

Issue 93813002: Implement gin::ObjectTemplateBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asdf Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gin/converter.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_CONVERTER_H_ 5 #ifndef GIN_CONVERTER_H_
6 #define GIN_CONVERTER_H_ 6 #define GIN_CONVERTER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/string_piece.h"
11 #include "v8/include/v8.h" 12 #include "v8/include/v8.h"
12 13
13 namespace gin { 14 namespace gin {
14 15
15 template<typename T> 16 template<typename T>
16 struct Converter {}; 17 struct Converter {};
17 18
18 template<> 19 template<>
19 struct Converter<bool> { 20 struct Converter<bool> {
20 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 21 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 template<> 66 template<>
66 struct Converter<double> { 67 struct Converter<double> {
67 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 68 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
68 double val); 69 double val);
69 static bool FromV8(v8::Isolate* isolate, 70 static bool FromV8(v8::Isolate* isolate,
70 v8::Handle<v8::Value> val, 71 v8::Handle<v8::Value> val,
71 double* out); 72 double* out);
72 }; 73 };
73 74
74 template<> 75 template<>
76 struct Converter<base::StringPiece> {
77 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
78 const base::StringPiece& val);
79 // No conversion out is possible because StringPiece does not contain storage.
80 };
81
82 template<>
75 struct Converter<std::string> { 83 struct Converter<std::string> {
76 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 84 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
77 const std::string& val); 85 const std::string& val);
78 static bool FromV8(v8::Isolate* isolate, 86 static bool FromV8(v8::Isolate* isolate,
79 v8::Handle<v8::Value> val, 87 v8::Handle<v8::Value> val,
80 std::string* out); 88 std::string* out);
81 }; 89 };
82 90
83 template<> 91 template<>
84 struct Converter<v8::Handle<v8::Function> > { 92 struct Converter<v8::Handle<v8::Function> > {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 }; 165 };
158 166
159 // Convenience functions that deduce T. 167 // Convenience functions that deduce T.
160 template<typename T> 168 template<typename T>
161 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, 169 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate,
162 T input) { 170 T input) {
163 return Converter<T>::ToV8(isolate, input); 171 return Converter<T>::ToV8(isolate, input);
164 } 172 }
165 173
166 inline v8::Handle<v8::String> StringToV8(v8::Isolate* isolate, 174 inline v8::Handle<v8::String> StringToV8(v8::Isolate* isolate,
167 std::string input) { 175 const base::StringPiece& input) {
168 return ConvertToV8(isolate, input).As<v8::String>(); 176 return ConvertToV8(isolate, input).As<v8::String>();
169 } 177 }
170 178
171 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, 179 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate,
172 const std::string& val); 180 const base::StringPiece& val);
173 181
174 template<typename T> 182 template<typename T>
175 bool ConvertFromV8(v8::Isolate* isolate, v8::Handle<v8::Value> input, 183 bool ConvertFromV8(v8::Isolate* isolate, v8::Handle<v8::Value> input,
176 T* result) { 184 T* result) {
177 return Converter<T>::FromV8(isolate, input, result); 185 return Converter<T>::FromV8(isolate, input, result);
178 } 186 }
179 187
180 std::string V8ToString(v8::Handle<v8::Value> value); 188 std::string V8ToString(v8::Handle<v8::Value> value);
181 189
182 } // namespace gin 190 } // namespace gin
183 191
184 #endif // GIN_CONVERTER_H_ 192 #endif // GIN_CONVERTER_H_
OLDNEW
« no previous file with comments | « no previous file | gin/converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698