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

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/DOMArrayBufferDeallocationObserver.h"
56 #include "core/dom/ExceptionCode.h" 57 #include "core/dom/ExceptionCode.h"
57 #include "core/dom/MessagePort.h" 58 #include "core/dom/MessagePort.h"
58 #include "core/fileapi/Blob.h" 59 #include "core/fileapi/Blob.h"
59 #include "core/fileapi/File.h" 60 #include "core/fileapi/File.h"
60 #include "core/fileapi/FileList.h" 61 #include "core/fileapi/FileList.h"
61 #include "core/html/ImageData.h" 62 #include "core/html/ImageData.h"
62 #include "core/html/canvas/DataView.h" 63 #include "core/html/canvas/DataView.h"
63 #include "platform/SharedBuffer.h" 64 #include "platform/SharedBuffer.h"
64 #include "platform/heap/Handle.h" 65 #include "platform/heap/Handle.h"
65 #include "public/platform/Platform.h" 66 #include "public/platform/Platform.h"
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 905
905 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Objec t> creationContext, v8::Isolate* isolate) 906 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Objec t> creationContext, v8::Isolate* isolate)
906 { 907 {
907 if (!impl) 908 if (!impl)
908 return v8::Handle<v8::Object>(); 909 return v8::Handle<v8::Object>();
909 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate); 910 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate);
910 ASSERT(wrapper->IsObject()); 911 ASSERT(wrapper->IsObject());
911 return wrapper.As<v8::Object>(); 912 return wrapper.As<v8::Object>();
912 } 913 }
913 914
914 static v8::Handle<v8::ArrayBuffer> toV8Object(ArrayBuffer* impl, v8::Handle<v8:: Object> creationContext, v8::Isolate* isolate) 915 static v8::Handle<v8::ArrayBuffer> toV8Object(DOMArrayBuffer* impl, v8::Handle<v 8::Object> creationContext, v8::Isolate* isolate)
915 { 916 {
916 if (!impl) 917 if (!impl)
917 return v8::Handle<v8::ArrayBuffer>(); 918 return v8::Handle<v8::ArrayBuffer>();
918 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate); 919 v8::Handle<v8::Value> wrapper = toV8(impl, creationContext, isolate);
919 ASSERT(wrapper->IsArrayBuffer()); 920 ASSERT(wrapper->IsArrayBuffer());
920 return wrapper.As<v8::ArrayBuffer>(); 921 return wrapper.As<v8::ArrayBuffer>();
921 } 922 }
922 923
923 class Serializer { 924 class Serializer {
924 class StateBase; 925 class StateBase;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 1367
1367 void writeRegExp(v8::Handle<v8::Value> value) 1368 void writeRegExp(v8::Handle<v8::Value> value)
1368 { 1369 {
1369 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>(); 1370 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>();
1370 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); 1371 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags());
1371 } 1372 }
1372 1373
1373 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB ase* next) 1374 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB ase* next)
1374 { 1375 {
1375 ASSERT(!object.IsEmpty()); 1376 ASSERT(!object.IsEmpty());
1376 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); 1377 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object);
1377 if (!arrayBufferView) 1378 if (!arrayBufferView)
1378 return 0; 1379 return 0;
1379 if (!arrayBufferView->buffer()) 1380 if (!arrayBufferView->buffer())
1380 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next); 1381 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next);
1381 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_scriptState->context()->Global(), isolate()); 1382 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(), m_scriptState->context()->Global(), isolate());
1382 if (underlyingBuffer.IsEmpty()) 1383 if (underlyingBuffer.IsEmpty())
1383 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next); 1384 return handleError(DataCloneError, "An ArrayBuffer could not be clon ed.", next);
1384 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); 1385 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next);
1385 if (stateOut) 1386 if (stateOut)
1386 return stateOut; 1387 return stateOut;
1387 m_writer.writeArrayBufferView(*arrayBufferView); 1388 m_writer.writeArrayBufferView(*arrayBufferView->view());
1388 // This should be safe: we serialize something that we know to be a wrap per (see 1389 // This should be safe: we serialize something that we know to be a wrap per (see
1389 // the toV8 call above), so the call to doSerializeArrayBuffer should ne ither 1390 // the toV8 call above), so the call to doSerializeArrayBuffer should ne ither
1390 // cause the system stack to overflow nor should it have potential to re ach 1391 // cause the system stack to overflow nor should it have potential to re ach
1391 // this ArrayBufferView again. 1392 // this ArrayBufferView again.
1392 // 1393 //
1393 // We do need to grey the underlying buffer before we grey its view, how ever; 1394 // We do need to grey the underlying buffer before we grey its view, how ever;
1394 // ArrayBuffers may be shared, so they need to be given reference IDs, a nd an 1395 // ArrayBuffers may be shared, so they need to be given reference IDs, a nd an
1395 // ArrayBufferView cannot be constructed without a corresponding ArrayBu ffer 1396 // ArrayBufferView cannot be constructed without a corresponding ArrayBu ffer
1396 // (or without an additional tag that would allow us to do two-stage con struction 1397 // (or without an additional tag that would allow us to do two-stage con struction
1397 // like we do for Objects and Arrays). 1398 // like we do for Objects and Arrays).
1398 greyObject(object); 1399 greyObject(object);
1399 return 0; 1400 return 0;
1400 } 1401 }
1401 1402
1402 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next) 1403 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next)
1403 { 1404 {
1404 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()) ; 1405 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object> ());
1405 if (!arrayBuffer) 1406 if (!arrayBuffer)
1406 return 0; 1407 return 0;
1407 if (arrayBuffer->isNeutered()) 1408 if (arrayBuffer->isNeutered())
1408 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next); 1409 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next);
1409 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>())); 1410 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>()));
1410 m_writer.writeArrayBuffer(*arrayBuffer); 1411 m_writer.writeArrayBuffer(*arrayBuffer->buffer());
1411 return 0; 1412 return 0;
1412 } 1413 }
1413 1414
1414 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t index, StateBase* next) 1415 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t index, StateBase* next)
1415 { 1416 {
1416 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>()) ; 1417 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object> ());
1417 if (!arrayBuffer) 1418 if (!arrayBuffer)
1418 return 0; 1419 return 0;
1419 if (arrayBuffer->isNeutered()) 1420 if (arrayBuffer->isNeutered())
1420 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next); 1421 return handleError(DataCloneError, "An ArrayBuffer is neutered and c ould not be cloned.", next);
1421 m_writer.writeTransferredArrayBuffer(index); 1422 m_writer.writeTransferredArrayBuffer(index);
1422 return 0; 1423 return 0;
1423 } 1424 }
1424 1425
1425 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount) 1426 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount)
1426 { 1427 {
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 2029
2029 PassRefPtr<ArrayBuffer> doReadArrayBuffer() 2030 PassRefPtr<ArrayBuffer> doReadArrayBuffer()
2030 { 2031 {
2031 uint32_t byteLength; 2032 uint32_t byteLength;
2032 if (!doReadUint32(&byteLength)) 2033 if (!doReadUint32(&byteLength))
2033 return nullptr; 2034 return nullptr;
2034 if (m_position + byteLength > m_length) 2035 if (m_position + byteLength > m_length)
2035 return nullptr; 2036 return nullptr;
2036 const void* bufferStart = m_buffer + m_position; 2037 const void* bufferStart = m_buffer + m_position;
2037 RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(bufferStart, byteL ength); 2038 RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(bufferStart, byteL ength);
2038 arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver:: instanceTemplate()); 2039 arrayBuffer->setDeallocationObserver(DOMArrayBufferDeallocationObserver: :instance());
haraken 2014/10/16 05:41:40 We always pass DOMArrayBufferDeallocationObserver:
Yuki 2014/10/16 14:21:50 I found that we can remove most of setDeallocation
2039 m_position += byteLength; 2040 m_position += byteLength;
2040 return arrayBuffer.release(); 2041 return arrayBuffer.release();
2041 } 2042 }
2042 2043
2043 bool readArrayBuffer(v8::Handle<v8::Value>* value) 2044 bool readArrayBuffer(v8::Handle<v8::Value>* value)
2044 { 2045 {
2045 RefPtr<ArrayBuffer> arrayBuffer = doReadArrayBuffer(); 2046 RefPtr<ArrayBuffer> arrayBuffer = doReadArrayBuffer();
2046 if (!arrayBuffer) 2047 if (!arrayBuffer)
2047 return false; 2048 return false;
2048 *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), isolate()); 2049 *value = toV8(DOMArrayBuffer::create(arrayBuffer.release()), m_scriptSta te->context()->Global(), isolate());
2049 return true; 2050 return true;
2050 } 2051 }
2051 2052
2052 bool readArrayBufferView(v8::Handle<v8::Value>* value, CompositeCreator& cre ator) 2053 bool readArrayBufferView(v8::Handle<v8::Value>* value, CompositeCreator& cre ator)
2053 { 2054 {
2054 ArrayBufferViewSubTag subTag; 2055 ArrayBufferViewSubTag subTag;
2055 uint32_t byteOffset; 2056 uint32_t byteOffset;
2056 uint32_t byteLength; 2057 uint32_t byteLength;
2057 RefPtr<ArrayBuffer> arrayBuffer; 2058 RefPtr<DOMArrayBuffer> arrayBuffer;
2058 v8::Handle<v8::Value> arrayBufferV8Value; 2059 v8::Handle<v8::Value> arrayBufferV8Value;
2059 if (!readArrayBufferViewSubTag(&subTag)) 2060 if (!readArrayBufferViewSubTag(&subTag))
2060 return false; 2061 return false;
2061 if (!doReadUint32(&byteOffset)) 2062 if (!doReadUint32(&byteOffset))
2062 return false; 2063 return false;
2063 if (!doReadUint32(&byteLength)) 2064 if (!doReadUint32(&byteLength))
2064 return false; 2065 return false;
2065 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) 2066 if (!creator.consumeTopOfStack(&arrayBufferV8Value))
2066 return false; 2067 return false;
2067 if (arrayBufferV8Value.IsEmpty()) 2068 if (arrayBufferV8Value.IsEmpty())
2068 return false; 2069 return false;
2069 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()) ; 2070 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>()) ;
2070 if (!arrayBuffer) 2071 if (!arrayBuffer)
2071 return false; 2072 return false;
2072 2073
2073 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa l(); 2074 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa l();
2074 switch (subTag) { 2075 switch (subTag) {
2075 case ByteArrayTag: 2076 case ByteArrayTag:
2076 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b yteLength), creationContext, isolate()); 2077 *value = toV8(DOMInt8Array::create(arrayBuffer.release(), byteOffset , byteLength), creationContext, isolate());
2077 break; 2078 break;
2078 case UnsignedByteArrayTag: 2079 case UnsignedByteArrayTag:
2079 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate()); 2080 *value = toV8(DOMUint8Array::create(arrayBuffer.release(), byteOffse t, byteLength), creationContext, isolate());
2080 break; 2081 break;
2081 case UnsignedByteClampedArrayTag: 2082 case UnsignedByteClampedArrayTag:
2082 *value = toV8(Uint8ClampedArray::create(arrayBuffer.release(), byteO ffset, byteLength), creationContext, isolate()); 2083 *value = toV8(DOMUint8ClampedArray::create(arrayBuffer.release(), by teOffset, byteLength), creationContext, isolate());
2083 break; 2084 break;
2084 case ShortArrayTag: { 2085 case ShortArrayTag: {
2085 uint32_t shortLength = byteLength / sizeof(int16_t); 2086 uint32_t shortLength = byteLength / sizeof(int16_t);
2086 if (shortLength * sizeof(int16_t) != byteLength) 2087 if (shortLength * sizeof(int16_t) != byteLength)
2087 return false; 2088 return false;
2088 *value = toV8(Int16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate()); 2089 *value = toV8(DOMInt16Array::create(arrayBuffer.release(), byteOffse t, shortLength), creationContext, isolate());
2089 break; 2090 break;
2090 } 2091 }
2091 case UnsignedShortArrayTag: { 2092 case UnsignedShortArrayTag: {
2092 uint32_t shortLength = byteLength / sizeof(uint16_t); 2093 uint32_t shortLength = byteLength / sizeof(uint16_t);
2093 if (shortLength * sizeof(uint16_t) != byteLength) 2094 if (shortLength * sizeof(uint16_t) != byteLength)
2094 return false; 2095 return false;
2095 *value = toV8(Uint16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate()); 2096 *value = toV8(DOMUint16Array::create(arrayBuffer.release(), byteOffs et, shortLength), creationContext, isolate());
2096 break; 2097 break;
2097 } 2098 }
2098 case IntArrayTag: { 2099 case IntArrayTag: {
2099 uint32_t intLength = byteLength / sizeof(int32_t); 2100 uint32_t intLength = byteLength / sizeof(int32_t);
2100 if (intLength * sizeof(int32_t) != byteLength) 2101 if (intLength * sizeof(int32_t) != byteLength)
2101 return false; 2102 return false;
2102 *value = toV8(Int32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate()); 2103 *value = toV8(DOMInt32Array::create(arrayBuffer.release(), byteOffse t, intLength), creationContext, isolate());
2103 break; 2104 break;
2104 } 2105 }
2105 case UnsignedIntArrayTag: { 2106 case UnsignedIntArrayTag: {
2106 uint32_t intLength = byteLength / sizeof(uint32_t); 2107 uint32_t intLength = byteLength / sizeof(uint32_t);
2107 if (intLength * sizeof(uint32_t) != byteLength) 2108 if (intLength * sizeof(uint32_t) != byteLength)
2108 return false; 2109 return false;
2109 *value = toV8(Uint32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate()); 2110 *value = toV8(DOMUint32Array::create(arrayBuffer.release(), byteOffs et, intLength), creationContext, isolate());
2110 break; 2111 break;
2111 } 2112 }
2112 case FloatArrayTag: { 2113 case FloatArrayTag: {
2113 uint32_t floatLength = byteLength / sizeof(float); 2114 uint32_t floatLength = byteLength / sizeof(float);
2114 if (floatLength * sizeof(float) != byteLength) 2115 if (floatLength * sizeof(float) != byteLength)
2115 return false; 2116 return false;
2116 *value = toV8(Float32Array::create(arrayBuffer.release(), byteOffset , floatLength), creationContext, isolate()); 2117 *value = toV8(DOMFloat32Array::create(arrayBuffer.release(), byteOff set, floatLength), creationContext, isolate());
2117 break; 2118 break;
2118 } 2119 }
2119 case DoubleArrayTag: { 2120 case DoubleArrayTag: {
2120 uint32_t floatLength = byteLength / sizeof(double); 2121 uint32_t floatLength = byteLength / sizeof(double);
2121 if (floatLength * sizeof(double) != byteLength) 2122 if (floatLength * sizeof(double) != byteLength)
2122 return false; 2123 return false;
2123 *value = toV8(Float64Array::create(arrayBuffer.release(), byteOffset , floatLength), creationContext, isolate()); 2124 *value = toV8(DOMFloat64Array::create(arrayBuffer.release(), byteOff set, floatLength), creationContext, isolate());
2124 break; 2125 break;
2125 } 2126 }
2126 case DataViewTag: 2127 case DataViewTag:
2127 *value = toV8(DataView::create(arrayBuffer.release(), byteOffset, by teLength), creationContext, isolate()); 2128 *value = toV8(DOMDataView::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
2128 break; 2129 break;
2129 default: 2130 default:
2130 return false; 2131 return false;
2131 } 2132 }
2132 // 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
2133 // 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
2134 // to the size of the element type. 2135 // to the size of the element type.
2135 return !value->IsEmpty(); 2136 return !value->IsEmpty();
2136 } 2137 }
2137 2138
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 } 2691 }
2691 2692
2692 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>* object) override 2693 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>* object) override
2693 { 2694 {
2694 if (!m_arrayBufferContents) 2695 if (!m_arrayBufferContents)
2695 return false; 2696 return false;
2696 if (index >= m_arrayBuffers.size()) 2697 if (index >= m_arrayBuffers.size())
2697 return false; 2698 return false;
2698 v8::Handle<v8::Object> result = m_arrayBuffers.at(index); 2699 v8::Handle<v8::Object> result = m_arrayBuffers.at(index);
2699 if (result.IsEmpty()) { 2700 if (result.IsEmpty()) {
2700 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_arrayBufferConten ts->at(index)); 2701 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(m_arrayBuffer Contents->at(index));
2701 buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::i nstanceTemplate()); 2702 buffer->setDeallocationObserver(DOMArrayBufferDeallocationObserver:: instance());
2702 v8::Isolate* isolate = m_reader.scriptState()->isolate(); 2703 v8::Isolate* isolate = m_reader.scriptState()->isolate();
2703 v8::Handle<v8::Object> creationContext = m_reader.scriptState()->con text()->Global(); 2704 v8::Handle<v8::Object> creationContext = m_reader.scriptState()->con text()->Global();
2704 isolate->AdjustAmountOfExternalAllocatedMemory(buffer->byteLength()) ; 2705 isolate->AdjustAmountOfExternalAllocatedMemory(buffer->byteLength()) ;
2705 result = toV8Object(buffer.get(), creationContext, isolate); 2706 result = toV8Object(buffer.get(), creationContext, isolate);
2706 m_arrayBuffers[index] = result; 2707 m_arrayBuffers[index] = result;
2707 } 2708 }
2708 *object = result; 2709 *object = result;
2709 return true; 2710 return true;
2710 } 2711 }
2711 2712
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 for (size_t i = 0; i < length; i++) 2875 for (size_t i = 0; i < length; i++)
2875 dst[i] = htons(src[i]); 2876 dst[i] = htons(src[i]);
2876 } 2877 }
2877 } 2878 }
2878 2879
2879 SerializedScriptValue::SerializedScriptValue() 2880 SerializedScriptValue::SerializedScriptValue()
2880 : m_externallyAllocatedMemory(0) 2881 : m_externallyAllocatedMemory(0)
2881 { 2882 {
2882 } 2883 }
2883 2884
2884 static void neuterArrayBufferInAllWorlds(ArrayBuffer* object) 2885 static void neuterArrayBufferInAllWorlds(DOMArrayBuffer* object)
2885 { 2886 {
2886 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2887 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2887 if (isMainThread()) { 2888 if (isMainThread()) {
2888 Vector<RefPtr<DOMWrapperWorld> > worlds; 2889 Vector<RefPtr<DOMWrapperWorld> > worlds;
2889 DOMWrapperWorld::allWorldsInMainThread(worlds); 2890 DOMWrapperWorld::allWorldsInMainThread(worlds);
2890 for (size_t i = 0; i < worlds.size(); i++) { 2891 for (size_t i = 0; i < worlds.size(); i++) {
2891 v8::Handle<v8::Object> wrapper = worlds[i]->domDataStore().get<V8Arr ayBuffer>(object, isolate); 2892 v8::Handle<v8::Object> wrapper = worlds[i]->domDataStore().get<V8Arr ayBuffer>(object, isolate);
2892 if (!wrapper.IsEmpty()) { 2893 if (!wrapper.IsEmpty()) {
2893 ASSERT(wrapper->IsArrayBuffer()); 2894 ASSERT(wrapper->IsArrayBuffer());
2894 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter(); 2895 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter();
(...skipping 14 matching lines...) Expand all
2909 2910
2910 for (size_t i = 0; i < arrayBuffers.size(); i++) { 2911 for (size_t i = 0; i < arrayBuffers.size(); i++) {
2911 if (arrayBuffers[i]->isNeutered()) { 2912 if (arrayBuffers[i]->isNeutered()) {
2912 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); 2913 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered.");
2913 return nullptr; 2914 return nullptr;
2914 } 2915 }
2915 } 2916 }
2916 2917
2917 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents Array(arrayBuffers.size())); 2918 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents Array(arrayBuffers.size()));
2918 2919
2919 HashSet<ArrayBuffer*> visited; 2920 HashSet<DOMArrayBuffer*> visited;
2920 for (size_t i = 0; i < arrayBuffers.size(); i++) { 2921 for (size_t i = 0; i < arrayBuffers.size(); i++) {
2921 if (visited.contains(arrayBuffers[i].get())) 2922 if (visited.contains(arrayBuffers[i].get()))
2922 continue; 2923 continue;
2923 visited.add(arrayBuffers[i].get()); 2924 visited.add(arrayBuffers[i].get());
2924 2925
2925 bool result = arrayBuffers[i]->transfer(contents->at(i)); 2926 bool result = arrayBuffers[i]->transfer(contents->at(i));
2926 if (!result) { 2927 if (!result) {
2927 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); 2928 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred.");
2928 return nullptr; 2929 return nullptr;
2929 } 2930 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15. 3030 // Validation of Objects implementing an interface, per WebIDL spec 4.1. 15.
3030 if (V8MessagePort::hasInstance(transferrable, isolate)) { 3031 if (V8MessagePort::hasInstance(transferrable, isolate)) {
3031 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toImpl(v8::Han dle<v8::Object>::Cast(transferrable)); 3032 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toImpl(v8::Han dle<v8::Object>::Cast(transferrable));
3032 // Check for duplicate MessagePorts. 3033 // Check for duplicate MessagePorts.
3033 if (ports.contains(port)) { 3034 if (ports.contains(port)) {
3034 exceptionState.throwDOMException(DataCloneError, "Message port a t index " + String::number(i) + " is a duplicate of an earlier port."); 3035 exceptionState.throwDOMException(DataCloneError, "Message port a t index " + String::number(i) + " is a duplicate of an earlier port.");
3035 return false; 3036 return false;
3036 } 3037 }
3037 ports.append(port.release()); 3038 ports.append(port.release());
3038 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { 3039 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) {
3039 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v 8::Object>::Cast(transferrable)); 3040 RefPtr<DOMArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handl e<v8::Object>::Cast(transferrable));
3040 if (arrayBuffers.contains(arrayBuffer)) { 3041 if (arrayBuffers.contains(arrayBuffer)) {
3041 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); 3042 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
3042 return false; 3043 return false;
3043 } 3044 }
3044 arrayBuffers.append(arrayBuffer.release()); 3045 arrayBuffers.append(arrayBuffer.release());
3045 } else { 3046 } else {
3046 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type."); 3047 exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type.");
3047 return false; 3048 return false;
3048 } 3049 }
3049 } 3050 }
(...skipping 13 matching lines...) Expand all
3063 // If the allocated memory was not registered before, then this class is lik ely 3064 // If the allocated memory was not registered before, then this class is lik ely
3064 // used in a context other then Worker's onmessage environment and the prese nce of 3065 // used in a context other then Worker's onmessage environment and the prese nce of
3065 // current v8 context is not guaranteed. Avoid calling v8 then. 3066 // current v8 context is not guaranteed. Avoid calling v8 then.
3066 if (m_externallyAllocatedMemory) { 3067 if (m_externallyAllocatedMemory) {
3067 ASSERT(v8::Isolate::GetCurrent()); 3068 ASSERT(v8::Isolate::GetCurrent());
3068 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); 3069 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory);
3069 } 3070 }
3070 } 3071 }
3071 3072
3072 } // namespace blink 3073 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698