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

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

Issue 18316003: Revert "Use V8 implementation of ArrayBuffer in Blink." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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/v8/SerializedScriptValue.h" 32 #include "bindings/v8/SerializedScriptValue.h"
33 33
34 #include "V8ArrayBuffer.h"
34 #include "V8ArrayBufferView.h" 35 #include "V8ArrayBufferView.h"
35 #include "V8Blob.h" 36 #include "V8Blob.h"
36 #include "V8DOMFileSystem.h" 37 #include "V8DOMFileSystem.h"
37 #include "V8DataView.h" 38 #include "V8DataView.h"
38 #include "V8File.h" 39 #include "V8File.h"
39 #include "V8FileList.h" 40 #include "V8FileList.h"
40 #include "V8Float32Array.h" 41 #include "V8Float32Array.h"
41 #include "V8ImageData.h" 42 #include "V8ImageData.h"
42 #include "V8Int16Array.h" 43 #include "V8Int16Array.h"
43 #include "V8Int32Array.h" 44 #include "V8Int32Array.h"
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 675
675 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Isolate* isolate ) 676 static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Isolate* isolate )
676 { 677 {
677 if (!impl) 678 if (!impl)
678 return v8::Handle<v8::Object>(); 679 return v8::Handle<v8::Object>();
679 v8::Handle<v8::Value> wrapper = toV8(impl, v8::Handle<v8::Object>(), isolate ); 680 v8::Handle<v8::Value> wrapper = toV8(impl, v8::Handle<v8::Object>(), isolate );
680 ASSERT(wrapper->IsObject()); 681 ASSERT(wrapper->IsObject());
681 return wrapper.As<v8::Object>(); 682 return wrapper.As<v8::Object>();
682 } 683 }
683 684
684 static v8::Handle<v8::ArrayBuffer> toV8Object(ArrayBuffer* impl, v8::Isolate* is olate) 685 static v8::Handle<v8::Object> toV8Object(ArrayBuffer* impl, v8::Isolate* isolate )
685 { 686 {
686 if (!impl) 687 if (!impl)
687 return v8::Handle<v8::ArrayBuffer>(); 688 return v8::Handle<v8::Object>();
688 v8::Handle<v8::Value> wrapper = toV8(impl, v8::Handle<v8::Object>(), isolate ); 689 v8::Handle<v8::Value> wrapper = toV8(impl, v8::Handle<v8::Object>(), isolate );
689 ASSERT(wrapper->IsArrayBuffer()); 690 ASSERT(wrapper->IsObject());
690 return wrapper.As<v8::ArrayBuffer>(); 691 return wrapper.As<v8::Object>();
691 } 692 }
692 693
693 class Serializer { 694 class Serializer {
694 class StateBase; 695 class StateBase;
695 public: 696 public:
696 enum Status { 697 enum Status {
697 Success, 698 Success,
698 InputError, 699 InputError,
699 DataCloneError, 700 DataCloneError,
700 InvalidStateError, 701 InvalidStateError,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 , m_nameDone(false) 839 , m_nameDone(false)
839 , m_isSerializingAccessor(false) 840 , m_isSerializingAccessor(false)
840 { 841 {
841 } 842 }
842 843
843 virtual uint32_t execDepth() const { return m_isSerializingAccessor ? 1 : 0; } 844 virtual uint32_t execDepth() const { return m_isSerializingAccessor ? 1 : 0; }
844 845
845 protected: 846 protected:
846 virtual StateBase* objectDone(unsigned numProperties, Serializer&) = 0; 847 virtual StateBase* objectDone(unsigned numProperties, Serializer&) = 0;
847 848
848 StateBase* serializeProperties(bool ignoreIndexed, Serializer& serialize r) 849 StateBase* serializeProperties(bool ignoreIndexed, Serializer& serialize r)
849 { 850 {
850 m_isSerializingAccessor = false; 851 m_isSerializingAccessor = false;
851 while (m_index < m_propertyNames->Length()) { 852 while (m_index < m_propertyNames->Length()) {
852 bool isAccessor = false; 853 bool isAccessor = false;
853 if (!m_nameDone) { 854 if (!m_nameDone) {
854 v8::Local<v8::Value> propertyName = m_propertyNames->Get(m_i ndex); 855 v8::Local<v8::Value> propertyName = m_propertyNames->Get(m_i ndex);
855 if (StateBase* newState = serializer.checkException(this)) 856 if (StateBase* newState = serializer.checkException(this))
856 return newState; 857 return newState;
857 if (propertyName.IsEmpty()) 858 if (propertyName.IsEmpty())
858 return serializer.reportFailure(this); 859 return serializer.reportFailure(this);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 }; 972 };
972 973
973 class SparseArrayState : public AbstractObjectState { 974 class SparseArrayState : public AbstractObjectState {
974 public: 975 public:
975 SparseArrayState(v8::Handle<v8::Array> array, v8::Handle<v8::Array> prop ertyNames, StateBase* next) 976 SparseArrayState(v8::Handle<v8::Array> array, v8::Handle<v8::Array> prop ertyNames, StateBase* next)
976 : AbstractObjectState(array, next) 977 : AbstractObjectState(array, next)
977 { 978 {
978 m_propertyNames = v8::Local<v8::Array>::New(propertyNames); 979 m_propertyNames = v8::Local<v8::Array>::New(propertyNames);
979 } 980 }
980 981
981 virtual StateBase* advance(Serializer& serializer) 982 virtual StateBase* advance(Serializer& serializer)
982 { 983 {
983 return serializeProperties(false, serializer); 984 return serializeProperties(false, serializer);
984 } 985 }
985 986
986 protected: 987 protected:
987 virtual StateBase* objectDone(unsigned numProperties, Serializer& serial izer) 988 virtual StateBase* objectDone(unsigned numProperties, Serializer& serial izer)
988 { 989 {
989 return serializer.writeSparseArray(numProperties, composite().As<v8: :Array>()->Length(), this); 990 return serializer.writeSparseArray(numProperties, composite().As<v8: :Array>()->Length(), this);
990 } 991 }
991 }; 992 };
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 { 1171 {
1171 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(value.As<v8::Object>( )); 1172 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(value.As<v8::Object>( ));
1172 if (!arrayBuffer) 1173 if (!arrayBuffer)
1173 return 0; 1174 return 0;
1174 if (arrayBuffer->isNeutered()) 1175 if (arrayBuffer->isNeutered())
1175 return handleError(DataCloneError, next); 1176 return handleError(DataCloneError, next);
1176 m_writer.writeTransferredArrayBuffer(index); 1177 m_writer.writeTransferredArrayBuffer(index);
1177 return 0; 1178 return 0;
1178 } 1179 }
1179 1180
1180 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount) 1181 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount)
1181 { 1182 {
1182 // Let K be the cost of serializing all property values that are there 1183 // Let K be the cost of serializing all property values that are there
1183 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32 _t key) 1184 // Cost of serializing sparsely: 5*propertyCount + K (5 bytes per uint32 _t key)
1184 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte f or all properties that are not there) 1185 // Cost of serializing densely: K + 1*(length - propertyCount) (1 byte f or all properties that are not there)
1185 // so densely is better than sparsly whenever 6*propertyCount > length 1186 // so densely is better than sparsly whenever 6*propertyCount > length
1186 return 6 * propertyCount >= length; 1187 return 6 * propertyCount >= length;
1187 } 1188 }
1188 1189
1189 StateBase* startArrayState(v8::Handle<v8::Array> array, StateBase* next) 1190 StateBase* startArrayState(v8::Handle<v8::Array> array, StateBase* next)
1190 { 1191 {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 } 1693 }
1693 1694
1694 bool readNumber(v8::Handle<v8::Value>* value) 1695 bool readNumber(v8::Handle<v8::Value>* value)
1695 { 1696 {
1696 double number; 1697 double number;
1697 if (!doReadNumber(&number)) 1698 if (!doReadNumber(&number))
1698 return false; 1699 return false;
1699 *value = v8::Number::New(number); 1700 *value = v8::Number::New(number);
1700 return true; 1701 return true;
1701 } 1702 }
1702 1703
1703 bool readNumberObject(v8::Handle<v8::Value>* value) 1704 bool readNumberObject(v8::Handle<v8::Value>* value)
1704 { 1705 {
1705 double number; 1706 double number;
1706 if (!doReadNumber(&number)) 1707 if (!doReadNumber(&number))
1707 return false; 1708 return false;
1708 *value = v8::NumberObject::New(number); 1709 *value = v8::NumberObject::New(number);
1709 return true; 1710 return true;
1710 } 1711 }
1711 1712
1712 bool readImageData(v8::Handle<v8::Value>* value) 1713 bool readImageData(v8::Handle<v8::Value>* value)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 RefPtr<ArrayBuffer> arrayBuffer; 1765 RefPtr<ArrayBuffer> arrayBuffer;
1765 v8::Handle<v8::Value> arrayBufferV8Value; 1766 v8::Handle<v8::Value> arrayBufferV8Value;
1766 if (!readArrayBufferViewSubTag(&subTag)) 1767 if (!readArrayBufferViewSubTag(&subTag))
1767 return false; 1768 return false;
1768 if (!doReadUint32(&byteOffset)) 1769 if (!doReadUint32(&byteOffset))
1769 return false; 1770 return false;
1770 if (!doReadUint32(&byteLength)) 1771 if (!doReadUint32(&byteLength))
1771 return false; 1772 return false;
1772 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) 1773 if (!creator.consumeTopOfStack(&arrayBufferV8Value))
1773 return false; 1774 return false;
1774 if (arrayBufferV8Value.IsEmpty()) 1775 if (arrayBufferV8Value.IsEmpty())
1775 return false; 1776 return false;
1776 arrayBuffer = V8ArrayBuffer::toNative(arrayBufferV8Value.As<v8::Object>( )); 1777 arrayBuffer = V8ArrayBuffer::toNative(arrayBufferV8Value.As<v8::Object>( ));
1777 if (!arrayBuffer) 1778 if (!arrayBuffer)
1778 return false; 1779 return false;
1779 switch (subTag) { 1780 switch (subTag) {
1780 case ByteArrayTag: 1781 case ByteArrayTag:
1781 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b yteLength), v8::Handle<v8::Object>(), m_isolate); 1782 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b yteLength), v8::Handle<v8::Object>(), m_isolate);
1782 break; 1783 break;
1783 case UnsignedByteArrayTag: 1784 case UnsignedByteArrayTag:
1784 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset, byteLength), v8::Handle<v8::Object>(), m_isolate); 1785 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset, byteLength), v8::Handle<v8::Object>(), m_isolate);
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_ data)); 2361 RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_ data));
2361 m_data = String(); 2362 m_data = String();
2362 return result.release(); 2363 return result.release();
2363 } 2364 }
2364 2365
2365 SerializedScriptValue::SerializedScriptValue() 2366 SerializedScriptValue::SerializedScriptValue()
2366 : m_externallyAllocatedMemory(0) 2367 : m_externallyAllocatedMemory(0)
2367 { 2368 {
2368 } 2369 }
2369 2370
2370 inline void neuterBinding(ArrayBuffer* object) 2371 template<typename T>
2372 inline void neuterBinding(T* object)
2371 { 2373 {
2372 Vector<DOMDataStore*>& allStores = V8PerIsolateData::current()->allStores(); 2374 Vector<DOMDataStore*>& allStores = V8PerIsolateData::current()->allStores();
2373 for (size_t i = 0; i < allStores.size(); i++) { 2375 for (size_t i = 0; i < allStores.size(); i++) {
2374 v8::Handle<v8::Object> wrapper = allStores[i]->get(object);
2375 if (!wrapper.IsEmpty()) {
2376 ASSERT(wrapper->IsArrayBuffer());
2377 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter();
2378 }
2379 }
2380 }
2381
2382 inline void neuterBinding(ArrayBufferView* object)
2383 {
2384 Vector<DOMDataStore*>& allStores = V8PerIsolateData::current()->allStores();
2385 for (size_t i = 0; i < allStores.size(); i++) {
2386 v8::Handle<v8::Object> wrapper = allStores[i]->get(object); 2376 v8::Handle<v8::Object> wrapper = allStores[i]->get(object);
2387 if (!wrapper.IsEmpty()) 2377 if (!wrapper.IsEmpty())
2388 wrapper->SetIndexedPropertiesToExternalArrayData(0, v8::kExternalByt eArray, 0); 2378 wrapper->SetIndexedPropertiesToExternalArrayData(0, v8::kExternalByt eArray, 0);
2389 } 2379 }
2390 } 2380 }
2391 2381
2392 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::transferArrayBuffers(ArrayBufferArray& arrayBuffers, bool& didThrow, v8::Isol ate* isolate) 2382 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::transferArrayBuffers(ArrayBufferArray& arrayBuffers, bool& didThrow, v8::Isol ate* isolate)
2393 { 2383 {
2394 ASSERT(arrayBuffers.size()); 2384 ASSERT(arrayBuffers.size());
2395 2385
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry); 2509 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry);
2520 } 2510 }
2521 } 2511 }
2522 2512
2523 uint32_t SerializedScriptValue::wireFormatVersion() 2513 uint32_t SerializedScriptValue::wireFormatVersion()
2524 { 2514 {
2525 return WebCore::wireFormatVersion; 2515 return WebCore::wireFormatVersion;
2526 } 2516 }
2527 2517
2528 } // namespace WebCore 2518 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/tests/results/V8TestOverloadedConstructors.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698