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> |
| 8 #include <stdint.h> |
| 9 |
7 #include <cmath> | 10 #include <cmath> |
8 #include <string> | 11 #include <string> |
9 | 12 |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 15 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
14 #include "base/values.h" | 17 #include "base/values.h" |
15 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 18 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
16 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" | 19 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 232 |
230 for (size_t i = 0; i < val->GetSize(); ++i) { | 233 for (size_t i = 0; i < val->GetSize(); ++i) { |
231 const base::Value* child = NULL; | 234 const base::Value* child = NULL; |
232 CHECK(val->Get(i, &child)); | 235 CHECK(val->Get(i, &child)); |
233 | 236 |
234 v8::Local<v8::Value> child_v8 = | 237 v8::Local<v8::Value> child_v8 = |
235 ToV8ValueImpl(isolate, creation_context, child); | 238 ToV8ValueImpl(isolate, creation_context, child); |
236 CHECK(!child_v8.IsEmpty()); | 239 CHECK(!child_v8.IsEmpty()); |
237 | 240 |
238 v8::TryCatch try_catch(isolate); | 241 v8::TryCatch try_catch(isolate); |
239 result->Set(static_cast<uint32>(i), child_v8); | 242 result->Set(static_cast<uint32_t>(i), child_v8); |
240 if (try_catch.HasCaught()) | 243 if (try_catch.HasCaught()) |
241 LOG(ERROR) << "Setter for index " << i << " threw an exception."; | 244 LOG(ERROR) << "Setter for index " << i << " threw an exception."; |
242 } | 245 } |
243 | 246 |
244 return result; | 247 return result; |
245 } | 248 } |
246 | 249 |
247 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object( | 250 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object( |
248 v8::Isolate* isolate, | 251 v8::Isolate* isolate, |
249 v8::Local<v8::Object> creation_context, | 252 v8::Local<v8::Object> creation_context, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 base::Unretained(this), | 391 base::Unretained(this), |
389 base::Unretained(state)); | 392 base::Unretained(state)); |
390 base::Value* out = NULL; | 393 base::Value* out = NULL; |
391 if (strategy_->FromV8Array(val, &out, isolate, callback)) | 394 if (strategy_->FromV8Array(val, &out, isolate, callback)) |
392 return out; | 395 return out; |
393 } | 396 } |
394 | 397 |
395 base::ListValue* result = new base::ListValue(); | 398 base::ListValue* result = new base::ListValue(); |
396 | 399 |
397 // Only fields with integer keys are carried over to the ListValue. | 400 // Only fields with integer keys are carried over to the ListValue. |
398 for (uint32 i = 0; i < val->Length(); ++i) { | 401 for (uint32_t i = 0; i < val->Length(); ++i) { |
399 v8::TryCatch try_catch(isolate); | 402 v8::TryCatch try_catch(isolate); |
400 v8::Local<v8::Value> child_v8 = val->Get(i); | 403 v8::Local<v8::Value> child_v8 = val->Get(i); |
401 if (try_catch.HasCaught()) { | 404 if (try_catch.HasCaught()) { |
402 LOG(ERROR) << "Getter for index " << i << " threw an exception."; | 405 LOG(ERROR) << "Getter for index " << i << " threw an exception."; |
403 child_v8 = v8::Null(isolate); | 406 child_v8 = v8::Null(isolate); |
404 } | 407 } |
405 | 408 |
406 if (!val->HasRealIndexedProperty(i)) { | 409 if (!val->HasRealIndexedProperty(i)) { |
407 result->Append(base::Value::CreateNullValue()); | 410 result->Append(base::Value::CreateNullValue()); |
408 continue; | 411 continue; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // do something else, such as convert to the node's name rather than NULL. | 492 // do something else, such as convert to the node's name rather than NULL. |
490 // | 493 // |
491 // ANOTHER NOTE: returning an empty dictionary here to minimise surprise. | 494 // ANOTHER NOTE: returning an empty dictionary here to minimise surprise. |
492 // See also http://crbug.com/330559. | 495 // See also http://crbug.com/330559. |
493 if (val->InternalFieldCount()) | 496 if (val->InternalFieldCount()) |
494 return new base::DictionaryValue(); | 497 return new base::DictionaryValue(); |
495 | 498 |
496 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 499 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
497 v8::Local<v8::Array> property_names(val->GetOwnPropertyNames()); | 500 v8::Local<v8::Array> property_names(val->GetOwnPropertyNames()); |
498 | 501 |
499 for (uint32 i = 0; i < property_names->Length(); ++i) { | 502 for (uint32_t i = 0; i < property_names->Length(); ++i) { |
500 v8::Local<v8::Value> key(property_names->Get(i)); | 503 v8::Local<v8::Value> key(property_names->Get(i)); |
501 | 504 |
502 // Extend this test to cover more types as necessary and if sensible. | 505 // Extend this test to cover more types as necessary and if sensible. |
503 if (!key->IsString() && | 506 if (!key->IsString() && |
504 !key->IsNumber()) { | 507 !key->IsNumber()) { |
505 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" " | 508 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" " |
506 "is neither a string nor a number"; | 509 "is neither a string nor a number"; |
507 continue; | 510 continue; |
508 } | 511 } |
509 | 512 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 continue; | 551 continue; |
549 | 552 |
550 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 553 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
551 child.release()); | 554 child.release()); |
552 } | 555 } |
553 | 556 |
554 return result.release(); | 557 return result.release(); |
555 } | 558 } |
556 | 559 |
557 } // namespace content | 560 } // namespace content |
OLD | NEW |