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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp

Issue 2684843005: Inline the V8BasedStructuredClone feature. (Closed)
Patch Set: Created 3 years, 10 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/modules/v8/SerializedScriptValueForModulesFactory.h" 5 #include "bindings/modules/v8/SerializedScriptValueForModulesFactory.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/SerializedScriptValue.h"
9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h"
10 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h" 7 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h"
11 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h" 8 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h"
12 #include "core/dom/ExceptionCode.h"
13 #include "platform/instrumentation/tracing/TraceEvent.h" 9 #include "platform/instrumentation/tracing/TraceEvent.h"
14 10
15 namespace blink { 11 namespace blink {
16 12
17 PassRefPtr<SerializedScriptValue> 13 PassRefPtr<SerializedScriptValue>
18 SerializedScriptValueForModulesFactory::create(v8::Isolate* isolate, 14 SerializedScriptValueForModulesFactory::create(v8::Isolate* isolate,
19 v8::Local<v8::Value> value, 15 v8::Local<v8::Value> value,
20 Transferables* transferables, 16 Transferables* transferables,
21 WebBlobInfoArray* blobInfo, 17 WebBlobInfoArray* blobInfo,
22 ExceptionState& exceptionState) { 18 ExceptionState& exceptionState) {
23 TRACE_EVENT0("blink", "SerializedScriptValueFactory::create"); 19 TRACE_EVENT0("blink", "SerializedScriptValueFactory::create");
24 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { 20 V8ScriptValueSerializerForModules serializer(ScriptState::current(isolate));
25 V8ScriptValueSerializerForModules serializer(ScriptState::current(isolate)); 21 serializer.setBlobInfoArray(blobInfo);
26 serializer.setBlobInfoArray(blobInfo);
27 return serializer.serialize(value, transferables, exceptionState);
28 }
29 SerializedScriptValueWriterForModules writer;
30 ScriptValueSerializerForModules serializer(writer, blobInfo,
31 ScriptState::current(isolate));
32 return serializer.serialize(value, transferables, exceptionState); 22 return serializer.serialize(value, transferables, exceptionState);
33 } 23 }
34 24
35 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize( 25 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(
36 SerializedScriptValue* value, 26 SerializedScriptValue* value,
37 v8::Isolate* isolate, 27 v8::Isolate* isolate,
38 MessagePortArray* messagePorts, 28 MessagePortArray* messagePorts,
39 const WebBlobInfoArray* blobInfo) { 29 const WebBlobInfoArray* blobInfo) {
40 TRACE_EVENT0("blink", "SerializedScriptValueFactory::deserialize"); 30 TRACE_EVENT0("blink", "SerializedScriptValueFactory::deserialize");
41 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { 31 V8ScriptValueDeserializerForModules deserializer(
42 V8ScriptValueDeserializerForModules deserializer( 32 ScriptState::current(isolate), value);
43 ScriptState::current(isolate), value); 33 deserializer.setTransferredMessagePorts(messagePorts);
44 deserializer.setTransferredMessagePorts(messagePorts); 34 deserializer.setBlobInfoArray(blobInfo);
45 deserializer.setBlobInfoArray(blobInfo);
46 return deserializer.deserialize();
47 }
48 // deserialize() can run arbitrary script (e.g., setters), which could result
49 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along
50 // with our internal data) throughout the operation.
51 RefPtr<SerializedScriptValue> protect(value);
52 if (!value->dataLengthInBytes())
53 return v8::Null(isolate);
54 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2,
55 "BufferValueType should be 2 bytes");
56 // FIXME: SerializedScriptValue shouldn't use String for its underlying
57 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
58 // information stored in m_data isn't even encoded in UTF-16. Instead,
59 // unicode characters are encoded as UTF-8 with two code units per UChar.
60 SerializedScriptValueReaderForModules reader(
61 value->data(), value->dataLengthInBytes(), blobInfo,
62 value->blobDataHandles(), ScriptState::current(isolate));
63 ScriptValueDeserializerForModules deserializer(
64 reader, messagePorts, value->getArrayBufferContentsArray(),
65 value->getImageBitmapContentsArray());
66 return deserializer.deserialize(); 35 return deserializer.deserialize();
67 } 36 }
68 37
69 } // namespace blink 38 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698