| 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 <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 FromV8ValueState* state, | 286 FromV8ValueState* state, |
| 287 v8::Local<v8::Value> val, | 287 v8::Local<v8::Value> val, |
| 288 v8::Isolate* isolate) const { | 288 v8::Isolate* isolate) const { |
| 289 CHECK(!val.IsEmpty()); | 289 CHECK(!val.IsEmpty()); |
| 290 | 290 |
| 291 FromV8ValueState::Level state_level(state); | 291 FromV8ValueState::Level state_level(state); |
| 292 if (state->HasReachedMaxRecursionDepth()) | 292 if (state->HasReachedMaxRecursionDepth()) |
| 293 return NULL; | 293 return NULL; |
| 294 | 294 |
| 295 if (val->IsNull()) | 295 if (val->IsNull()) |
| 296 return base::Value::CreateNullValue(); | 296 return base::Value::CreateNullValue().release(); |
| 297 | 297 |
| 298 if (val->IsBoolean()) | 298 if (val->IsBoolean()) |
| 299 return new base::FundamentalValue(val->ToBoolean(isolate)->Value()); | 299 return new base::FundamentalValue(val->ToBoolean(isolate)->Value()); |
| 300 | 300 |
| 301 if (val->IsNumber() && strategy_) { | 301 if (val->IsNumber() && strategy_) { |
| 302 base::Value* out = NULL; | 302 base::Value* out = NULL; |
| 303 if (strategy_->FromV8Number(val.As<v8::Number>(), &out)) | 303 if (strategy_->FromV8Number(val.As<v8::Number>(), &out)) |
| 304 return out; | 304 return out; |
| 305 } | 305 } |
| 306 | 306 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 LOG(ERROR) << "Unexpected v8 value type encountered."; | 365 LOG(ERROR) << "Unexpected v8 value type encountered."; |
| 366 return NULL; | 366 return NULL; |
| 367 } | 367 } |
| 368 | 368 |
| 369 base::Value* V8ValueConverterImpl::FromV8Array( | 369 base::Value* V8ValueConverterImpl::FromV8Array( |
| 370 v8::Local<v8::Array> val, | 370 v8::Local<v8::Array> val, |
| 371 FromV8ValueState* state, | 371 FromV8ValueState* state, |
| 372 v8::Isolate* isolate) const { | 372 v8::Isolate* isolate) const { |
| 373 if (!state->UpdateAndCheckUniqueness(val)) | 373 if (!state->UpdateAndCheckUniqueness(val)) |
| 374 return base::Value::CreateNullValue(); | 374 return base::Value::CreateNullValue().release(); |
| 375 | 375 |
| 376 scoped_ptr<v8::Context::Scope> scope; | 376 scoped_ptr<v8::Context::Scope> scope; |
| 377 // If val was created in a different context than our current one, change to | 377 // If val was created in a different context than our current one, change to |
| 378 // that context, but change back after val is converted. | 378 // that context, but change back after val is converted. |
| 379 if (!val->CreationContext().IsEmpty() && | 379 if (!val->CreationContext().IsEmpty() && |
| 380 val->CreationContext() != isolate->GetCurrentContext()) | 380 val->CreationContext() != isolate->GetCurrentContext()) |
| 381 scope.reset(new v8::Context::Scope(val->CreationContext())); | 381 scope.reset(new v8::Context::Scope(val->CreationContext())); |
| 382 | 382 |
| 383 if (strategy_) { | 383 if (strategy_) { |
| 384 // These base::Unretained's are safe, because Strategy::FromV8Value should | 384 // These base::Unretained's are safe, because Strategy::FromV8Value should |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 return base::BinaryValue::CreateWithCopiedBuffer(data, length); | 449 return base::BinaryValue::CreateWithCopiedBuffer(data, length); |
| 450 else | 450 else |
| 451 return NULL; | 451 return NULL; |
| 452 } | 452 } |
| 453 | 453 |
| 454 base::Value* V8ValueConverterImpl::FromV8Object( | 454 base::Value* V8ValueConverterImpl::FromV8Object( |
| 455 v8::Local<v8::Object> val, | 455 v8::Local<v8::Object> val, |
| 456 FromV8ValueState* state, | 456 FromV8ValueState* state, |
| 457 v8::Isolate* isolate) const { | 457 v8::Isolate* isolate) const { |
| 458 if (!state->UpdateAndCheckUniqueness(val)) | 458 if (!state->UpdateAndCheckUniqueness(val)) |
| 459 return base::Value::CreateNullValue(); | 459 return base::Value::CreateNullValue().release(); |
| 460 | 460 |
| 461 scoped_ptr<v8::Context::Scope> scope; | 461 scoped_ptr<v8::Context::Scope> scope; |
| 462 // If val was created in a different context than our current one, change to | 462 // If val was created in a different context than our current one, change to |
| 463 // that context, but change back after val is converted. | 463 // that context, but change back after val is converted. |
| 464 if (!val->CreationContext().IsEmpty() && | 464 if (!val->CreationContext().IsEmpty() && |
| 465 val->CreationContext() != isolate->GetCurrentContext()) | 465 val->CreationContext() != isolate->GetCurrentContext()) |
| 466 scope.reset(new v8::Context::Scope(val->CreationContext())); | 466 scope.reset(new v8::Context::Scope(val->CreationContext())); |
| 467 | 467 |
| 468 if (strategy_) { | 468 if (strategy_) { |
| 469 // These base::Unretained's are safe, because Strategy::FromV8Value should | 469 // These base::Unretained's are safe, because Strategy::FromV8Value should |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 continue; | 548 continue; |
| 549 | 549 |
| 550 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 550 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
| 551 child.release()); | 551 child.release()); |
| 552 } | 552 } |
| 553 | 553 |
| 554 return result.release(); | 554 return result.release(); |
| 555 } | 555 } |
| 556 | 556 |
| 557 } // namespace content | 557 } // namespace content |
| OLD | NEW |