| 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/renderer/v8_value_converter_impl.h" | 5 #include "content/renderer/v8_value_converter_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 bool V8ValueConverter::Strategy::FromV8Array( | 32 bool V8ValueConverter::Strategy::FromV8Array( |
| 33 v8::Handle<v8::Array> value, | 33 v8::Handle<v8::Array> value, |
| 34 base::Value** out, | 34 base::Value** out, |
| 35 v8::Isolate* isolate, | 35 v8::Isolate* isolate, |
| 36 const FromV8ValueCallback& callback) const { | 36 const FromV8ValueCallback& callback) const { |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool V8ValueConverter::Strategy::FromV8ArrayBuffer(v8::Handle<v8::Object> value, | 40 bool V8ValueConverter::Strategy::FromV8ArrayBuffer(v8::Handle<v8::Object> value, |
| 41 base::Value** out) const { | 41 base::Value** out, |
| 42 v8::Isolate* isolate) const { |
| 42 return false; | 43 return false; |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool V8ValueConverter::Strategy::FromV8Number(v8::Handle<v8::Number> value, | 46 bool V8ValueConverter::Strategy::FromV8Number(v8::Handle<v8::Number> value, |
| 46 base::Value** out) const { | 47 base::Value** out) const { |
| 47 return false; | 48 return false; |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool V8ValueConverter::Strategy::FromV8Undefined(base::Value** out) const { | 51 bool V8ValueConverter::Strategy::FromV8Undefined(base::Value** out) const { |
| 51 return false; | 52 return false; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return FromV8Array(val.As<v8::Array>(), state, isolate); | 336 return FromV8Array(val.As<v8::Array>(), state, isolate); |
| 336 | 337 |
| 337 if (val->IsFunction()) { | 338 if (val->IsFunction()) { |
| 338 if (!function_allowed_) | 339 if (!function_allowed_) |
| 339 // JSON.stringify refuses to convert function(){}. | 340 // JSON.stringify refuses to convert function(){}. |
| 340 return NULL; | 341 return NULL; |
| 341 return FromV8Object(val->ToObject(), state, isolate); | 342 return FromV8Object(val->ToObject(), state, isolate); |
| 342 } | 343 } |
| 343 | 344 |
| 344 if (val->IsArrayBuffer() || val->IsArrayBufferView()) | 345 if (val->IsArrayBuffer() || val->IsArrayBufferView()) |
| 345 return FromV8ArrayBuffer(val->ToObject()); | 346 return FromV8ArrayBuffer(val->ToObject(), isolate); |
| 346 | 347 |
| 347 if (val->IsObject()) | 348 if (val->IsObject()) |
| 348 return FromV8Object(val->ToObject(), state, isolate); | 349 return FromV8Object(val->ToObject(), state, isolate); |
| 349 | 350 |
| 350 LOG(ERROR) << "Unexpected v8 value type encountered."; | 351 LOG(ERROR) << "Unexpected v8 value type encountered."; |
| 351 return NULL; | 352 return NULL; |
| 352 } | 353 } |
| 353 | 354 |
| 354 base::Value* V8ValueConverterImpl::FromV8Array( | 355 base::Value* V8ValueConverterImpl::FromV8Array( |
| 355 v8::Handle<v8::Array> val, | 356 v8::Handle<v8::Array> val, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 result->Append(child); | 399 result->Append(child); |
| 399 else | 400 else |
| 400 // JSON.stringify puts null in places where values don't serialize, for | 401 // JSON.stringify puts null in places where values don't serialize, for |
| 401 // example undefined and functions. Emulate that behavior. | 402 // example undefined and functions. Emulate that behavior. |
| 402 result->Append(base::Value::CreateNullValue()); | 403 result->Append(base::Value::CreateNullValue()); |
| 403 } | 404 } |
| 404 return result; | 405 return result; |
| 405 } | 406 } |
| 406 | 407 |
| 407 base::Value* V8ValueConverterImpl::FromV8ArrayBuffer( | 408 base::Value* V8ValueConverterImpl::FromV8ArrayBuffer( |
| 408 v8::Handle<v8::Object> val) const { | 409 v8::Handle<v8::Object> val, |
| 410 v8::Isolate* isolate) const { |
| 409 if (strategy_) { | 411 if (strategy_) { |
| 410 base::Value* out = NULL; | 412 base::Value* out = NULL; |
| 411 if (strategy_->FromV8ArrayBuffer(val, &out)) | 413 if (strategy_->FromV8ArrayBuffer(val, &out, isolate)) |
| 412 return out; | 414 return out; |
| 413 } | 415 } |
| 414 | 416 |
| 415 char* data = NULL; | 417 char* data = NULL; |
| 416 size_t length = 0; | 418 size_t length = 0; |
| 417 | 419 |
| 418 scoped_ptr<blink::WebArrayBuffer> array_buffer( | 420 scoped_ptr<blink::WebArrayBuffer> array_buffer( |
| 419 blink::WebArrayBufferConverter::createFromV8Value(val)); | 421 blink::WebArrayBufferConverter::createFromV8Value(val)); |
| 420 scoped_ptr<blink::WebArrayBufferView> view; | 422 scoped_ptr<blink::WebArrayBufferView> view; |
| 421 if (array_buffer) { | 423 if (array_buffer) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 continue; | 534 continue; |
| 533 | 535 |
| 534 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 536 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
| 535 child.release()); | 537 child.release()); |
| 536 } | 538 } |
| 537 | 539 |
| 538 return result.release(); | 540 return result.release(); |
| 539 } | 541 } |
| 540 | 542 |
| 541 } // namespace content | 543 } // namespace content |
| OLD | NEW |