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" |
11 #include "bindings/core/v8/V8CompositorProxy.h" | 11 #include "bindings/core/v8/V8CompositorProxy.h" |
12 #include "bindings/core/v8/V8File.h" | 12 #include "bindings/core/v8/V8File.h" |
13 #include "bindings/core/v8/V8FileList.h" | 13 #include "bindings/core/v8/V8FileList.h" |
14 #include "bindings/core/v8/V8ImageData.h" | 14 #include "bindings/core/v8/V8ImageData.h" |
15 #include "bindings/core/v8/V8MessagePort.h" | 15 #include "bindings/core/v8/V8MessagePort.h" |
| 16 #include "bindings/core/v8/V8SharedArrayBuffer.h" |
16 #include "core/dom/CompositorProxy.h" | 17 #include "core/dom/CompositorProxy.h" |
17 #include "core/dom/DOMDataView.h" | 18 #include "core/dom/DOMDataView.h" |
| 19 #include "core/dom/DOMSharedArrayBuffer.h" |
| 20 #include "core/dom/DOMTypedArray.h" |
18 #include "core/fileapi/Blob.h" | 21 #include "core/fileapi/Blob.h" |
19 #include "core/fileapi/File.h" | 22 #include "core/fileapi/File.h" |
20 #include "core/fileapi/FileList.h" | 23 #include "core/fileapi/FileList.h" |
| 24 #include "platform/RuntimeEnabledFeatures.h" |
21 #include "public/platform/Platform.h" | 25 #include "public/platform/Platform.h" |
22 #include "public/platform/WebBlobInfo.h" | 26 #include "public/platform/WebBlobInfo.h" |
23 #include "wtf/DateMath.h" | 27 #include "wtf/DateMath.h" |
24 #include "wtf/text/StringHash.h" | 28 #include "wtf/text/StringHash.h" |
25 #include "wtf/text/StringUTF8Adaptor.h" | 29 #include "wtf/text/StringUTF8Adaptor.h" |
26 | 30 |
27 // FIXME: consider crashing in debug mode on deserialization errors | 31 // FIXME: consider crashing in debug mode on deserialization errors |
28 // NOTE: be sure to change wireFormatVersion as necessary! | 32 // NOTE: be sure to change wireFormatVersion as necessary! |
29 | 33 |
30 namespace blink { | 34 namespace blink { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 void SerializedScriptValueWriter::writeArrayBuffer(const DOMArrayBuffer& arrayBu
ffer) | 244 void SerializedScriptValueWriter::writeArrayBuffer(const DOMArrayBuffer& arrayBu
ffer) |
241 { | 245 { |
242 append(ArrayBufferTag); | 246 append(ArrayBufferTag); |
243 doWriteArrayBuffer(arrayBuffer); | 247 doWriteArrayBuffer(arrayBuffer); |
244 } | 248 } |
245 | 249 |
246 void SerializedScriptValueWriter::writeArrayBufferView(const DOMArrayBufferView&
arrayBufferView) | 250 void SerializedScriptValueWriter::writeArrayBufferView(const DOMArrayBufferView&
arrayBufferView) |
247 { | 251 { |
248 append(ArrayBufferViewTag); | 252 append(ArrayBufferViewTag); |
249 #if ENABLE(ASSERT) | 253 #if ENABLE(ASSERT) |
250 const DOMArrayBuffer& arrayBuffer = *arrayBufferView.buffer(); | 254 ASSERT(static_cast<const uint8_t*>(arrayBufferView.bufferBase()->data()) + a
rrayBufferView.byteOffset() == |
251 ASSERT(static_cast<const uint8_t*>(arrayBuffer.data()) + arrayBufferView.byt
eOffset() == | |
252 static_cast<const uint8_t*>(arrayBufferView.baseAddress())); | 255 static_cast<const uint8_t*>(arrayBufferView.baseAddress())); |
253 #endif | 256 #endif |
254 DOMArrayBufferView::ViewType type = arrayBufferView.type(); | 257 DOMArrayBufferView::ViewType type = arrayBufferView.type(); |
255 | 258 |
256 switch (type) { | 259 switch (type) { |
257 case DOMArrayBufferView::TypeInt8: | 260 case DOMArrayBufferView::TypeInt8: |
258 append(ByteArrayTag); | 261 append(ByteArrayTag); |
259 break; | 262 break; |
260 case DOMArrayBufferView::TypeUint8Clamped: | 263 case DOMArrayBufferView::TypeUint8Clamped: |
261 append(UnsignedByteClampedArrayTag); | 264 append(UnsignedByteClampedArrayTag); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 append(MessagePortTag); | 316 append(MessagePortTag); |
314 doWriteUint32(index); | 317 doWriteUint32(index); |
315 } | 318 } |
316 | 319 |
317 void SerializedScriptValueWriter::writeTransferredArrayBuffer(uint32_t index) | 320 void SerializedScriptValueWriter::writeTransferredArrayBuffer(uint32_t index) |
318 { | 321 { |
319 append(ArrayBufferTransferTag); | 322 append(ArrayBufferTransferTag); |
320 doWriteUint32(index); | 323 doWriteUint32(index); |
321 } | 324 } |
322 | 325 |
| 326 void SerializedScriptValueWriter::writeTransferredSharedArrayBuffer(uint32_t ind
ex) |
| 327 { |
| 328 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
| 329 append(SharedArrayBufferTransferTag); |
| 330 doWriteUint32(index); |
| 331 } |
| 332 |
323 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) | 333 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) |
324 { | 334 { |
325 append(ObjectReferenceTag); | 335 append(ObjectReferenceTag); |
326 doWriteUint32(reference); | 336 doWriteUint32(reference); |
327 } | 337 } |
328 | 338 |
329 void SerializedScriptValueWriter::writeObject(uint32_t numProperties) | 339 void SerializedScriptValueWriter::writeObject(uint32_t numProperties) |
330 { | 340 { |
331 append(ObjectTag); | 341 append(ObjectTag); |
332 doWriteUint32(numProperties); | 342 doWriteUint32(numProperties); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 { | 630 { |
621 if (!impl) | 631 if (!impl) |
622 return v8::Local<v8::Object>(); | 632 return v8::Local<v8::Object>(); |
623 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); | 633 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); |
624 if (wrapper.IsEmpty()) | 634 if (wrapper.IsEmpty()) |
625 return v8::Local<v8::Object>(); | 635 return v8::Local<v8::Object>(); |
626 ASSERT(wrapper->IsObject()); | 636 ASSERT(wrapper->IsObject()); |
627 return wrapper.As<v8::Object>(); | 637 return wrapper.As<v8::Object>(); |
628 } | 638 } |
629 | 639 |
630 static v8::Local<v8::ArrayBuffer> toV8Object(DOMArrayBuffer* impl, v8::Local<v8:
:Object> creationContext, v8::Isolate* isolate) | 640 static v8::Local<v8::Object> toV8Object(DOMArrayBufferBase* impl, v8::Local<v8::
Object> creationContext, v8::Isolate* isolate) |
631 { | 641 { |
632 if (!impl) | 642 if (!impl) |
633 return v8::Local<v8::ArrayBuffer>(); | 643 return v8::Local<v8::Object>(); |
634 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); | 644 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); |
635 if (wrapper.IsEmpty()) | 645 if (wrapper.IsEmpty()) |
636 return v8::Local<v8::ArrayBuffer>(); | 646 return v8::Local<v8::Object>(); |
637 ASSERT(wrapper->IsArrayBuffer()); | 647 return wrapper.As<v8::Object>(); |
638 return wrapper.As<v8::ArrayBuffer>(); | |
639 } | 648 } |
640 | 649 |
641 // Returns true if the provided object is to be considered a 'host object', as u
sed in the | 650 // Returns true if the provided object is to be considered a 'host object', as u
sed in the |
642 // HTML5 structured clone algorithm. | 651 // HTML5 structured clone algorithm. |
643 static bool isHostObject(v8::Local<v8::Object> object) | 652 static bool isHostObject(v8::Local<v8::Object> object) |
644 { | 653 { |
645 // If the object has any internal fields, then we won't be able to serialize
or deserialize | 654 // If the object has any internal fields, then we won't be able to serialize
or deserialize |
646 // them; conveniently, this is also a quick way to detect DOM wrapper object
s, because | 655 // them; conveniently, this is also a quick way to detect DOM wrapper object
s, because |
647 // the mechanism for these relies on data stored in these fields. We should | 656 // the mechanism for these relies on data stored in these fields. We should |
648 // catch external array data as a special case. | 657 // catch external array data as a special case. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 writeString(value); | 735 writeString(value); |
727 } else if (V8MessagePort::hasInstance(value, isolate())) { | 736 } else if (V8MessagePort::hasInstance(value, isolate())) { |
728 uint32_t messagePortIndex; | 737 uint32_t messagePortIndex; |
729 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor
tIndex)) { | 738 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor
tIndex)) { |
730 m_writer.writeTransferredMessagePort(messagePortIndex); | 739 m_writer.writeTransferredMessagePort(messagePortIndex); |
731 } else { | 740 } else { |
732 return handleError(DataCloneError, "A MessagePort could not be clone
d.", next); | 741 return handleError(DataCloneError, "A MessagePort could not be clone
d.", next); |
733 } | 742 } |
734 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra
yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { | 743 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra
yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { |
735 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); | 744 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); |
| 745 } else if (V8SharedArrayBuffer::hasInstance(value, isolate()) && m_transferr
edArrayBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { |
| 746 return writeTransferredSharedArrayBuffer(value, arrayBufferIndex, next); |
736 } else { | 747 } else { |
737 v8::Local<v8::Object> jsObject = value.As<v8::Object>(); | 748 v8::Local<v8::Object> jsObject = value.As<v8::Object>(); |
738 if (jsObject.IsEmpty()) | 749 if (jsObject.IsEmpty()) |
739 return handleError(DataCloneError, "An object could not be cloned.",
next); | 750 return handleError(DataCloneError, "An object could not be cloned.",
next); |
740 greyObject(jsObject); | 751 greyObject(jsObject); |
741 if (value->IsDate()) { | 752 if (value->IsDate()) { |
742 m_writer.writeDate(value.As<v8::Date>()->ValueOf()); | 753 m_writer.writeDate(value.As<v8::Date>()->ValueOf()); |
743 } else if (value->IsStringObject()) { | 754 } else if (value->IsStringObject()) { |
744 writeStringObject(value); | 755 writeStringObject(value); |
745 } else if (value->IsNumberObject()) { | 756 } else if (value->IsNumberObject()) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); | 971 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); |
961 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); | 972 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); |
962 } | 973 } |
963 | 974 |
964 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeAndGreyArrayBuffer
View(v8::Local<v8::Object> object, ScriptValueSerializer::StateBase* next) | 975 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeAndGreyArrayBuffer
View(v8::Local<v8::Object> object, ScriptValueSerializer::StateBase* next) |
965 { | 976 { |
966 ASSERT(!object.IsEmpty()); | 977 ASSERT(!object.IsEmpty()); |
967 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); | 978 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); |
968 if (!arrayBufferView) | 979 if (!arrayBufferView) |
969 return 0; | 980 return 0; |
970 if (!arrayBufferView->buffer()) | 981 if (!arrayBufferView->bufferBase()) |
971 return handleError(DataCloneError, "An ArrayBuffer could not be cloned."
, next); | 982 return handleError(DataCloneError, "An ArrayBuffer could not be cloned."
, next); |
972 v8::Local<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_sc
riptState->context()->Global(), isolate()); | 983 v8::Local<v8::Value> underlyingBuffer = toV8(arrayBufferView->bufferBase(),
m_scriptState->context()->Global(), isolate()); |
973 if (underlyingBuffer.IsEmpty()) | 984 if (underlyingBuffer.IsEmpty()) |
974 return handleError(DataCloneError, "An ArrayBuffer could not be cloned."
, next); | 985 return handleError(DataCloneError, "An ArrayBuffer could not be cloned."
, next); |
975 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); | 986 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); |
976 if (stateOut) | 987 if (stateOut) |
977 return stateOut; | 988 return stateOut; |
978 m_writer.writeArrayBufferView(*arrayBufferView); | 989 m_writer.writeArrayBufferView(*arrayBufferView); |
979 // This should be safe: we serialize something that we know to be a wrapper
(see | 990 // This should be safe: we serialize something that we know to be a wrapper
(see |
980 // the toV8 call above), so the call to doSerializeArrayBuffer should neithe
r | 991 // the toV8 call above), so the call to doSerializeArrayBuffer should neithe
r |
981 // cause the system stack to overflow nor should it have potential to reach | 992 // cause the system stack to overflow nor should it have potential to reach |
982 // this ArrayBufferView again. | 993 // this ArrayBufferView again. |
(...skipping 23 matching lines...) Expand all Loading... |
1006 { | 1017 { |
1007 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()); | 1018 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()); |
1008 if (!arrayBuffer) | 1019 if (!arrayBuffer) |
1009 return 0; | 1020 return 0; |
1010 if (arrayBuffer->isNeutered()) | 1021 if (arrayBuffer->isNeutered()) |
1011 return handleError(DataCloneError, "An ArrayBuffer is neutered and could
not be cloned.", next); | 1022 return handleError(DataCloneError, "An ArrayBuffer is neutered and could
not be cloned.", next); |
1012 m_writer.writeTransferredArrayBuffer(index); | 1023 m_writer.writeTransferredArrayBuffer(index); |
1013 return 0; | 1024 return 0; |
1014 } | 1025 } |
1015 | 1026 |
| 1027 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredSharedA
rrayBuffer(v8::Local<v8::Value> value, uint32_t index, ScriptValueSerializer::St
ateBase* next) |
| 1028 { |
| 1029 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
| 1030 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl(value.
As<v8::Object>()); |
| 1031 if (!sharedArrayBuffer) |
| 1032 return 0; |
| 1033 m_writer.writeTransferredSharedArrayBuffer(index); |
| 1034 return 0; |
| 1035 } |
| 1036 |
1016 bool ScriptValueSerializer::shouldSerializeDensely(uint32_t length, uint32_t pro
pertyCount) | 1037 bool ScriptValueSerializer::shouldSerializeDensely(uint32_t length, uint32_t pro
pertyCount) |
1017 { | 1038 { |
1018 // Let K be the cost of serializing all property values that are there | 1039 // Let K be the cost of serializing all property values that are there |
1019 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32_t k
ey) | 1040 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32_t k
ey) |
1020 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte for a
ll properties that are not there) | 1041 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte for a
ll properties that are not there) |
1021 // so densely is better than sparsly whenever 6*propertyCount > length | 1042 // so densely is better than sparsly whenever 6*propertyCount > length |
1022 return 6 * propertyCount >= length; | 1043 return 6 * propertyCount >= length; |
1023 } | 1044 } |
1024 | 1045 |
1025 ScriptValueSerializer::StateBase* ScriptValueSerializer::startArrayState(v8::Loc
al<v8::Array> array, ScriptValueSerializer::StateBase* next) | 1046 ScriptValueSerializer::StateBase* ScriptValueSerializer::startArrayState(v8::Loc
al<v8::Array> array, ScriptValueSerializer::StateBase* next) |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 case ArrayBufferTransferTag: { | 1345 case ArrayBufferTransferTag: { |
1325 if (!m_version) | 1346 if (!m_version) |
1326 return false; | 1347 return false; |
1327 uint32_t index; | 1348 uint32_t index; |
1328 if (!doReadUint32(&index)) | 1349 if (!doReadUint32(&index)) |
1329 return false; | 1350 return false; |
1330 if (!creator.tryGetTransferredArrayBuffer(index, value)) | 1351 if (!creator.tryGetTransferredArrayBuffer(index, value)) |
1331 return false; | 1352 return false; |
1332 break; | 1353 break; |
1333 } | 1354 } |
| 1355 case SharedArrayBufferTransferTag: { |
| 1356 if (!m_version) |
| 1357 return false; |
| 1358 uint32_t index; |
| 1359 if (!doReadUint32(&index)) |
| 1360 return false; |
| 1361 if (!creator.tryGetTransferredSharedArrayBuffer(index, value)) |
| 1362 return false; |
| 1363 break; |
| 1364 } |
1334 case ObjectReferenceTag: { | 1365 case ObjectReferenceTag: { |
1335 if (!m_version) | 1366 if (!m_version) |
1336 return false; | 1367 return false; |
1337 uint32_t reference; | 1368 uint32_t reference; |
1338 if (!doReadUint32(&reference)) | 1369 if (!doReadUint32(&reference)) |
1339 return false; | 1370 return false; |
1340 if (!creator.tryGetObjectFromObjectReference(reference, value)) | 1371 if (!creator.tryGetObjectFromObjectReference(reference, value)) |
1341 return false; | 1372 return false; |
1342 break; | 1373 break; |
1343 } | 1374 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 return false; | 1576 return false; |
1546 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), iso
late()); | 1577 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), iso
late()); |
1547 return !value->IsEmpty(); | 1578 return !value->IsEmpty(); |
1548 } | 1579 } |
1549 | 1580 |
1550 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu
e, ScriptValueCompositeCreator& creator) | 1581 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu
e, ScriptValueCompositeCreator& creator) |
1551 { | 1582 { |
1552 ArrayBufferViewSubTag subTag; | 1583 ArrayBufferViewSubTag subTag; |
1553 uint32_t byteOffset; | 1584 uint32_t byteOffset; |
1554 uint32_t byteLength; | 1585 uint32_t byteLength; |
1555 RefPtr<DOMArrayBuffer> arrayBuffer; | 1586 RefPtr<DOMArrayBufferBase> arrayBuffer; |
1556 v8::Local<v8::Value> arrayBufferV8Value; | 1587 v8::Local<v8::Value> arrayBufferV8Value; |
1557 if (!readArrayBufferViewSubTag(&subTag)) | 1588 if (!readArrayBufferViewSubTag(&subTag)) |
1558 return false; | 1589 return false; |
1559 if (!doReadUint32(&byteOffset)) | 1590 if (!doReadUint32(&byteOffset)) |
1560 return false; | 1591 return false; |
1561 if (!doReadUint32(&byteLength)) | 1592 if (!doReadUint32(&byteLength)) |
1562 return false; | 1593 return false; |
1563 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) | 1594 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) |
1564 return false; | 1595 return false; |
1565 if (arrayBufferV8Value.IsEmpty()) | 1596 if (arrayBufferV8Value.IsEmpty()) |
1566 return false; | 1597 return false; |
1567 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()); | 1598 if (arrayBufferV8Value->IsArrayBuffer()) { |
1568 if (!arrayBuffer) | 1599 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>())
; |
1569 return false; | 1600 if (!arrayBuffer) |
| 1601 return false; |
| 1602 } else if (arrayBufferV8Value->IsSharedArrayBuffer()) { |
| 1603 arrayBuffer = V8SharedArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Obje
ct>()); |
| 1604 if (!arrayBuffer) |
| 1605 return false; |
| 1606 } else { |
| 1607 ASSERT_NOT_REACHED(); |
| 1608 } |
1570 | 1609 |
1571 // Check the offset, length and alignment. | 1610 // Check the offset, length and alignment. |
1572 int elementByteSize; | 1611 int elementByteSize; |
1573 switch (subTag) { | 1612 switch (subTag) { |
1574 case ByteArrayTag: | 1613 case ByteArrayTag: |
1575 elementByteSize = sizeof(DOMInt8Array::ValueType); | 1614 elementByteSize = sizeof(DOMInt8Array::ValueType); |
1576 break; | 1615 break; |
1577 case UnsignedByteArrayTag: | 1616 case UnsignedByteArrayTag: |
1578 elementByteSize = sizeof(DOMUint8Array::ValueType); | 1617 elementByteSize = sizeof(DOMUint8Array::ValueType); |
1579 break; | 1618 break; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2020 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context(
)->Global(); | 2059 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context(
)->Global(); |
2021 result = toV8(buffer.get(), creationContext, isolate); | 2060 result = toV8(buffer.get(), creationContext, isolate); |
2022 if (result.IsEmpty()) | 2061 if (result.IsEmpty()) |
2023 return false; | 2062 return false; |
2024 m_arrayBuffers[index] = result; | 2063 m_arrayBuffers[index] = result; |
2025 } | 2064 } |
2026 *object = result; | 2065 *object = result; |
2027 return true; | 2066 return true; |
2028 } | 2067 } |
2029 | 2068 |
| 2069 bool ScriptValueDeserializer::tryGetTransferredSharedArrayBuffer(uint32_t index,
v8::Local<v8::Value>* object) |
| 2070 { |
| 2071 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); |
| 2072 if (!m_arrayBufferContents) |
| 2073 return false; |
| 2074 if (index >= m_arrayBuffers.size()) |
| 2075 return false; |
| 2076 v8::Local<v8::Value> result = m_arrayBuffers.at(index); |
| 2077 if (result.IsEmpty()) { |
| 2078 RefPtr<DOMSharedArrayBuffer> buffer = DOMSharedArrayBuffer::create(m_arr
ayBufferContents->at(index)); |
| 2079 v8::Isolate* isolate = m_reader.scriptState()->isolate(); |
| 2080 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context(
)->Global(); |
| 2081 result = toV8(buffer.get(), creationContext, isolate); |
| 2082 if (result.IsEmpty()) |
| 2083 return false; |
| 2084 m_arrayBuffers[index] = result; |
| 2085 } |
| 2086 *object = result; |
| 2087 return true; |
| 2088 } |
| 2089 |
2030 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) | 2090 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference
, v8::Local<v8::Value>* object) |
2031 { | 2091 { |
2032 if (reference >= m_objectPool.size()) | 2092 if (reference >= m_objectPool.size()) |
2033 return false; | 2093 return false; |
2034 *object = m_objectPool[reference]; | 2094 *object = m_objectPool[reference]; |
2035 return object; | 2095 return object; |
2036 } | 2096 } |
2037 | 2097 |
2038 uint32_t ScriptValueDeserializer::objectReferenceCount() | 2098 uint32_t ScriptValueDeserializer::objectReferenceCount() |
2039 { | 2099 { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 return false; | 2158 return false; |
2099 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 2159 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
2100 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 2160 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
2101 if (objectReference >= m_objectPool.size()) | 2161 if (objectReference >= m_objectPool.size()) |
2102 return false; | 2162 return false; |
2103 *object = m_objectPool[objectReference]; | 2163 *object = m_objectPool[objectReference]; |
2104 return true; | 2164 return true; |
2105 } | 2165 } |
2106 | 2166 |
2107 } // namespace blink | 2167 } // namespace blink |
OLD | NEW |