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 "bindings/core/v8/ScriptValueSerializer.h" | 5 #include "bindings/core/v8/ScriptValueSerializer.h" |
6 | 6 |
7 #include "bindings/core/v8/V8ArrayBuffer.h" | 7 #include "bindings/core/v8/V8ArrayBuffer.h" |
8 #include "bindings/core/v8/V8ArrayBufferView.h" | 8 #include "bindings/core/v8/V8ArrayBufferView.h" |
9 #include "bindings/core/v8/V8Blob.h" | 9 #include "bindings/core/v8/V8Blob.h" |
10 #include "bindings/core/v8/V8CompositorProxy.h" | 10 #include "bindings/core/v8/V8CompositorProxy.h" |
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 if (!doReadUint64(&element)) | 1650 if (!doReadUint64(&element)) |
1651 return false; | 1651 return false; |
1652 if (!doReadUint32(&attributes)) | 1652 if (!doReadUint32(&attributes)) |
1653 return false; | 1653 return false; |
1654 | 1654 |
1655 CompositorProxy* compositorProxy = CompositorProxy::create(element, attribut
es); | 1655 CompositorProxy* compositorProxy = CompositorProxy::create(element, attribut
es); |
1656 *value = toV8(compositorProxy, m_scriptState->context()->Global(), isolate()
); | 1656 *value = toV8(compositorProxy, m_scriptState->context()->Global(), isolate()
); |
1657 return !value->IsEmpty(); | 1657 return !value->IsEmpty(); |
1658 } | 1658 } |
1659 | 1659 |
1660 PassRefPtr<DOMArrayBuffer> SerializedScriptValueReader::doReadArrayBuffer() | 1660 DOMArrayBuffer* SerializedScriptValueReader::doReadArrayBuffer() |
1661 { | 1661 { |
1662 uint32_t byteLength; | 1662 uint32_t byteLength; |
1663 if (!doReadUint32(&byteLength)) | 1663 if (!doReadUint32(&byteLength)) |
1664 return nullptr; | 1664 return nullptr; |
1665 if (m_position + byteLength > m_length) | 1665 if (m_position + byteLength > m_length) |
1666 return nullptr; | 1666 return nullptr; |
1667 const void* bufferStart = m_buffer + m_position; | 1667 const void* bufferStart = m_buffer + m_position; |
1668 m_position += byteLength; | 1668 m_position += byteLength; |
1669 return DOMArrayBuffer::create(bufferStart, byteLength); | 1669 return DOMArrayBuffer::create(bufferStart, byteLength); |
1670 } | 1670 } |
1671 | 1671 |
1672 bool SerializedScriptValueReader::readArrayBuffer(v8::Local<v8::Value>* value) | 1672 bool SerializedScriptValueReader::readArrayBuffer(v8::Local<v8::Value>* value) |
1673 { | 1673 { |
1674 RefPtr<DOMArrayBuffer> arrayBuffer = doReadArrayBuffer(); | 1674 DOMArrayBuffer* arrayBuffer = doReadArrayBuffer(); |
1675 if (!arrayBuffer) | 1675 if (!arrayBuffer) |
1676 return false; | 1676 return false; |
1677 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), iso
late()); | 1677 *value = toV8(arrayBuffer, m_scriptState->context()->Global(), isolate()); |
1678 return !value->IsEmpty(); | 1678 return !value->IsEmpty(); |
1679 } | 1679 } |
1680 | 1680 |
1681 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu
e, ScriptValueCompositeCreator& creator) | 1681 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu
e, ScriptValueCompositeCreator& creator) |
1682 { | 1682 { |
1683 ArrayBufferViewSubTag subTag; | 1683 ArrayBufferViewSubTag subTag; |
1684 uint32_t byteOffset; | 1684 uint32_t byteOffset; |
1685 uint32_t byteLength; | 1685 uint32_t byteLength; |
1686 RefPtr<DOMArrayBufferBase> arrayBuffer; | 1686 DOMArrayBufferBase* arrayBuffer = nullptr; |
1687 v8::Local<v8::Value> arrayBufferV8Value; | 1687 v8::Local<v8::Value> arrayBufferV8Value; |
1688 if (!readArrayBufferViewSubTag(&subTag)) | 1688 if (!readArrayBufferViewSubTag(&subTag)) |
1689 return false; | 1689 return false; |
1690 if (!doReadUint32(&byteOffset)) | 1690 if (!doReadUint32(&byteOffset)) |
1691 return false; | 1691 return false; |
1692 if (!doReadUint32(&byteLength)) | 1692 if (!doReadUint32(&byteLength)) |
1693 return false; | 1693 return false; |
1694 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) | 1694 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) |
1695 return false; | 1695 return false; |
1696 if (arrayBufferV8Value.IsEmpty()) | 1696 if (arrayBufferV8Value.IsEmpty()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 const unsigned numElements = byteLength / elementByteSize; | 1746 const unsigned numElements = byteLength / elementByteSize; |
1747 const unsigned remainingElements = (arrayBuffer->byteLength() - byteOffset)
/ elementByteSize; | 1747 const unsigned remainingElements = (arrayBuffer->byteLength() - byteOffset)
/ elementByteSize; |
1748 if (byteOffset % elementByteSize | 1748 if (byteOffset % elementByteSize |
1749 || byteOffset > arrayBuffer->byteLength() | 1749 || byteOffset > arrayBuffer->byteLength() |
1750 || numElements > remainingElements) | 1750 || numElements > remainingElements) |
1751 return false; | 1751 return false; |
1752 | 1752 |
1753 v8::Local<v8::Object> creationContext = m_scriptState->context()->Global(); | 1753 v8::Local<v8::Object> creationContext = m_scriptState->context()->Global(); |
1754 switch (subTag) { | 1754 switch (subTag) { |
1755 case ByteArrayTag: | 1755 case ByteArrayTag: |
1756 *value = toV8(DOMInt8Array::create(arrayBuffer.release(), byteOffset, nu
mElements), creationContext, isolate()); | 1756 *value = toV8(DOMInt8Array::create(arrayBuffer, byteOffset, numElements)
, creationContext, isolate()); |
1757 break; | 1757 break; |
1758 case UnsignedByteArrayTag: | 1758 case UnsignedByteArrayTag: |
1759 *value = toV8(DOMUint8Array::create(arrayBuffer.release(), byteOffset, n
umElements), creationContext, isolate()); | 1759 *value = toV8(DOMUint8Array::create(arrayBuffer, byteOffset, numElements
), creationContext, isolate()); |
1760 break; | 1760 break; |
1761 case UnsignedByteClampedArrayTag: | 1761 case UnsignedByteClampedArrayTag: |
1762 *value = toV8(DOMUint8ClampedArray::create(arrayBuffer.release(), byteOf
fset, numElements), creationContext, isolate()); | 1762 *value = toV8(DOMUint8ClampedArray::create(arrayBuffer, byteOffset, numE
lements), creationContext, isolate()); |
1763 break; | 1763 break; |
1764 case ShortArrayTag: | 1764 case ShortArrayTag: |
1765 *value = toV8(DOMInt16Array::create(arrayBuffer.release(), byteOffset, n
umElements), creationContext, isolate()); | 1765 *value = toV8(DOMInt16Array::create(arrayBuffer, byteOffset, numElements
), creationContext, isolate()); |
1766 break; | 1766 break; |
1767 case UnsignedShortArrayTag: | 1767 case UnsignedShortArrayTag: |
1768 *value = toV8(DOMUint16Array::create(arrayBuffer.release(), byteOffset,
numElements), creationContext, isolate()); | 1768 *value = toV8(DOMUint16Array::create(arrayBuffer, byteOffset, numElement
s), creationContext, isolate()); |
1769 break; | 1769 break; |
1770 case IntArrayTag: | 1770 case IntArrayTag: |
1771 *value = toV8(DOMInt32Array::create(arrayBuffer.release(), byteOffset, n
umElements), creationContext, isolate()); | 1771 *value = toV8(DOMInt32Array::create(arrayBuffer, byteOffset, numElements
), creationContext, isolate()); |
1772 break; | 1772 break; |
1773 case UnsignedIntArrayTag: | 1773 case UnsignedIntArrayTag: |
1774 *value = toV8(DOMUint32Array::create(arrayBuffer.release(), byteOffset,
numElements), creationContext, isolate()); | 1774 *value = toV8(DOMUint32Array::create(arrayBuffer, byteOffset, numElement
s), creationContext, isolate()); |
1775 break; | 1775 break; |
1776 case FloatArrayTag: | 1776 case FloatArrayTag: |
1777 *value = toV8(DOMFloat32Array::create(arrayBuffer.release(), byteOffset,
numElements), creationContext, isolate()); | 1777 *value = toV8(DOMFloat32Array::create(arrayBuffer, byteOffset, numElemen
ts), creationContext, isolate()); |
1778 break; | 1778 break; |
1779 case DoubleArrayTag: | 1779 case DoubleArrayTag: |
1780 *value = toV8(DOMFloat64Array::create(arrayBuffer.release(), byteOffset,
numElements), creationContext, isolate()); | 1780 *value = toV8(DOMFloat64Array::create(arrayBuffer, byteOffset, numElemen
ts), creationContext, isolate()); |
1781 break; | 1781 break; |
1782 case DataViewTag: | 1782 case DataViewTag: |
1783 *value = toV8(DOMDataView::create(arrayBuffer.release(), byteOffset, byt
eLength), creationContext, isolate()); | 1783 *value = toV8(DOMDataView::create(arrayBuffer, byteOffset, byteLength),
creationContext, isolate()); |
1784 break; | 1784 break; |
1785 } | 1785 } |
1786 return !value->IsEmpty(); | 1786 return !value->IsEmpty(); |
1787 } | 1787 } |
1788 | 1788 |
1789 bool SerializedScriptValueReader::readRegExp(v8::Local<v8::Value>* value) | 1789 bool SerializedScriptValueReader::readRegExp(v8::Local<v8::Value>* value) |
1790 { | 1790 { |
1791 v8::Local<v8::Value> pattern; | 1791 v8::Local<v8::Value> pattern; |
1792 if (!readString(&pattern)) | 1792 if (!readString(&pattern)) |
1793 return false; | 1793 return false; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 } | 2147 } |
2148 | 2148 |
2149 bool ScriptValueDeserializer::tryGetTransferredArrayBuffer(uint32_t index, v8::L
ocal<v8::Value>* object) | 2149 bool ScriptValueDeserializer::tryGetTransferredArrayBuffer(uint32_t index, v8::L
ocal<v8::Value>* object) |
2150 { | 2150 { |
2151 if (!m_arrayBufferContents) | 2151 if (!m_arrayBufferContents) |
2152 return false; | 2152 return false; |
2153 if (index >= m_arrayBuffers.size()) | 2153 if (index >= m_arrayBuffers.size()) |
2154 return false; | 2154 return false; |
2155 v8::Local<v8::Value> result = m_arrayBuffers.at(index); | 2155 v8::Local<v8::Value> result = m_arrayBuffers.at(index); |
2156 if (result.IsEmpty()) { | 2156 if (result.IsEmpty()) { |
2157 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(m_arrayBufferCont
ents->at(index)); | 2157 DOMArrayBuffer* buffer = DOMArrayBuffer::create(m_arrayBufferContents->a
t(index)); |
2158 v8::Isolate* isolate = m_reader.getScriptState()->isolate(); | 2158 v8::Isolate* isolate = m_reader.getScriptState()->isolate(); |
2159 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); | 2159 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); |
2160 result = toV8(buffer.get(), creationContext, isolate); | 2160 result = toV8(buffer, creationContext, isolate); |
2161 if (result.IsEmpty()) | 2161 if (result.IsEmpty()) |
2162 return false; | 2162 return false; |
2163 m_arrayBuffers[index] = result; | 2163 m_arrayBuffers[index] = result; |
2164 } | 2164 } |
2165 *object = result; | 2165 *object = result; |
2166 return true; | 2166 return true; |
2167 } | 2167 } |
2168 | 2168 |
2169 bool ScriptValueDeserializer::tryGetTransferredImageBitmap(uint32_t index, v8::L
ocal<v8::Value>* object) | 2169 bool ScriptValueDeserializer::tryGetTransferredImageBitmap(uint32_t index, v8::L
ocal<v8::Value>* object) |
2170 { | 2170 { |
(...skipping 17 matching lines...) Expand all Loading... |
2188 | 2188 |
2189 bool ScriptValueDeserializer::tryGetTransferredSharedArrayBuffer(uint32_t index,
v8::Local<v8::Value>* object) | 2189 bool ScriptValueDeserializer::tryGetTransferredSharedArrayBuffer(uint32_t index,
v8::Local<v8::Value>* object) |
2190 { | 2190 { |
2191 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | 2191 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
2192 if (!m_arrayBufferContents) | 2192 if (!m_arrayBufferContents) |
2193 return false; | 2193 return false; |
2194 if (index >= m_arrayBuffers.size()) | 2194 if (index >= m_arrayBuffers.size()) |
2195 return false; | 2195 return false; |
2196 v8::Local<v8::Value> result = m_arrayBuffers.at(index); | 2196 v8::Local<v8::Value> result = m_arrayBuffers.at(index); |
2197 if (result.IsEmpty()) { | 2197 if (result.IsEmpty()) { |
2198 RefPtr<DOMSharedArrayBuffer> buffer = DOMSharedArrayBuffer::create(m_arr
ayBufferContents->at(index)); | 2198 DOMSharedArrayBuffer* buffer = DOMSharedArrayBuffer::create(m_arrayBuffe
rContents->at(index)); |
2199 v8::Isolate* isolate = m_reader.getScriptState()->isolate(); | 2199 v8::Isolate* isolate = m_reader.getScriptState()->isolate(); |
2200 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); | 2200 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->conte
xt()->Global(); |
2201 result = toV8(buffer.get(), creationContext, isolate); | 2201 result = toV8(buffer, creationContext, isolate); |
2202 if (result.IsEmpty()) | 2202 if (result.IsEmpty()) |
2203 return false; | 2203 return false; |
2204 m_arrayBuffers[index] = result; | 2204 m_arrayBuffers[index] = result; |
2205 } | 2205 } |
2206 *object = result; | 2206 *object = result; |
2207 return true; | 2207 return true; |
2208 } | 2208 } |
2209 | 2209 |
2210 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) | 2210 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) |
2211 { | 2211 { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 return false; | 2278 return false; |
2279 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 2279 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
2280 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 2280 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
2281 if (objectReference >= m_objectPool.size()) | 2281 if (objectReference >= m_objectPool.size()) |
2282 return false; | 2282 return false; |
2283 *object = m_objectPool[objectReference]; | 2283 *object = m_objectPool[objectReference]; |
2284 return true; | 2284 return true; |
2285 } | 2285 } |
2286 | 2286 |
2287 } // namespace blink | 2287 } // namespace blink |
OLD | NEW |