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

Side by Side Diff: content/renderer/v8_value_converter.cc

Issue 7647026: base: Add three helper functions to Values API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a typo Ceate -> Create Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_view.cc ('k') | content/renderer/v8_value_converter_browsertest.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/renderer/v8_value_converter.h" 5 #include "content/renderer/v8_value_converter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 } 113 }
114 114
115 return result; 115 return result;
116 } 116 }
117 117
118 Value* V8ValueConverter::FromV8ValueImpl(v8::Handle<v8::Value> val) const { 118 Value* V8ValueConverter::FromV8ValueImpl(v8::Handle<v8::Value> val) const {
119 CHECK(!val.IsEmpty()); 119 CHECK(!val.IsEmpty());
120 120
121 if (val->IsNull()) 121 if (val->IsNull())
122 return Value::CreateNullValue(); 122 return base::NullValue();
123 123
124 if (val->IsBoolean()) 124 if (val->IsBoolean())
125 return Value::CreateBooleanValue(val->ToBoolean()->Value()); 125 return Value::CreateBooleanValue(val->ToBoolean()->Value());
126 126
127 if (val->IsInt32()) 127 if (val->IsInt32())
128 return Value::CreateIntegerValue(val->ToInt32()->Value()); 128 return Value::CreateIntegerValue(val->ToInt32()->Value());
129 129
130 if (val->IsNumber()) 130 if (val->IsNumber())
131 return Value::CreateDoubleValue(val->ToNumber()->Value()); 131 return Value::CreateDoubleValue(val->ToNumber()->Value());
132 132
133 if (val->IsString()) { 133 if (val->IsString()) {
134 v8::String::Utf8Value utf8(val->ToString()); 134 v8::String::Utf8Value utf8(val->ToString());
135 return Value::CreateStringValue(std::string(*utf8, utf8.length())); 135 return Value::CreateStringValue(std::string(*utf8, utf8.length()));
136 } 136 }
137 137
138 if (allow_undefined_ && val->IsUndefined()) 138 if (allow_undefined_ && val->IsUndefined())
139 return Value::CreateNullValue(); 139 return base::NullValue();
140 140
141 if (allow_date_ && val->IsDate()) { 141 if (allow_date_ && val->IsDate()) {
142 v8::Date* date = v8::Date::Cast(*val); 142 v8::Date* date = v8::Date::Cast(*val);
143 return Value::CreateDoubleValue(date->NumberValue() / 1000.0); 143 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
144 } 144 }
145 145
146 if (allow_regexp_ && val->IsRegExp()) { 146 if (allow_regexp_ && val->IsRegExp()) {
147 return Value::CreateStringValue( 147 return Value::CreateStringValue(
148 *v8::String::Utf8Value(val->ToString())); 148 *v8::String::Utf8Value(val->ToString()));
149 } 149 }
150 150
151 // v8::Value doesn't have a ToArray() method for some reason. 151 // v8::Value doesn't have a ToArray() method for some reason.
152 if (val->IsArray()) 152 if (val->IsArray())
153 return FromV8Array(val.As<v8::Array>()); 153 return FromV8Array(val.As<v8::Array>());
154 154
155 if (val->IsObject()) 155 if (val->IsObject())
156 return FromV8Object(val->ToObject()); 156 return FromV8Object(val->ToObject());
157 157
158 LOG(ERROR) << "Unexpected v8 value type encountered."; 158 LOG(ERROR) << "Unexpected v8 value type encountered.";
159 return Value::CreateNullValue(); 159 return base::NullValue();
160 } 160 }
161 161
162 ListValue* V8ValueConverter::FromV8Array(v8::Handle<v8::Array> val) const { 162 ListValue* V8ValueConverter::FromV8Array(v8::Handle<v8::Array> val) const {
163 ListValue* result = new ListValue(); 163 ListValue* result = new ListValue();
164 for (uint32 i = 0; i < val->Length(); ++i) { 164 for (uint32 i = 0; i < val->Length(); ++i) {
165 v8::TryCatch try_catch; 165 v8::TryCatch try_catch;
166 v8::Handle<v8::Value> child_v8 = val->Get(i); 166 v8::Handle<v8::Value> child_v8 = val->Get(i);
167 if (try_catch.HasCaught()) { 167 if (try_catch.HasCaught()) {
168 LOG(ERROR) << "Getter for index " << i << " threw an exception."; 168 LOG(ERROR) << "Getter for index " << i << " threw an exception.";
169 child_v8 = v8::Null(); 169 child_v8 = v8::Null();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 206
207 Value* child = FromV8ValueImpl(child_v8); 207 Value* child = FromV8ValueImpl(child_v8);
208 CHECK(child); 208 CHECK(child);
209 209
210 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 210 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
211 child); 211 child);
212 } 212 }
213 return result; 213 return result;
214 } 214 }
OLDNEW
« no previous file with comments | « content/renderer/render_view.cc ('k') | content/renderer/v8_value_converter_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698