| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptValueSerializer.h" | 6 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Blob.h" | 10 #include "bindings/core/v8/V8Blob.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 void SerializedScriptValueWriter::writeDenseArray(uint32_t numProperties, uint32
_t length) | 332 void SerializedScriptValueWriter::writeDenseArray(uint32_t numProperties, uint32
_t length) |
| 333 { | 333 { |
| 334 append(DenseArrayTag); | 334 append(DenseArrayTag); |
| 335 doWriteUint32(numProperties); | 335 doWriteUint32(numProperties); |
| 336 doWriteUint32(length); | 336 doWriteUint32(length); |
| 337 } | 337 } |
| 338 | 338 |
| 339 String SerializedScriptValueWriter::takeWireString() | 339 String SerializedScriptValueWriter::takeWireString() |
| 340 { | 340 { |
| 341 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 341 static_assert(sizeof(BufferValueType) == 2, "BufferValueType should be 2 byt
es"); |
| 342 fillHole(); | 342 fillHole(); |
| 343 String data = String(m_buffer.data(), m_buffer.size()); | 343 String data = String(m_buffer.data(), m_buffer.size()); |
| 344 data.impl()->truncateAssumingIsolated((m_position + 1) / sizeof(BufferValueT
ype)); | 344 data.impl()->truncateAssumingIsolated((m_position + 1) / sizeof(BufferValueT
ype)); |
| 345 return data; | 345 return data; |
| 346 } | 346 } |
| 347 | 347 |
| 348 void SerializedScriptValueWriter::writeReferenceCount(uint32_t numberOfReference
s) | 348 void SerializedScriptValueWriter::writeReferenceCount(uint32_t numberOfReference
s) |
| 349 { | 349 { |
| 350 append(ReferenceCountTag); | 350 append(ReferenceCountTag); |
| 351 doWriteUint32(numberOfReferences); | 351 doWriteUint32(numberOfReferences); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 void SerializedScriptValueWriter::append(const uint8_t* data, int length) | 453 void SerializedScriptValueWriter::append(const uint8_t* data, int length) |
| 454 { | 454 { |
| 455 ensureSpace(length); | 455 ensureSpace(length); |
| 456 memcpy(byteAt(m_position), data, length); | 456 memcpy(byteAt(m_position), data, length); |
| 457 m_position += length; | 457 m_position += length; |
| 458 } | 458 } |
| 459 | 459 |
| 460 void SerializedScriptValueWriter::ensureSpace(unsigned extra) | 460 void SerializedScriptValueWriter::ensureSpace(unsigned extra) |
| 461 { | 461 { |
| 462 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 462 static_assert(sizeof(BufferValueType) == 2, "BufferValueType should be 2 byt
es"); |
| 463 m_buffer.resize((m_position + extra + 1) / sizeof(BufferValueType)); // "+ 1
" to round up. | 463 m_buffer.resize((m_position + extra + 1) / sizeof(BufferValueType)); // "+ 1
" to round up. |
| 464 } | 464 } |
| 465 | 465 |
| 466 void SerializedScriptValueWriter::fillHole() | 466 void SerializedScriptValueWriter::fillHole() |
| 467 { | 467 { |
| 468 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 468 static_assert(sizeof(BufferValueType) == 2, "BufferValueType should be 2 byt
es"); |
| 469 // If the writer is at odd position in the buffer, then one of | 469 // If the writer is at odd position in the buffer, then one of |
| 470 // the bytes in the last UChar is not initialized. | 470 // the bytes in the last UChar is not initialized. |
| 471 if (m_position % 2) | 471 if (m_position % 2) |
| 472 *byteAt(m_position) = static_cast<uint8_t>(PaddingTag); | 472 *byteAt(m_position) = static_cast<uint8_t>(PaddingTag); |
| 473 } | 473 } |
| 474 | 474 |
| 475 uint8_t* SerializedScriptValueWriter::byteAt(int position) | 475 uint8_t* SerializedScriptValueWriter::byteAt(int position) |
| 476 { | 476 { |
| 477 return reinterpret_cast<uint8_t*>(m_buffer.data()) + position; | 477 return reinterpret_cast<uint8_t*>(m_buffer.data()) + position; |
| 478 } | 478 } |
| (...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 return false; | 1877 return false; |
| 1878 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 1878 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
| 1879 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 1879 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
| 1880 if (objectReference >= m_objectPool.size()) | 1880 if (objectReference >= m_objectPool.size()) |
| 1881 return false; | 1881 return false; |
| 1882 *object = m_objectPool[objectReference]; | 1882 *object = m_objectPool[objectReference]; |
| 1883 return true; | 1883 return true; |
| 1884 } | 1884 } |
| 1885 | 1885 |
| 1886 } // namespace blink | 1886 } // namespace blink |
| OLD | NEW |