Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: Source/bindings/core/v8/SerializedScriptValue.cpp

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/SerializedScriptValue.h" 32 #include "bindings/core/v8/SerializedScriptValue.h"
33 33
34 #include "bindings/core/v8/ExceptionState.h" 34 #include "bindings/core/v8/ExceptionState.h"
35 #include "bindings/core/v8/V8ArrayBuffer.h"
36 #include "bindings/core/v8/V8ArrayBufferView.h"
35 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8Blob.h" 38 #include "bindings/core/v8/V8Blob.h"
39 #include "bindings/core/v8/V8DataView.h"
37 #include "bindings/core/v8/V8File.h" 40 #include "bindings/core/v8/V8File.h"
38 #include "bindings/core/v8/V8FileList.h" 41 #include "bindings/core/v8/V8FileList.h"
42 #include "bindings/core/v8/V8Float32Array.h"
43 #include "bindings/core/v8/V8Float64Array.h"
39 #include "bindings/core/v8/V8ImageData.h" 44 #include "bindings/core/v8/V8ImageData.h"
45 #include "bindings/core/v8/V8Int16Array.h"
46 #include "bindings/core/v8/V8Int32Array.h"
47 #include "bindings/core/v8/V8Int8Array.h"
40 #include "bindings/core/v8/V8MessagePort.h" 48 #include "bindings/core/v8/V8MessagePort.h"
49 #include "bindings/core/v8/V8Uint16Array.h"
50 #include "bindings/core/v8/V8Uint32Array.h"
51 #include "bindings/core/v8/V8Uint8Array.h"
52 #include "bindings/core/v8/V8Uint8ClampedArray.h"
41 #include "bindings/core/v8/WorkerScriptController.h" 53 #include "bindings/core/v8/WorkerScriptController.h"
42 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
43 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
44 #include "bindings/core/v8/custom/V8DataViewCustom.h"
45 #include "bindings/core/v8/custom/V8Float32ArrayCustom.h"
46 #include "bindings/core/v8/custom/V8Float64ArrayCustom.h"
47 #include "bindings/core/v8/custom/V8Int16ArrayCustom.h"
48 #include "bindings/core/v8/custom/V8Int32ArrayCustom.h"
49 #include "bindings/core/v8/custom/V8Int8ArrayCustom.h"
50 #include "bindings/core/v8/custom/V8Uint16ArrayCustom.h"
51 #include "bindings/core/v8/custom/V8Uint32ArrayCustom.h"
52 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h"
53 #include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h"
54 #include "bindings/modules/v8/V8CryptoKey.h" 54 #include "bindings/modules/v8/V8CryptoKey.h"
55 #include "bindings/modules/v8/V8DOMFileSystem.h" 55 #include "bindings/modules/v8/V8DOMFileSystem.h"
56 #include "core/dom/ExceptionCode.h" 56 #include "core/dom/ExceptionCode.h"
57 #include "core/dom/MessagePort.h" 57 #include "core/dom/MessagePort.h"
58 #include "core/fileapi/Blob.h" 58 #include "core/fileapi/Blob.h"
59 #include "core/fileapi/File.h" 59 #include "core/fileapi/File.h"
60 #include "core/fileapi/FileList.h" 60 #include "core/fileapi/FileList.h"
61 #include "core/html/ImageData.h" 61 #include "core/html/ImageData.h"
62 #include "core/html/canvas/DataView.h" 62 #include "core/html/canvas/DataView.h"
63 #include "platform/SharedBuffer.h" 63 #include "platform/SharedBuffer.h"
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 907
908 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Objec t> creationContext, v8::Isolate* isolate) 908 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Objec t> creationContext, v8::Isolate* isolate)
909 { 909 {
910 if (!impl) 910 if (!impl)
911 return v8::Handle<v8::Object>(); 911 return v8::Handle<v8::Object>();
912 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate); 912 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate);
913 ASSERT(wrapper->IsObject()); 913 ASSERT(wrapper->IsObject());
914 return wrapper.As<v8::Object>(); 914 return wrapper.As<v8::Object>();
915 } 915 }
916 916
917 static v8::Handle<v8::ArrayBuffer> toV8Object(ArrayBuffer* impl, v8::Handle<v8:: Object> creationContext, v8::Isolate* isolate) 917 static v8::Handle<v8::ArrayBuffer> toV8Object(DOMArrayBuffer* impl, v8::Handle<v 8::Object> creationContext, v8::Isolate* isolate)
918 { 918 {
919 if (!impl) 919 if (!impl)
920 return v8::Handle<v8::ArrayBuffer>(); 920 return v8::Handle<v8::ArrayBuffer>();
921 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate); 921 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate);
922 ASSERT(wrapper->IsArrayBuffer()); 922 ASSERT(wrapper->IsArrayBuffer());
923 return wrapper.As<v8::ArrayBuffer>(); 923 return wrapper.As<v8::ArrayBuffer>();
924 } 924 }
925 925
926 class Serializer { 926 class Serializer {
927 class StateBase; 927 class StateBase;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 1369
1370 void writeRegExp(v8::Handle<v8::Value> value) 1370 void writeRegExp(v8::Handle<v8::Value> value)
1371 { 1371 {
1372 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>(); 1372 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>();
1373 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); 1373 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags());
1374 } 1374 }
1375 1375
1376 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB ase* next) 1376 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB ase* next)
1377 { 1377 {
1378 ASSERT(!object.IsEmpty()); 1378 ASSERT(!object.IsEmpty());
1379 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); 1379 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object);
1380 if (!arrayBufferView) 1380 if (!arrayBufferView)
1381 return 0; 1381 return 0;
1382 if (!arrayBufferView->buffer()) 1382 if (!arrayBufferView->buffer())
1383 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next); 1383 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next);
1384 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_scriptState->context()->Global(), isolate()); 1384 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_scriptState->context()->Global(), isolate());
1385 if (underlyingBuffer.IsEmpty()) 1385 if (underlyingBuffer.IsEmpty())
1386 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next); 1386 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next);
1387 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); 1387 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next);
1388 if (stateOut) 1388 if (stateOut)
1389 return stateOut; 1389 return stateOut;
1390 m_writer.writeArrayBufferView(*arrayBufferView); 1390 m_writer.writeArrayBufferView(*arrayBufferView->view());
1391 // This should be safe: we serialize something that we know to be a wrap per (see 1391 // This should be safe: we serialize something that we know to be a wrap per (see
1392 // the toV8 call above), so the call to doSerializeArrayBuffer should ne ither 1392 // the toV8 call above), so the call to doSerializeArrayBuffer should ne ither
1393 // cause the system stack to overflow nor should it have potential to re ach 1393 // cause the system stack to overflow nor should it have potential to re ach
1394 // this ArrayBufferView again. 1394 // this ArrayBufferView again.
1395 // 1395 //
1396 // We do need to grey the underlying buffer before we grey its view, how ever; 1396 // We do need to grey the underlying buffer before we grey its view, how ever;
1397 // ArrayBuffers may be shared, so they need to be given reference IDs, a nd an 1397 // ArrayBuffers may be shared, so they need to be given reference IDs, a nd an
1398 // ArrayBufferView cannot be constructed without a corresponding ArrayBu ffer 1398 // ArrayBufferView cannot be constructed without a corresponding ArrayBu ffer
1399 // (or without an additional tag that would allow us to do two-stage con struction 1399 // (or without an additional tag that would allow us to do two-stage con struction
1400 // like we do for Objects and Arrays). 1400 // like we do for Objects and Arrays).
1401 greyObject(object); 1401 greyObject(object);
1402 return 0; 1402 return 0;
1403 } 1403 }
1404 1404
1405 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next) 1405 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next)
1406 { 1406 {
1407 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()) ; 1407 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object> ());
1408 if (!arrayBuffer) 1408 if (!arrayBuffer)
1409 return 0; 1409 return 0;
1410 if (arrayBuffer->isNeutered()) 1410 if (arrayBuffer->isNeutered())
1411 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next); 1411 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next);
1412 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>())); 1412 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>()));
1413 m_writer.writeArrayBuffer(*arrayBuffer); 1413 m_writer.writeArrayBuffer(*arrayBuffer->buffer());
1414 return 0; 1414 return 0;
1415 } 1415 }
1416 1416
1417 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t index, StateBase* next) 1417 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t index, StateBase* next)
1418 { 1418 {
1419 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()) ; 1419 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object> ());
1420 if (!arrayBuffer) 1420 if (!arrayBuffer)
1421 return 0; 1421 return 0;
1422 if (arrayBuffer->isNeutered()) 1422 if (arrayBuffer->isNeutered())
1423 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next); 1423 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next);
1424 m_writer.writeTransferredArrayBuffer(index); 1424 m_writer.writeTransferredArrayBuffer(index);
1425 return 0; 1425 return 0;
1426 } 1426 }
1427 1427
1428 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount) 1428 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount)
1429 { 1429 {
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 } 2030 }
2031 2031
2032 PassRefPtr<ArrayBuffer> doReadArrayBuffer() 2032 PassRefPtr<ArrayBuffer> doReadArrayBuffer()
2033 { 2033 {
2034 uint32_t byteLength; 2034 uint32_t byteLength;
2035 if (!doReadUint32(&byteLength)) 2035 if (!doReadUint32(&byteLength))
2036 return nullptr; 2036 return nullptr;
2037 if (m_position + byteLength > m_length) 2037 if (m_position + byteLength > m_length)
2038 return nullptr; 2038 return nullptr;
2039 const void* bufferStart = m_buffer + m_position; 2039 const void* bufferStart = m_buffer + m_position;
2040 RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(bufferStart, byteL ength);
2041 arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver:: instanceTemplate());
2042 m_position += byteLength; 2040 m_position += byteLength;
2043 return arrayBuffer.release(); 2041 return ArrayBuffer::create(bufferStart, byteLength);
2044 } 2042 }
2045 2043
2046 bool readArrayBuffer(v8::Handle<v8::Value>* value) 2044 bool readArrayBuffer(v8::Handle<v8::Value>* value)
2047 { 2045 {
2048 RefPtr<ArrayBuffer> arrayBuffer = doReadArrayBuffer(); 2046 RefPtr<ArrayBuffer> arrayBuffer = doReadArrayBuffer();
2049 if (!arrayBuffer) 2047 if (!arrayBuffer)
2050 return false; 2048 return false;
2051 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), isolate()); 2049 *value = toV8(DOMArrayBuffer::create(arrayBuffer.release()), m_scriptSta te->context()->Global(), isolate());
2052 return true; 2050 return true;
2053 } 2051 }
2054 2052
2055 bool readArrayBufferView(v8::Handle<v8::Value>* value, CompositeCreator& cre ator) 2053 bool readArrayBufferView(v8::Handle<v8::Value>* value, CompositeCreator& cre ator)
2056 { 2054 {
2057 ArrayBufferViewSubTag subTag; 2055 ArrayBufferViewSubTag subTag;
2058 uint32_t byteOffset; 2056 uint32_t byteOffset;
2059 uint32_t byteLength; 2057 uint32_t byteLength;
2060 RefPtr<ArrayBuffer> arrayBuffer; 2058 RefPtr<DOMArrayBuffer> arrayBuffer;
2061 v8::Handle<v8::Value> arrayBufferV8Value; 2059 v8::Handle<v8::Value> arrayBufferV8Value;
2062 if (!readArrayBufferViewSubTag(&subTag)) 2060 if (!readArrayBufferViewSubTag(&subTag))
2063 return false; 2061 return false;
2064 if (!doReadUint32(&byteOffset)) 2062 if (!doReadUint32(&byteOffset))
2065 return false; 2063 return false;
2066 if (!doReadUint32(&byteLength)) 2064 if (!doReadUint32(&byteLength))
2067 return false; 2065 return false;
2068 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) 2066 if (!creator.consumeTopOfStack(&arrayBufferV8Value))
2069 return false; 2067 return false;
2070 if (arrayBufferV8Value.IsEmpty()) 2068 if (arrayBufferV8Value.IsEmpty())
2071 return false; 2069 return false;
2072 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()) ; 2070 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()) ;
2073 if (!arrayBuffer) 2071 if (!arrayBuffer)
2074 return false; 2072 return false;
2075 2073
2076 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa l(); 2074 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa l();
2077 switch (subTag) { 2075 switch (subTag) {
2078 case ByteArrayTag: 2076 case ByteArrayTag:
2079 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b yteLength), creationContext, isolate()); 2077 *value = toV8(DOMInt8Array::create(arrayBuffer.release(), byteOffset , byteLength), creationContext, isolate());
2080 break; 2078 break;
2081 case UnsignedByteArrayTag: 2079 case UnsignedByteArrayTag:
2082 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate()); 2080 *value = toV8(DOMUint8Array::create(arrayBuffer.release(), byteOffse t, byteLength), creationContext, isolate());
2083 break; 2081 break;
2084 case UnsignedByteClampedArrayTag: 2082 case UnsignedByteClampedArrayTag:
2085 *value = toV8(Uint8ClampedArray::create(arrayBuffer.release(), byteO ffset, byteLength), creationContext, isolate()); 2083 *value = toV8(DOMUint8ClampedArray::create(arrayBuffer.release(), by teOffset, byteLength), creationContext, isolate());
2086 break; 2084 break;
2087 case ShortArrayTag: { 2085 case ShortArrayTag: {
2088 uint32_t shortLength = byteLength / sizeof(int16_t); 2086 uint32_t shortLength = byteLength / sizeof(int16_t);
2089 if (shortLength * sizeof(int16_t) != byteLength) 2087 if (shortLength * sizeof(int16_t) != byteLength)
2090 return false; 2088 return false;
2091 *value = toV8(Int16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate()); 2089 *value = toV8(DOMInt16Array::create(arrayBuffer.release(), byteOffse t, shortLength), creationContext, isolate());
2092 break; 2090 break;
2093 } 2091 }
2094 case UnsignedShortArrayTag: { 2092 case UnsignedShortArrayTag: {
2095 uint32_t shortLength = byteLength / sizeof(uint16_t); 2093 uint32_t shortLength = byteLength / sizeof(uint16_t);
2096 if (shortLength * sizeof(uint16_t) != byteLength) 2094 if (shortLength * sizeof(uint16_t) != byteLength)
2097 return false; 2095 return false;
2098 *value = toV8(Uint16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate()); 2096 *value = toV8(DOMUint16Array::create(arrayBuffer.release(), byteOffs et, shortLength), creationContext, isolate());
2099 break; 2097 break;
2100 } 2098 }
2101 case IntArrayTag: { 2099 case IntArrayTag: {
2102 uint32_t intLength = byteLength / sizeof(int32_t); 2100 uint32_t intLength = byteLength / sizeof(int32_t);
2103 if (intLength * sizeof(int32_t) != byteLength) 2101 if (intLength * sizeof(int32_t) != byteLength)
2104 return false; 2102 return false;
2105 *value = toV8(Int32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate()); 2103 *value = toV8(DOMInt32Array::create(arrayBuffer.release(), byteOffse t, intLength), creationContext, isolate());
2106 break; 2104 break;
2107 } 2105 }
2108 case UnsignedIntArrayTag: { 2106 case UnsignedIntArrayTag: {
2109 uint32_t intLength = byteLength / sizeof(uint32_t); 2107 uint32_t intLength = byteLength / sizeof(uint32_t);
2110 if (intLength * sizeof(uint32_t) != byteLength) 2108 if (intLength * sizeof(uint32_t) != byteLength)
2111 return false; 2109 return false;
2112 *value = toV8(Uint32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate()); 2110 *value = toV8(DOMUint32Array::create(arrayBuffer.release(), byteOffs et, intLength), creationContext, isolate());
2113 break; 2111 break;
2114 } 2112 }
2115 case FloatArrayTag: { 2113 case FloatArrayTag: {
2116 uint32_t floatLength = byteLength / sizeof(float); 2114 uint32_t floatLength = byteLength / sizeof(float);
2117 if (floatLength * sizeof(float) != byteLength) 2115 if (floatLength * sizeof(float) != byteLength)
2118 return false; 2116 return false;
2119 *value = toV8(Float32Array::create(arrayBuffer.release(), byteOffset , floatLength), creationContext, isolate()); 2117 *value = toV8(DOMFloat32Array::create(arrayBuffer.release(), byteOff set, floatLength), creationContext, isolate());
2120 break; 2118 break;
2121 } 2119 }
2122 case DoubleArrayTag: { 2120 case DoubleArrayTag: {
2123 uint32_t floatLength = byteLength / sizeof(double); 2121 uint32_t floatLength = byteLength / sizeof(double);
2124 if (floatLength * sizeof(double) != byteLength) 2122 if (floatLength * sizeof(double) != byteLength)
2125 return false; 2123 return false;
2126 *value = toV8(Float64Array::create(arrayBuffer.release(), byteOffset , floatLength), creationContext, isolate()); 2124 *value = toV8(DOMFloat64Array::create(arrayBuffer.release(), byteOff set, floatLength), creationContext, isolate());
2127 break; 2125 break;
2128 } 2126 }
2129 case DataViewTag: 2127 case DataViewTag:
2130 *value = toV8(DataView::create(arrayBuffer.release(), byteOffset, by teLength), creationContext, isolate()); 2128 *value = toV8(DOMDataView::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
2131 break; 2129 break;
2132 default: 2130 default:
2133 return false; 2131 return false;
2134 } 2132 }
2135 // The various *Array::create() methods will return null if the range th e view expects is 2133 // The various *Array::create() methods will return null if the range th e view expects is
2136 // mismatched with the range the buffer can provide or if the byte offse t is not aligned 2134 // mismatched with the range the buffer can provide or if the byte offse t is not aligned
2137 // to the size of the element type. 2135 // to the size of the element type.
2138 return !value->IsEmpty(); 2136 return !value->IsEmpty();
2139 } 2137 }
2140 2138
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 } 2694 }
2697 2695
2698 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>* object) override 2696 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>* object) override
2699 { 2697 {
2700 if (!m_arrayBufferContents) 2698 if (!m_arrayBufferContents)
2701 return false; 2699 return false;
2702 if (index >= m_arrayBuffers.size()) 2700 if (index >= m_arrayBuffers.size())
2703 return false; 2701 return false;
2704 v8::Handle<v8::Object> result = m_arrayBuffers.at(index); 2702 v8::Handle<v8::Object> result = m_arrayBuffers.at(index);
2705 if (result.IsEmpty()) { 2703 if (result.IsEmpty()) {
2706 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_arrayBufferConten ts->at(index)); 2704 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(m_arrayBuffer Contents->at(index));
2707 buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::i nstanceTemplate());
2708 v8::Isolate* isolate = m_reader.scriptState()->isolate(); 2705 v8::Isolate* isolate = m_reader.scriptState()->isolate();
2709 v8::Handle<v8::Object> creationContext = m_reader.scriptState()->con text()->Global(); 2706 v8::Handle<v8::Object> creationContext = m_reader.scriptState()->con text()->Global();
2710 isolate->AdjustAmountOfExternalAllocatedMemory(buffer->byteLength()) ;
2711 result = toV8Object(buffer.get(), creationContext, isolate); 2707 result = toV8Object(buffer.get(), creationContext, isolate);
2712 m_arrayBuffers[index] = result; 2708 m_arrayBuffers[index] = result;
2713 } 2709 }
2714 *object = result; 2710 *object = result;
2715 return true; 2711 return true;
2716 } 2712 }
2717 2713
2718 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Handle< v8::Value>* object) override 2714 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Handle< v8::Value>* object) override
2719 { 2715 {
2720 if (reference >= m_objectPool.size()) 2716 if (reference >= m_objectPool.size())
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 for (size_t i = 0; i < length; i++) 2876 for (size_t i = 0; i < length; i++)
2881 dst[i] = htons(src[i]); 2877 dst[i] = htons(src[i]);
2882 } 2878 }
2883 } 2879 }
2884 2880
2885 SerializedScriptValue::SerializedScriptValue() 2881 SerializedScriptValue::SerializedScriptValue()
2886 : m_externallyAllocatedMemory(0) 2882 : m_externallyAllocatedMemory(0)
2887 { 2883 {
2888 } 2884 }
2889 2885
2890 static void neuterArrayBufferInAllWorlds(ArrayBuffer* object) 2886 static void neuterArrayBufferInAllWorlds(DOMArrayBuffer* object)
2891 { 2887 {
2892 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2888 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2893 if (isMainThread()) { 2889 if (isMainThread()) {
2894 Vector<RefPtr<DOMWrapperWorld> > worlds; 2890 Vector<RefPtr<DOMWrapperWorld> > worlds;
2895 DOMWrapperWorld::allWorldsInMainThread(worlds); 2891 DOMWrapperWorld::allWorldsInMainThread(worlds);
2896 for (size_t i = 0; i < worlds.size(); i++) { 2892 for (size_t i = 0; i < worlds.size(); i++) {
2897 v8::Handle<v8::Object> wrapper = worlds[i]->domDataStore().get<V8Arr ayBuffer>(object, isolate); 2893 v8::Handle<v8::Object> wrapper = worlds[i]->domDataStore().get<V8Arr ayBuffer>(object, isolate);
2898 if (!wrapper.IsEmpty()) { 2894 if (!wrapper.IsEmpty()) {
2899 ASSERT(wrapper->IsArrayBuffer()); 2895 ASSERT(wrapper->IsArrayBuffer());
2900 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter(); 2896 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter();
(...skipping 14 matching lines...) Expand all
2915 2911
2916 for (size_t i = 0; i < arrayBuffers.size(); i++) { 2912 for (size_t i = 0; i < arrayBuffers.size(); i++) {
2917 if (arrayBuffers[i]->isNeutered()) { 2913 if (arrayBuffers[i]->isNeutered()) {
2918 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); 2914 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered.");
2919 return nullptr; 2915 return nullptr;
2920 } 2916 }
2921 } 2917 }
2922 2918
2923 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents Array(arrayBuffers.size())); 2919 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents Array(arrayBuffers.size()));
2924 2920
2925 HashSet<ArrayBuffer*> visited; 2921 HashSet<DOMArrayBuffer*> visited;
2926 for (size_t i = 0; i < arrayBuffers.size(); i++) { 2922 for (size_t i = 0; i < arrayBuffers.size(); i++) {
2927 if (visited.contains(arrayBuffers[i].get())) 2923 if (visited.contains(arrayBuffers[i].get()))
2928 continue; 2924 continue;
2929 visited.add(arrayBuffers[i].get()); 2925 visited.add(arrayBuffers[i].get());
2930 2926
2931 bool result = arrayBuffers[i]->transfer(contents->at(i)); 2927 bool result = arrayBuffers[i]->transfer(contents->at(i));
2932 if (!result) { 2928 if (!result) {
2933 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); 2929 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred.");
2934 return nullptr; 2930 return nullptr;
2935 } 2931 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15. 3031 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15.
3036 if (V8MessagePort::hasInstance(transferrable, isolate)) { 3032 if (V8MessagePort::hasInstance(transferrable, isolate)) {
3037 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toImpl(v8::Han dle<v8::Object>::Cast(transferrable)); 3033 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toImpl(v8::Han dle<v8::Object>::Cast(transferrable));
3038 // Check for duplicate MessagePorts. 3034 // Check for duplicate MessagePorts.
3039 if (ports.contains(port)) { 3035 if (ports.contains(port)) {
3040 exceptionState.throwDOMException(DataCloneError, "Message port a t index " + String::number(i) + " is a duplicate of an earlier port."); 3036 exceptionState.throwDOMException(DataCloneError, "Message port a t index " + String::number(i) + " is a duplicate of an earlier port.");
3041 return false; 3037 return false;
3042 } 3038 }
3043 ports.append(port.release()); 3039 ports.append(port.release());
3044 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { 3040 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) {
3045 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v 8::Object>::Cast(transferrable)); 3041 RefPtr<DOMArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handl e<v8::Object>::Cast(transferrable));
3046 if (arrayBuffers.contains(arrayBuffer)) { 3042 if (arrayBuffers.contains(arrayBuffer)) {
3047 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); 3043 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
3048 return false; 3044 return false;
3049 } 3045 }
3050 arrayBuffers.append(arrayBuffer.release()); 3046 arrayBuffers.append(arrayBuffer.release());
3051 } else { 3047 } else {
3052 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type."); 3048 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type.");
3053 return false; 3049 return false;
3054 } 3050 }
3055 } 3051 }
(...skipping 13 matching lines...) Expand all
3069 // If the allocated memory was not registered before, then this class is lik ely 3065 // If the allocated memory was not registered before, then this class is lik ely
3070 // used in a context other then Worker's onmessage environment and the prese nce of 3066 // used in a context other then Worker's onmessage environment and the prese nce of
3071 // current v8 context is not guaranteed. Avoid calling v8 then. 3067 // current v8 context is not guaranteed. Avoid calling v8 then.
3072 if (m_externallyAllocatedMemory) { 3068 if (m_externallyAllocatedMemory) {
3073 ASSERT(v8::Isolate::GetCurrent()); 3069 ASSERT(v8::Isolate::GetCurrent());
3074 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); 3070 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory);
3075 } 3071 }
3076 } 3072 }
3077 3073
3078 } // namespace blink 3074 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValue.h ('k') | Source/bindings/core/v8/custom/V8ArrayBufferCustom.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698