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

Side by Side Diff: gin/converter.h

Issue 59153005: Begin implementing V8 bindings for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix skipped comment Created 7 years, 1 month 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
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
(...skipping 22 matching lines...) Expand all
33 33
34 template<> 34 template<>
35 struct Converter<uint32_t> { 35 struct Converter<uint32_t> {
36 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 36 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
37 uint32_t val); 37 uint32_t val);
38 static bool FromV8(v8::Handle<v8::Value> val, 38 static bool FromV8(v8::Handle<v8::Value> val,
39 uint32_t* out); 39 uint32_t* out);
40 }; 40 };
41 41
42 template<> 42 template<>
43 struct Converter<int64_t> {
44 // Warning: JavaScript cannot represent 64 integers precisely.
45 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
46 int64_t val);
47 static bool FromV8(v8::Handle<v8::Value> val,
48 int64_t* out);
49 };
50
51 template<>
52 struct Converter<uint64_t> {
53 // Warning: JavaScript cannot represent 64 integers precisely.
54 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
55 uint64_t val);
56 static bool FromV8(v8::Handle<v8::Value> val,
57 uint64_t* out);
58 };
59
60 template<>
43 struct Converter<double> { 61 struct Converter<double> {
44 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 62 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
45 double val); 63 double val);
46 static bool FromV8(v8::Handle<v8::Value> val, 64 static bool FromV8(v8::Handle<v8::Value> val,
47 double* out); 65 double* out);
48 }; 66 };
49 67
50 template<> 68 template<>
51 struct Converter<std::string> { 69 struct Converter<std::string> {
52 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 70 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
53 const std::string& val); 71 const std::string& val);
54 static bool FromV8(v8::Handle<v8::Value> val, 72 static bool FromV8(v8::Handle<v8::Value> val,
55 std::string* out); 73 std::string* out);
56 }; 74 };
57 75
58 template<> 76 template<>
59 struct Converter<v8::Handle<v8::Function> > { 77 struct Converter<v8::Handle<v8::Function> > {
60 static bool FromV8(v8::Handle<v8::Value> val, 78 static bool FromV8(v8::Handle<v8::Value> val,
61 v8::Handle<v8::Function>* out); 79 v8::Handle<v8::Function>* out);
62 }; 80 };
63 81
64 template<> 82 template<>
65 struct Converter<v8::Handle<v8::Object> > { 83 struct Converter<v8::Handle<v8::Object> > {
66 static v8::Handle<v8::Value> ToV8(v8::Handle<v8::Object> val); 84 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
85 v8::Handle<v8::Object> val);
67 static bool FromV8(v8::Handle<v8::Value> val, 86 static bool FromV8(v8::Handle<v8::Value> val,
68 v8::Handle<v8::Object>* out); 87 v8::Handle<v8::Object>* out);
69 }; 88 };
70 89
71 template<typename T> 90 template<typename T>
72 struct Converter<std::vector<T> > { 91 struct Converter<std::vector<T> > {
73 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 92 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
74 const std::vector<T>& val) { 93 const std::vector<T>& val) {
75 v8::Handle<v8::Array> result(v8::Array::New(static_cast<int>(val.size()))); 94 v8::Handle<v8::Array> result(v8::Array::New(static_cast<int>(val.size())));
76 for (size_t i = 0; i < val.size(); ++i) { 95 for (size_t i = 0; i < val.size(); ++i) {
(...skipping 27 matching lines...) Expand all
104 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, 123 v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate,
105 T input) { 124 T input) {
106 return Converter<T>::ToV8(isolate, input); 125 return Converter<T>::ToV8(isolate, input);
107 } 126 }
108 127
109 inline v8::Handle<v8::String> StringToV8( 128 inline v8::Handle<v8::String> StringToV8(
110 v8::Isolate* isolate, std::string input) { 129 v8::Isolate* isolate, std::string input) {
111 return ConvertToV8(isolate, input).As<v8::String>(); 130 return ConvertToV8(isolate, input).As<v8::String>();
112 } 131 }
113 132
133 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate,
134 const std::string& val);
135
114 template<typename T> 136 template<typename T>
115 bool ConvertFromV8(v8::Handle<v8::Value> input, T* result) { 137 bool ConvertFromV8(v8::Handle<v8::Value> input, T* result) {
116 return Converter<T>::FromV8(input, result); 138 return Converter<T>::FromV8(input, result);
117 } 139 }
118 140
119 } // namespace gin 141 } // namespace gin
120 142
121 #endif // GIN_CONVERTER_H_ 143 #endif // GIN_CONVERTER_H_
OLDNEW
« gin/arguments.cc ('K') | « gin/array_buffer.cc ('k') | gin/converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698