| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 256 } |
| 257 | 257 |
| 258 base::BinaryValue* V8ValueConverterImpl::FromV8Buffer( | 258 base::BinaryValue* V8ValueConverterImpl::FromV8Buffer( |
| 259 v8::Handle<v8::Value> val) const { | 259 v8::Handle<v8::Value> val) const { |
| 260 char* data = NULL; | 260 char* data = NULL; |
| 261 size_t length = 0; | 261 size_t length = 0; |
| 262 | 262 |
| 263 scoped_ptr<WebKit::WebArrayBuffer> array_buffer( | 263 scoped_ptr<WebKit::WebArrayBuffer> array_buffer( |
| 264 WebKit::WebArrayBuffer::createFromV8Value(val)); | 264 WebKit::WebArrayBuffer::createFromV8Value(val)); |
| 265 scoped_ptr<WebKit::WebArrayBufferView> view; | 265 scoped_ptr<WebKit::WebArrayBufferView> view; |
| 266 if (array_buffer.get()) { | 266 if (array_buffer) { |
| 267 data = reinterpret_cast<char*>(array_buffer->data()); | 267 data = reinterpret_cast<char*>(array_buffer->data()); |
| 268 length = array_buffer->byteLength(); | 268 length = array_buffer->byteLength(); |
| 269 } else { | 269 } else { |
| 270 view.reset(WebKit::WebArrayBufferView::createFromV8Value(val)); | 270 view.reset(WebKit::WebArrayBufferView::createFromV8Value(val)); |
| 271 if (view.get()) { | 271 if (view) { |
| 272 data = reinterpret_cast<char*>(view->baseAddress()) + view->byteOffset(); | 272 data = reinterpret_cast<char*>(view->baseAddress()) + view->byteOffset(); |
| 273 length = view->byteLength(); | 273 length = view->byteLength(); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 if (data) | 277 if (data) |
| 278 return base::BinaryValue::CreateWithCopiedBuffer(data, length); | 278 return base::BinaryValue::CreateWithCopiedBuffer(data, length); |
| 279 else | 279 else |
| 280 return NULL; | 280 return NULL; |
| 281 } | 281 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 v8::TryCatch try_catch; | 315 v8::TryCatch try_catch; |
| 316 v8::Handle<v8::Value> child_v8 = val->Get(key); | 316 v8::Handle<v8::Value> child_v8 = val->Get(key); |
| 317 | 317 |
| 318 if (try_catch.HasCaught()) { | 318 if (try_catch.HasCaught()) { |
| 319 LOG(ERROR) << "Getter for property " << *name_utf8 | 319 LOG(ERROR) << "Getter for property " << *name_utf8 |
| 320 << " threw an exception."; | 320 << " threw an exception."; |
| 321 child_v8 = v8::Null(); | 321 child_v8 = v8::Null(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 scoped_ptr<base::Value> child(FromV8ValueImpl(child_v8, unique_map)); | 324 scoped_ptr<base::Value> child(FromV8ValueImpl(child_v8, unique_map)); |
| 325 if (!child.get()) | 325 if (!child) |
| 326 // JSON.stringify skips properties whose values don't serialize, for | 326 // JSON.stringify skips properties whose values don't serialize, for |
| 327 // example undefined and functions. Emulate that behavior. | 327 // example undefined and functions. Emulate that behavior. |
| 328 continue; | 328 continue; |
| 329 | 329 |
| 330 // Strip null if asked (and since undefined is turned into null, undefined | 330 // Strip null if asked (and since undefined is turned into null, undefined |
| 331 // too). The use case for supporting this is JSON-schema support, | 331 // too). The use case for supporting this is JSON-schema support, |
| 332 // specifically for extensions, where "optional" JSON properties may be | 332 // specifically for extensions, where "optional" JSON properties may be |
| 333 // represented as null, yet due to buggy legacy code elsewhere isn't | 333 // represented as null, yet due to buggy legacy code elsewhere isn't |
| 334 // treated as such (potentially causing crashes). For example, the | 334 // treated as such (potentially causing crashes). For example, the |
| 335 // "tabs.create" function takes an object as its first argument with an | 335 // "tabs.create" function takes an object as its first argument with an |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // Operator == for handles actually compares the underlying objects. | 371 // Operator == for handles actually compares the underlying objects. |
| 372 if (it->second == handle) | 372 if (it->second == handle) |
| 373 return false; | 373 return false; |
| 374 } | 374 } |
| 375 | 375 |
| 376 map->insert(std::pair<int, v8::Handle<v8::Object> >(hash, handle)); | 376 map->insert(std::pair<int, v8::Handle<v8::Object> >(hash, handle)); |
| 377 return true; | 377 return true; |
| 378 } | 378 } |
| 379 | 379 |
| 380 } // namespace content | 380 } // namespace content |
| OLD | NEW |