Chromium Code Reviews| 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" |
| 30 #include <stdio.h> | |
|
haraken
2015/06/11 05:59:28
Remove this.
| |
| 26 | 31 |
| 27 // FIXME: consider crashing in debug mode on deserialization errors | 32 // FIXME: consider crashing in debug mode on deserialization errors |
| 28 // NOTE: be sure to change wireFormatVersion as necessary! | 33 // NOTE: be sure to change wireFormatVersion as necessary! |
| 29 | 34 |
| 30 namespace blink { | 35 namespace blink { |
| 31 | 36 |
| 32 // This code implements the HTML5 Structured Clone algorithm: | 37 // This code implements the HTML5 Structured Clone algorithm: |
| 33 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data | 38 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data |
| 34 | 39 |
| 35 // ZigZag encoding helps VarInt encoding stay small for negative | 40 // ZigZag encoding helps VarInt encoding stay small for negative |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 void SerializedScriptValueWriter::writeArrayBuffer(const DOMArrayBuffer& arrayBu ffer) | 245 void SerializedScriptValueWriter::writeArrayBuffer(const DOMArrayBuffer& arrayBu ffer) |
| 241 { | 246 { |
| 242 append(ArrayBufferTag); | 247 append(ArrayBufferTag); |
| 243 doWriteArrayBuffer(arrayBuffer); | 248 doWriteArrayBuffer(arrayBuffer); |
| 244 } | 249 } |
| 245 | 250 |
| 246 void SerializedScriptValueWriter::writeArrayBufferView(const DOMArrayBufferView& arrayBufferView) | 251 void SerializedScriptValueWriter::writeArrayBufferView(const DOMArrayBufferView& arrayBufferView) |
| 247 { | 252 { |
| 248 append(ArrayBufferViewTag); | 253 append(ArrayBufferViewTag); |
| 249 #if ENABLE(ASSERT) | 254 #if ENABLE(ASSERT) |
| 250 const DOMArrayBuffer& arrayBuffer = *arrayBufferView.buffer(); | 255 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())); | 256 static_cast<const uint8_t*>(arrayBufferView.baseAddress())); |
| 253 #endif | 257 #endif |
| 254 DOMArrayBufferView::ViewType type = arrayBufferView.type(); | 258 DOMArrayBufferView::ViewType type = arrayBufferView.type(); |
| 255 | 259 |
| 256 switch (type) { | 260 switch (type) { |
| 257 case DOMArrayBufferView::TypeInt8: | 261 case DOMArrayBufferView::TypeInt8: |
| 258 append(ByteArrayTag); | 262 append(ByteArrayTag); |
| 259 break; | 263 break; |
| 260 case DOMArrayBufferView::TypeUint8Clamped: | 264 case DOMArrayBufferView::TypeUint8Clamped: |
| 261 append(UnsignedByteClampedArrayTag); | 265 append(UnsignedByteClampedArrayTag); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 append(MessagePortTag); | 317 append(MessagePortTag); |
| 314 doWriteUint32(index); | 318 doWriteUint32(index); |
| 315 } | 319 } |
| 316 | 320 |
| 317 void SerializedScriptValueWriter::writeTransferredArrayBuffer(uint32_t index) | 321 void SerializedScriptValueWriter::writeTransferredArrayBuffer(uint32_t index) |
| 318 { | 322 { |
| 319 append(ArrayBufferTransferTag); | 323 append(ArrayBufferTransferTag); |
| 320 doWriteUint32(index); | 324 doWriteUint32(index); |
| 321 } | 325 } |
| 322 | 326 |
| 327 void SerializedScriptValueWriter::writeTransferredSharedArrayBuffer(uint32_t ind ex) | |
| 328 { | |
| 329 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | |
| 330 append(SharedArrayBufferTransferTag); | |
| 331 doWriteUint32(index); | |
| 332 } | |
| 333 | |
| 323 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) | 334 void SerializedScriptValueWriter::writeObjectReference(uint32_t reference) |
| 324 { | 335 { |
| 325 append(ObjectReferenceTag); | 336 append(ObjectReferenceTag); |
| 326 doWriteUint32(reference); | 337 doWriteUint32(reference); |
| 327 } | 338 } |
| 328 | 339 |
| 329 void SerializedScriptValueWriter::writeObject(uint32_t numProperties) | 340 void SerializedScriptValueWriter::writeObject(uint32_t numProperties) |
| 330 { | 341 { |
| 331 append(ObjectTag); | 342 append(ObjectTag); |
| 332 doWriteUint32(numProperties); | 343 doWriteUint32(numProperties); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 { | 593 { |
| 583 if (!impl) | 594 if (!impl) |
| 584 return v8::Local<v8::Object>(); | 595 return v8::Local<v8::Object>(); |
| 585 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); | 596 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); |
| 586 if (wrapper.IsEmpty()) | 597 if (wrapper.IsEmpty()) |
| 587 return v8::Local<v8::Object>(); | 598 return v8::Local<v8::Object>(); |
| 588 ASSERT(wrapper->IsObject()); | 599 ASSERT(wrapper->IsObject()); |
| 589 return wrapper.As<v8::Object>(); | 600 return wrapper.As<v8::Object>(); |
| 590 } | 601 } |
| 591 | 602 |
| 592 static v8::Local<v8::ArrayBuffer> toV8Object(DOMArrayBuffer* impl, v8::Local<v8: :Object> creationContext, v8::Isolate* isolate) | 603 static v8::Local<v8::Object> toV8Object(DOMArrayBufferBase* impl, v8::Local<v8:: Object> creationContext, v8::Isolate* isolate) |
| 593 { | 604 { |
| 594 if (!impl) | 605 if (!impl) |
| 595 return v8::Local<v8::ArrayBuffer>(); | 606 return v8::Local<v8::Object>(); |
| 596 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); | 607 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate); |
| 597 if (wrapper.IsEmpty()) | 608 if (wrapper.IsEmpty()) |
| 598 return v8::Local<v8::ArrayBuffer>(); | 609 return v8::Local<v8::Object>(); |
| 599 ASSERT(wrapper->IsArrayBuffer()); | 610 return wrapper.As<v8::Object>(); |
| 600 return wrapper.As<v8::ArrayBuffer>(); | |
| 601 } | 611 } |
| 602 | 612 |
| 603 // Returns true if the provided object is to be considered a 'host object', as u sed in the | 613 // Returns true if the provided object is to be considered a 'host object', as u sed in the |
| 604 // HTML5 structured clone algorithm. | 614 // HTML5 structured clone algorithm. |
| 605 static bool isHostObject(v8::Local<v8::Object> object) | 615 static bool isHostObject(v8::Local<v8::Object> object) |
| 606 { | 616 { |
| 607 // If the object has any internal fields, then we won't be able to serialize or deserialize | 617 // If the object has any internal fields, then we won't be able to serialize or deserialize |
| 608 // them; conveniently, this is also a quick way to detect DOM wrapper object s, because | 618 // them; conveniently, this is also a quick way to detect DOM wrapper object s, because |
| 609 // the mechanism for these relies on data stored in these fields. We should | 619 // the mechanism for these relies on data stored in these fields. We should |
| 610 // catch external array data as a special case. | 620 // catch external array data as a special case. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 writeString(value); | 698 writeString(value); |
| 689 } else if (V8MessagePort::hasInstance(value, isolate())) { | 699 } else if (V8MessagePort::hasInstance(value, isolate())) { |
| 690 uint32_t messagePortIndex; | 700 uint32_t messagePortIndex; |
| 691 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor tIndex)) { | 701 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor tIndex)) { |
| 692 m_writer.writeTransferredMessagePort(messagePortIndex); | 702 m_writer.writeTransferredMessagePort(messagePortIndex); |
| 693 } else { | 703 } else { |
| 694 return handleError(DataCloneError, "A MessagePort could not be clone d.", next); | 704 return handleError(DataCloneError, "A MessagePort could not be clone d.", next); |
| 695 } | 705 } |
| 696 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { | 706 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { |
| 697 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); | 707 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); |
| 708 } else if (V8SharedArrayBuffer::hasInstance(value, isolate()) && m_transferr edArrayBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { | |
| 709 return writeTransferredSharedArrayBuffer(value, arrayBufferIndex, next); | |
| 698 } else { | 710 } else { |
| 699 v8::Local<v8::Object> jsObject = value.As<v8::Object>(); | 711 v8::Local<v8::Object> jsObject = value.As<v8::Object>(); |
| 700 if (jsObject.IsEmpty()) | 712 if (jsObject.IsEmpty()) |
| 701 return handleError(DataCloneError, "An object could not be cloned.", next); | 713 return handleError(DataCloneError, "An object could not be cloned.", next); |
| 702 greyObject(jsObject); | 714 greyObject(jsObject); |
| 703 if (value->IsDate()) { | 715 if (value->IsDate()) { |
| 704 m_writer.writeDate(value.As<v8::Date>()->ValueOf()); | 716 m_writer.writeDate(value.As<v8::Date>()->ValueOf()); |
| 705 } else if (value->IsStringObject()) { | 717 } else if (value->IsStringObject()) { |
| 706 writeStringObject(value); | 718 writeStringObject(value); |
| 707 } else if (value->IsNumberObject()) { | 719 } else if (value->IsNumberObject()) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); | 916 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); |
| 905 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); | 917 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); |
| 906 } | 918 } |
| 907 | 919 |
| 908 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeAndGreyArrayBuffer View(v8::Local<v8::Object> object, ScriptValueSerializer::StateBase* next) | 920 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeAndGreyArrayBuffer View(v8::Local<v8::Object> object, ScriptValueSerializer::StateBase* next) |
| 909 { | 921 { |
| 910 ASSERT(!object.IsEmpty()); | 922 ASSERT(!object.IsEmpty()); |
| 911 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); | 923 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); |
| 912 if (!arrayBufferView) | 924 if (!arrayBufferView) |
| 913 return 0; | 925 return 0; |
| 914 if (!arrayBufferView->buffer()) | 926 if (!arrayBufferView->bufferBase()) |
| 915 return handleError(DataCloneError, "An ArrayBuffer could not be cloned." , next); | 927 return handleError(DataCloneError, "An ArrayBuffer could not be cloned." , next); |
| 916 v8::Local<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_sc riptState->context()->Global(), isolate()); | 928 v8::Local<v8::Value> underlyingBuffer = toV8(arrayBufferView->bufferBase(), m_scriptState->context()->Global(), isolate()); |
| 917 if (underlyingBuffer.IsEmpty()) | 929 if (underlyingBuffer.IsEmpty()) |
| 918 return handleError(DataCloneError, "An ArrayBuffer could not be cloned." , next); | 930 return handleError(DataCloneError, "An ArrayBuffer could not be cloned." , next); |
| 919 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); | 931 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); |
| 920 if (stateOut) | 932 if (stateOut) |
| 921 return stateOut; | 933 return stateOut; |
| 922 m_writer.writeArrayBufferView(*arrayBufferView); | 934 m_writer.writeArrayBufferView(*arrayBufferView); |
| 923 // This should be safe: we serialize something that we know to be a wrapper (see | 935 // This should be safe: we serialize something that we know to be a wrapper (see |
| 924 // the toV8 call above), so the call to doSerializeArrayBuffer should neithe r | 936 // the toV8 call above), so the call to doSerializeArrayBuffer should neithe r |
| 925 // cause the system stack to overflow nor should it have potential to reach | 937 // cause the system stack to overflow nor should it have potential to reach |
| 926 // this ArrayBufferView again. | 938 // this ArrayBufferView again. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 950 { | 962 { |
| 951 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()); | 963 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()); |
| 952 if (!arrayBuffer) | 964 if (!arrayBuffer) |
| 953 return 0; | 965 return 0; |
| 954 if (arrayBuffer->isNeutered()) | 966 if (arrayBuffer->isNeutered()) |
| 955 return handleError(DataCloneError, "An ArrayBuffer is neutered and could not be cloned.", next); | 967 return handleError(DataCloneError, "An ArrayBuffer is neutered and could not be cloned.", next); |
| 956 m_writer.writeTransferredArrayBuffer(index); | 968 m_writer.writeTransferredArrayBuffer(index); |
| 957 return 0; | 969 return 0; |
| 958 } | 970 } |
| 959 | 971 |
| 972 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeTransferredSharedA rrayBuffer(v8::Local<v8::Value> value, uint32_t index, ScriptValueSerializer::St ateBase* next) | |
| 973 { | |
| 974 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | |
| 975 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl(value. As<v8::Object>()); | |
| 976 if (!sharedArrayBuffer) | |
| 977 return 0; | |
| 978 m_writer.writeTransferredSharedArrayBuffer(index); | |
| 979 return 0; | |
| 980 } | |
| 981 | |
| 960 bool ScriptValueSerializer::shouldSerializeDensely(uint32_t length, uint32_t pro pertyCount) | 982 bool ScriptValueSerializer::shouldSerializeDensely(uint32_t length, uint32_t pro pertyCount) |
| 961 { | 983 { |
| 962 // Let K be the cost of serializing all property values that are there | 984 // Let K be the cost of serializing all property values that are there |
| 963 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32_t k ey) | 985 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32_t k ey) |
| 964 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte for a ll properties that are not there) | 986 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte for a ll properties that are not there) |
| 965 // so densely is better than sparsly whenever 6*propertyCount > length | 987 // so densely is better than sparsly whenever 6*propertyCount > length |
| 966 return 6 * propertyCount >= length; | 988 return 6 * propertyCount >= length; |
| 967 } | 989 } |
| 968 | 990 |
| 969 ScriptValueSerializer::StateBase* ScriptValueSerializer::startArrayState(v8::Loc al<v8::Array> array, ScriptValueSerializer::StateBase* next) | 991 ScriptValueSerializer::StateBase* ScriptValueSerializer::startArrayState(v8::Loc al<v8::Array> array, ScriptValueSerializer::StateBase* next) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 case ArrayBufferTransferTag: { | 1248 case ArrayBufferTransferTag: { |
| 1227 if (!m_version) | 1249 if (!m_version) |
| 1228 return false; | 1250 return false; |
| 1229 uint32_t index; | 1251 uint32_t index; |
| 1230 if (!doReadUint32(&index)) | 1252 if (!doReadUint32(&index)) |
| 1231 return false; | 1253 return false; |
| 1232 if (!creator.tryGetTransferredArrayBuffer(index, value)) | 1254 if (!creator.tryGetTransferredArrayBuffer(index, value)) |
| 1233 return false; | 1255 return false; |
| 1234 break; | 1256 break; |
| 1235 } | 1257 } |
| 1258 case SharedArrayBufferTransferTag: { | |
| 1259 if (!m_version) | |
| 1260 return false; | |
| 1261 uint32_t index; | |
| 1262 if (!doReadUint32(&index)) | |
| 1263 return false; | |
| 1264 if (!creator.tryGetTransferredSharedArrayBuffer(index, value)) | |
| 1265 return false; | |
| 1266 break; | |
| 1267 } | |
| 1236 case ObjectReferenceTag: { | 1268 case ObjectReferenceTag: { |
| 1237 if (!m_version) | 1269 if (!m_version) |
| 1238 return false; | 1270 return false; |
| 1239 uint32_t reference; | 1271 uint32_t reference; |
| 1240 if (!doReadUint32(&reference)) | 1272 if (!doReadUint32(&reference)) |
| 1241 return false; | 1273 return false; |
| 1242 if (!creator.tryGetObjectFromObjectReference(reference, value)) | 1274 if (!creator.tryGetObjectFromObjectReference(reference, value)) |
| 1243 return false; | 1275 return false; |
| 1244 break; | 1276 break; |
| 1245 } | 1277 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1447 return false; | 1479 return false; |
| 1448 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), iso late()); | 1480 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), iso late()); |
| 1449 return !value->IsEmpty(); | 1481 return !value->IsEmpty(); |
| 1450 } | 1482 } |
| 1451 | 1483 |
| 1452 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu e, ScriptValueCompositeCreator& creator) | 1484 bool SerializedScriptValueReader::readArrayBufferView(v8::Local<v8::Value>* valu e, ScriptValueCompositeCreator& creator) |
| 1453 { | 1485 { |
| 1454 ArrayBufferViewSubTag subTag; | 1486 ArrayBufferViewSubTag subTag; |
| 1455 uint32_t byteOffset; | 1487 uint32_t byteOffset; |
| 1456 uint32_t byteLength; | 1488 uint32_t byteLength; |
| 1457 RefPtr<DOMArrayBuffer> arrayBuffer; | 1489 RefPtr<DOMArrayBufferBase> arrayBuffer; |
| 1458 v8::Local<v8::Value> arrayBufferV8Value; | 1490 v8::Local<v8::Value> arrayBufferV8Value; |
| 1459 if (!readArrayBufferViewSubTag(&subTag)) | 1491 if (!readArrayBufferViewSubTag(&subTag)) |
| 1460 return false; | 1492 return false; |
| 1461 if (!doReadUint32(&byteOffset)) | 1493 if (!doReadUint32(&byteOffset)) |
| 1462 return false; | 1494 return false; |
| 1463 if (!doReadUint32(&byteLength)) | 1495 if (!doReadUint32(&byteLength)) |
| 1464 return false; | 1496 return false; |
| 1465 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) | 1497 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) |
| 1466 return false; | 1498 return false; |
| 1467 if (arrayBufferV8Value.IsEmpty()) | 1499 if (arrayBufferV8Value.IsEmpty()) |
| 1468 return false; | 1500 return false; |
| 1469 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()); | 1501 if (arrayBufferV8Value->IsArrayBuffer()) { |
| 1470 if (!arrayBuffer) | 1502 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()) ; |
| 1471 return false; | 1503 if (!arrayBuffer) |
| 1504 return false; | |
| 1505 } else if (arrayBufferV8Value->IsSharedArrayBuffer()) { | |
| 1506 arrayBuffer = V8SharedArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Obje ct>()); | |
| 1507 if (!arrayBuffer) | |
| 1508 return false; | |
| 1509 } else { | |
| 1510 ASSERT_NOT_REACHED(); | |
| 1511 } | |
| 1472 | 1512 |
| 1473 // Check the offset, length and alignment. | 1513 // Check the offset, length and alignment. |
| 1474 int elementByteSize; | 1514 int elementByteSize; |
| 1475 switch (subTag) { | 1515 switch (subTag) { |
| 1476 case ByteArrayTag: | 1516 case ByteArrayTag: |
| 1477 elementByteSize = sizeof(DOMInt8Array::ValueType); | 1517 elementByteSize = sizeof(DOMInt8Array::ValueType); |
| 1478 break; | 1518 break; |
| 1479 case UnsignedByteArrayTag: | 1519 case UnsignedByteArrayTag: |
| 1480 elementByteSize = sizeof(DOMUint8Array::ValueType); | 1520 elementByteSize = sizeof(DOMUint8Array::ValueType); |
| 1481 break; | 1521 break; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context( )->Global(); | 1908 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context( )->Global(); |
| 1869 result = toV8(buffer.get(), creationContext, isolate); | 1909 result = toV8(buffer.get(), creationContext, isolate); |
| 1870 if (result.IsEmpty()) | 1910 if (result.IsEmpty()) |
| 1871 return false; | 1911 return false; |
| 1872 m_arrayBuffers[index] = result; | 1912 m_arrayBuffers[index] = result; |
| 1873 } | 1913 } |
| 1874 *object = result; | 1914 *object = result; |
| 1875 return true; | 1915 return true; |
| 1876 } | 1916 } |
| 1877 | 1917 |
| 1918 bool ScriptValueDeserializer::tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8::Value>* object) | |
| 1919 { | |
| 1920 ASSERT(RuntimeEnabledFeatures::sharedArrayBufferEnabled()); | |
| 1921 if (!m_arrayBufferContents) | |
| 1922 return false; | |
| 1923 if (index >= m_arrayBuffers.size()) | |
| 1924 return false; | |
| 1925 v8::Local<v8::Value> result = m_arrayBuffers.at(index); | |
| 1926 if (result.IsEmpty()) { | |
| 1927 RefPtr<DOMSharedArrayBuffer> buffer = DOMSharedArrayBuffer::create(m_arr ayBufferContents->at(index)); | |
| 1928 v8::Isolate* isolate = m_reader.scriptState()->isolate(); | |
| 1929 v8::Local<v8::Object> creationContext = m_reader.scriptState()->context( )->Global(); | |
| 1930 result = toV8(buffer.get(), creationContext, isolate); | |
|
haraken
2015/06/11 05:59:28
You need to add:
if (result.isEmpty())
retu
| |
| 1931 m_arrayBuffers[index] = result; | |
| 1932 } | |
| 1933 *object = result; | |
| 1934 return true; | |
| 1935 } | |
| 1936 | |
| 1878 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference , v8::Local<v8::Value>* object) | 1937 bool ScriptValueDeserializer::tryGetObjectFromObjectReference(uint32_t reference , v8::Local<v8::Value>* object) |
| 1879 { | 1938 { |
| 1880 if (reference >= m_objectPool.size()) | 1939 if (reference >= m_objectPool.size()) |
| 1881 return false; | 1940 return false; |
| 1882 *object = m_objectPool[reference]; | 1941 *object = m_objectPool[reference]; |
| 1883 return object; | 1942 return object; |
| 1884 } | 1943 } |
| 1885 | 1944 |
| 1886 uint32_t ScriptValueDeserializer::objectReferenceCount() | 1945 uint32_t ScriptValueDeserializer::objectReferenceCount() |
| 1887 { | 1946 { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1940 return false; | 1999 return false; |
| 1941 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; | 2000 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; |
| 1942 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); | 2001 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); |
| 1943 if (objectReference >= m_objectPool.size()) | 2002 if (objectReference >= m_objectPool.size()) |
| 1944 return false; | 2003 return false; |
| 1945 *object = m_objectPool[objectReference]; | 2004 *object = m_objectPool[objectReference]; |
| 1946 return true; | 2005 return true; |
| 1947 } | 2006 } |
| 1948 | 2007 |
| 1949 } // namespace blink | 2008 } // namespace blink |
| OLD | NEW |