OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/child/v8_value_converter_impl.h" | 5 #include "content/child/v8_value_converter_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 FromV8ValueState state(avoid_identity_hash_for_testing_); | 225 FromV8ValueState state(avoid_identity_hash_for_testing_); |
226 return FromV8ValueImpl(&state, val, context->GetIsolate()); | 226 return FromV8ValueImpl(&state, val, context->GetIsolate()); |
227 } | 227 } |
228 | 228 |
229 v8::Local<v8::Value> V8ValueConverterImpl::ToV8ValueImpl( | 229 v8::Local<v8::Value> V8ValueConverterImpl::ToV8ValueImpl( |
230 v8::Isolate* isolate, | 230 v8::Isolate* isolate, |
231 v8::Local<v8::Object> creation_context, | 231 v8::Local<v8::Object> creation_context, |
232 const base::Value* value) const { | 232 const base::Value* value) const { |
233 CHECK(value); | 233 CHECK(value); |
234 switch (value->GetType()) { | 234 switch (value->GetType()) { |
235 case base::Value::TYPE_NULL: | 235 case base::Value::Type::NONE: |
236 return v8::Null(isolate); | 236 return v8::Null(isolate); |
237 | 237 |
238 case base::Value::TYPE_BOOLEAN: { | 238 case base::Value::Type::BOOLEAN: { |
239 bool val = false; | 239 bool val = false; |
240 CHECK(value->GetAsBoolean(&val)); | 240 CHECK(value->GetAsBoolean(&val)); |
241 return v8::Boolean::New(isolate, val); | 241 return v8::Boolean::New(isolate, val); |
242 } | 242 } |
243 | 243 |
244 case base::Value::TYPE_INTEGER: { | 244 case base::Value::Type::INTEGER: { |
245 int val = 0; | 245 int val = 0; |
246 CHECK(value->GetAsInteger(&val)); | 246 CHECK(value->GetAsInteger(&val)); |
247 return v8::Integer::New(isolate, val); | 247 return v8::Integer::New(isolate, val); |
248 } | 248 } |
249 | 249 |
250 case base::Value::TYPE_DOUBLE: { | 250 case base::Value::Type::DOUBLE: { |
251 double val = 0.0; | 251 double val = 0.0; |
252 CHECK(value->GetAsDouble(&val)); | 252 CHECK(value->GetAsDouble(&val)); |
253 return v8::Number::New(isolate, val); | 253 return v8::Number::New(isolate, val); |
254 } | 254 } |
255 | 255 |
256 case base::Value::TYPE_STRING: { | 256 case base::Value::Type::STRING: { |
257 std::string val; | 257 std::string val; |
258 CHECK(value->GetAsString(&val)); | 258 CHECK(value->GetAsString(&val)); |
259 return v8::String::NewFromUtf8( | 259 return v8::String::NewFromUtf8( |
260 isolate, val.c_str(), v8::String::kNormalString, val.length()); | 260 isolate, val.c_str(), v8::String::kNormalString, val.length()); |
261 } | 261 } |
262 | 262 |
263 case base::Value::TYPE_LIST: | 263 case base::Value::Type::LIST: |
264 return ToV8Array(isolate, | 264 return ToV8Array(isolate, |
265 creation_context, | 265 creation_context, |
266 static_cast<const base::ListValue*>(value)); | 266 static_cast<const base::ListValue*>(value)); |
267 | 267 |
268 case base::Value::TYPE_DICTIONARY: | 268 case base::Value::Type::DICTIONARY: |
269 return ToV8Object(isolate, | 269 return ToV8Object(isolate, |
270 creation_context, | 270 creation_context, |
271 static_cast<const base::DictionaryValue*>(value)); | 271 static_cast<const base::DictionaryValue*>(value)); |
272 | 272 |
273 case base::Value::TYPE_BINARY: | 273 case base::Value::Type::BINARY: |
274 return ToArrayBuffer(isolate, | 274 return ToArrayBuffer(isolate, |
275 creation_context, | 275 creation_context, |
276 static_cast<const base::BinaryValue*>(value)); | 276 static_cast<const base::BinaryValue*>(value)); |
277 | 277 |
278 default: | 278 default: |
279 LOG(ERROR) << "Unexpected value type: " << value->GetType(); | 279 LOG(ERROR) << "Unexpected value type: " << value->GetType(); |
280 return v8::Null(isolate); | 280 return v8::Null(isolate); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 // tabs.create({}) | 608 // tabs.create({}) |
609 // | 609 // |
610 // this will work as expected on code that only checks for the existence of | 610 // this will work as expected on code that only checks for the existence of |
611 // a "windowId" property (such as that legacy code). However given | 611 // a "windowId" property (such as that legacy code). However given |
612 // | 612 // |
613 // tabs.create({windowId: null}) | 613 // tabs.create({windowId: null}) |
614 // | 614 // |
615 // there *is* a "windowId" property, but since it should be an int, code | 615 // there *is* a "windowId" property, but since it should be an int, code |
616 // on the browser which doesn't additionally check for null will fail. | 616 // on the browser which doesn't additionally check for null will fail. |
617 // We can avoid all bugs related to this by stripping null. | 617 // We can avoid all bugs related to this by stripping null. |
618 if (strip_null_from_objects_ && child->IsType(base::Value::TYPE_NULL)) | 618 if (strip_null_from_objects_ && child->IsType(base::Value::Type::NONE)) |
619 continue; | 619 continue; |
620 | 620 |
621 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 621 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
622 std::move(child)); | 622 std::move(child)); |
623 } | 623 } |
624 | 624 |
625 return std::move(result); | 625 return std::move(result); |
626 } | 626 } |
627 | 627 |
628 } // namespace content | 628 } // namespace content |
OLD | NEW |