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

Side by Side Diff: gin/converter.cc

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 | « gin/converter.h ('k') | gin/function_template.h » ('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 #include "gin/converter.h" 5 #include "gin/converter.h"
6 6
7 #include "v8/include/v8.h" 7 #include "v8/include/v8.h"
8 8
9 using v8::ArrayBuffer; 9 using v8::ArrayBuffer;
10 using v8::Boolean; 10 using v8::Boolean;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 bool Converter<double>::FromV8(Isolate* isolate, Handle<Value> val, 86 bool Converter<double>::FromV8(Isolate* isolate, Handle<Value> val,
87 double* out) { 87 double* out) {
88 if (!val->IsNumber()) 88 if (!val->IsNumber())
89 return false; 89 return false;
90 *out = val->NumberValue(); 90 *out = val->NumberValue();
91 return true; 91 return true;
92 } 92 }
93 93
94 Handle<Value> Converter<base::StringPiece>::ToV8(
95 Isolate* isolate, const base::StringPiece& val) {
96 return String::NewFromUtf8(isolate, val.data(), String::kNormalString,
97 static_cast<uint32_t>(val.length()));
98 }
99
94 Handle<Value> Converter<std::string>::ToV8(Isolate* isolate, 100 Handle<Value> Converter<std::string>::ToV8(Isolate* isolate,
95 const std::string& val) { 101 const std::string& val) {
96 return String::NewFromUtf8(isolate, 102 return Converter<base::StringPiece>::ToV8(isolate, val);
97 val.data(),
98 String::kNormalString,
99 static_cast<uint32_t>(val.length()));
100 } 103 }
101 104
102 bool Converter<std::string>::FromV8(Isolate* isolate, Handle<Value> val, 105 bool Converter<std::string>::FromV8(Isolate* isolate, Handle<Value> val,
103 std::string* out) { 106 std::string* out) {
104 if (!val->IsString()) 107 if (!val->IsString())
105 return false; 108 return false;
106 Handle<String> str = Handle<String>::Cast(val); 109 Handle<String> str = Handle<String>::Cast(val);
107 int length = str->Utf8Length(); 110 int length = str->Utf8Length();
108 out->resize(length); 111 out->resize(length);
109 str->WriteUtf8(&(*out)[0], length, NULL, String::NO_NULL_TERMINATION); 112 str->WriteUtf8(&(*out)[0], length, NULL, String::NO_NULL_TERMINATION);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return val; 167 return val;
165 } 168 }
166 169
167 bool Converter<Handle<Value> >::FromV8(Isolate* isolate, Handle<Value> val, 170 bool Converter<Handle<Value> >::FromV8(Isolate* isolate, Handle<Value> val,
168 Handle<Value>* out) { 171 Handle<Value>* out) {
169 *out = val; 172 *out = val;
170 return true; 173 return true;
171 } 174 }
172 175
173 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, 176 v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate,
174 const std::string& val) { 177 const base::StringPiece& val) {
175 return String::NewFromUtf8(isolate, 178 return String::NewFromUtf8(isolate,
176 val.data(), 179 val.data(),
177 String::kInternalizedString, 180 String::kInternalizedString,
178 static_cast<uint32_t>(val.length())); 181 static_cast<uint32_t>(val.length()));
179 } 182 }
180 183
181 std::string V8ToString(v8::Handle<v8::Value> value) { 184 std::string V8ToString(v8::Handle<v8::Value> value) {
182 if (value.IsEmpty()) 185 if (value.IsEmpty())
183 return std::string(); 186 return std::string();
184 std::string result; 187 std::string result;
185 if (!ConvertFromV8(NULL, value, &result)) 188 if (!ConvertFromV8(NULL, value, &result))
186 return std::string(); 189 return std::string();
187 return result; 190 return result;
188 } 191 }
189 192
190 } // namespace gin 193 } // namespace gin
OLDNEW
« no previous file with comments | « gin/converter.h ('k') | gin/function_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698