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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp

Issue 2277403002: Support structured clone atop v8::ValueSerializer behind a RuntimeEnabledFeature. (Closed)
Patch Set: Merge branch 'master' into serialization-feature Created 4 years, 3 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
OLDNEW
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 "bindings/core/v8/ScriptValueSerializer.h" 5 #include "bindings/core/v8/ScriptValueSerializer.h"
6 6
7 #include "bindings/core/v8/Transferables.h" 7 #include "bindings/core/v8/Transferables.h"
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"
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 CustomCountHistogram domWrapperCount{"Blink.ScriptValueSerializer.DOMWra pperCount", 0, 100000, 50}; 728 CustomCountHistogram domWrapperCount{"Blink.ScriptValueSerializer.DOMWra pperCount", 0, 100000, 50};
729 }; 729 };
730 DEFINE_THREAD_SAFE_STATIC_LOCAL(ObjectCountHistograms, histograms, new Objec tCountHistograms); 730 DEFINE_THREAD_SAFE_STATIC_LOCAL(ObjectCountHistograms, histograms, new Objec tCountHistograms);
731 histograms.primitiveCount.count(primitiveCount); 731 histograms.primitiveCount.count(primitiveCount);
732 histograms.jsObjectCount.count(jsObjectCount); 732 histograms.jsObjectCount.count(jsObjectCount);
733 histograms.domWrapperCount.count(domWrapperCount); 733 histograms.domWrapperCount.count(domWrapperCount);
734 } 734 }
735 735
736 PassRefPtr<SerializedScriptValue> ScriptValueSerializer::serialize(v8::Local<v8: :Value> value, Transferables* transferables, ExceptionState& exceptionState) 736 PassRefPtr<SerializedScriptValue> ScriptValueSerializer::serialize(v8::Local<v8: :Value> value, Transferables* transferables, ExceptionState& exceptionState)
737 { 737 {
738 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) {
739 v8::HandleScope scope(isolate());
740 v8::ValueSerializer serializer(isolate());
741 serializer.WriteHeader();
742 if (!serializer.WriteValue(context(), value).FromMaybe(false)) {
haraken 2016/08/29 14:12:14 Use To instead.
jbroman 2016/08/29 14:29:37 Can do, though doing so is more verbose in this ca
haraken 2016/08/29 16:25:01 V8 APIs around Maybe/MaybeLocal are really confusi
jbroman 2016/08/29 17:07:41 Done.
743 if (m_tryCatch.HasCaught()) {
744 exceptionState.rethrowV8Exception(m_tryCatch.Exception());
745 } else {
haraken 2016/08/29 14:12:14 This shouldn't happen. To returns false if and onl
jbroman 2016/08/29 14:29:37 Technically, Maybe::To returns false if and only i
746 exceptionState.throwDOMException(DataCloneError, "An object coul d not be cloned.");
747 }
748 return nullptr;
749 }
750 std::vector<uint8_t> buffer = serializer.ReleaseBuffer();
751 // TODO(jbroman): Remove this old conversion to WTF::String.
752 if (buffer.size() % 2)
753 buffer.push_back(0);
754 return SerializedScriptValue::create(String(reinterpret_cast<const UChar *>(&buffer[0]), buffer.size() / 2));
755 }
756
738 m_primitiveCount = m_jsObjectCount = m_domWrapperCount = 0; 757 m_primitiveCount = m_jsObjectCount = m_domWrapperCount = 0;
739 758
740 DCHECK(!m_blobDataHandles); 759 DCHECK(!m_blobDataHandles);
741 760
742 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(); 761 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e();
743 762
744 m_blobDataHandles = &serializedValue->blobDataHandles(); 763 m_blobDataHandles = &serializedValue->blobDataHandles();
745 if (transferables) 764 if (transferables)
746 copyTransferables(*transferables); 765 copyTransferables(*transferables);
747 766
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 if (it != m_blobDataHandles.end()) { 2139 if (it != m_blobDataHandles.end()) {
2121 // make assertions about type and size? 2140 // make assertions about type and size?
2122 return it->value; 2141 return it->value;
2123 } 2142 }
2124 return BlobDataHandle::create(uuid, type, size); 2143 return BlobDataHandle::create(uuid, type, size);
2125 } 2144 }
2126 2145
2127 v8::Local<v8::Value> ScriptValueDeserializer::deserialize() 2146 v8::Local<v8::Value> ScriptValueDeserializer::deserialize()
2128 { 2147 {
2129 v8::Isolate* isolate = m_reader.getScriptState()->isolate(); 2148 v8::Isolate* isolate = m_reader.getScriptState()->isolate();
2149
2150 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) {
2151 v8::EscapableHandleScope scope(isolate);
2152 v8::TryCatch tryCatch(isolate);
2153 v8::ValueDeserializer deserializer(isolate, m_reader.buffer(), m_reader. length());
2154 deserializer.SetSupportsLegacyWireFormat(true);
2155 if (!deserializer.ReadHeader().FromMaybe(false))
haraken 2016/08/29 14:12:14 Use To instead.
2156 return v8::Null(isolate);
2157 v8::Local<v8::Context> context = m_reader.getScriptState()->context();
2158 v8::Local<v8::Value> value;
2159 if (!deserializer.ReadValue(context).ToLocal(&value))
2160 return v8::Null(isolate);
2161 return scope.Escape(value);
2162 }
2163
2130 if (!m_reader.readVersion(m_version) || m_version > SerializedScriptValue::w ireFormatVersion) 2164 if (!m_reader.readVersion(m_version) || m_version > SerializedScriptValue::w ireFormatVersion)
2131 return v8::Null(isolate); 2165 return v8::Null(isolate);
2132 m_reader.setVersion(m_version); 2166 m_reader.setVersion(m_version);
2133 v8::EscapableHandleScope scope(isolate); 2167 v8::EscapableHandleScope scope(isolate);
2134 while (!m_reader.isEof()) { 2168 while (!m_reader.isEof()) {
2135 if (!doDeserialize()) 2169 if (!doDeserialize())
2136 return v8::Null(isolate); 2170 return v8::Null(isolate);
2137 } 2171 }
2138 if (stackDepth() != 1 || m_openCompositeReferenceStack.size()) 2172 if (stackDepth() != 1 || m_openCompositeReferenceStack.size())
2139 return v8::Null(isolate); 2173 return v8::Null(isolate);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 return false; 2481 return false;
2448 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; 2482 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1];
2449 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); 2483 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1);
2450 if (objectReference >= m_objectPool.size()) 2484 if (objectReference >= m_objectPool.size())
2451 return false; 2485 return false;
2452 *object = m_objectPool[objectReference]; 2486 *object = m_objectPool[objectReference];
2453 return true; 2487 return true;
2454 } 2488 }
2455 2489
2456 } // namespace blink 2490 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698