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

Side by Side Diff: gin/converter.h

Issue 93813002: Implement gin::ObjectTemplateBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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') | gin/function_template.h » ('J')
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 }; 164 };
157 165
158 // Convenience functions that deduce T. 166 // Convenience functions that deduce T.
159 template<typename T> 167 template<typename T>
160 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, 168 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate,
161 T input) { 169 T input) {
162 return Converter<T>::ToV8(isolate, input); 170 return Converter<T>::ToV8(isolate, input);
163 } 171 }
164 172
165 inline v8::Handle<v8::String> StringToV8(v8::Isolate* isolate, 173 inline v8::Handle<v8::String> StringToV8(v8::Isolate* isolate,
166 std::string input) { 174 const base::StringPiece& input) {
167 return ConvertToV8(isolate, input).As<v8::String>(); 175 return ConvertToV8(isolate, input).As<v8::String>();
168 } 176 }
169 177
170 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, 178 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate,
171 const std::string& val); 179 const base::StringPiece& val);
172 180
173 template<typename T> 181 template<typename T>
174 bool ConvertFromV8(v8::Isolate* isolate, v8::Handle<v8::Value> input, 182 bool ConvertFromV8(v8::Isolate* isolate, v8::Handle<v8::Value> input,
175 T* result) { 183 T* result) {
176 return Converter<T>::FromV8(isolate, input, result); 184 return Converter<T>::FromV8(isolate, input, result);
177 } 185 }
178 186
179 std::string V8ToString(v8::Handle<v8::Value> value); 187 std::string V8ToString(v8::Handle<v8::Value> value);
180 188
181 } // namespace gin 189 } // namespace gin
182 190
183 #endif // GIN_CONVERTER_H_ 191 #endif // GIN_CONVERTER_H_
OLDNEW
« no previous file with comments | « no previous file | gin/converter.cc » ('j') | gin/function_template.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698