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: third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp

Issue 2101953002: [Refactoring] Clean up code for serializing ScriptValues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/SerializedScriptValue.h" 8 #include "bindings/core/v8/SerializedScriptValue.h"
9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" 9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create (v8::Isolate* isolate, v8::Local<v8::Value> value, Transferables* transferables, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState) 14 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create (v8::Isolate* isolate, v8::Local<v8::Value> value, Transferables* transferables, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState)
15 { 15 {
16 SerializedScriptValueWriterForModules writer; 16 SerializedScriptValueWriterForModules writer;
17 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo, ScriptState::current(isolate)); 17 ScriptValueSerializerForModules serializer(writer, blobInfo, ScriptState::cu rrent(isolate));
18 return serializer.serialize(value, transferables, exceptionState); 18 return serializer.serialize(value, transferables, exceptionState);
19 } 19 }
20 20
21 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String& data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) 21 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String& data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo)
22 { 22 {
23 if (!data.impl()) 23 if (!data.impl())
24 return v8::Null(isolate); 24 return v8::Null(isolate);
25 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes"); 25 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes");
26 data.ensure16Bit(); 26 data.ensure16Bit();
27 // FIXME: SerializedScriptValue shouldn't use String for its underlying 27 // FIXME: SerializedScriptValue shouldn't use String for its underlying
28 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The 28 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
29 // information stored in m_data isn't even encoded in UTF-16. Instead, 29 // information stored in m_data isn't even encoded in UTF-16. Instead,
30 // unicode characters are encoded as UTF-8 with two code units per UChar. 30 // unicode characters are encoded as UTF-8 with two code units per UChar.
31 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t* >(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc riptState::current(isolate)); 31 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t* >(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc riptState::current(isolate));
32 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu fferContentsArray, imageBitmapContentsArray); 32 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu fferContentsArray, imageBitmapContentsArray);
33 return deserializer.deserialize(); 33 return deserializer.deserialize();
34 } 34 }
35 35
36 } // namespace blink 36 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698