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

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

Issue 2494823002: V8ScriptValueSerializer: Use PartitionAlloc for the buffer, and avoid copying it into a String. (Closed)
Patch Set: initialize SerializedScriptValue::m_dataBufferSize Created 4 years, 1 month 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 "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h" 10 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 V8ScriptValueDeserializerForModules deserializer( 42 V8ScriptValueDeserializerForModules deserializer(
43 ScriptState::current(isolate), value); 43 ScriptState::current(isolate), value);
44 deserializer.setTransferredMessagePorts(messagePorts); 44 deserializer.setTransferredMessagePorts(messagePorts);
45 deserializer.setBlobInfoArray(blobInfo); 45 deserializer.setBlobInfoArray(blobInfo);
46 return deserializer.deserialize(); 46 return deserializer.deserialize();
47 } 47 }
48 // deserialize() can run arbitrary script (e.g., setters), which could result 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 49 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along
50 // with our internal data) throughout the operation. 50 // with our internal data) throughout the operation.
51 RefPtr<SerializedScriptValue> protect(value); 51 RefPtr<SerializedScriptValue> protect(value);
52 String& data = value->data(); 52 if (!value->dataLengthInBytes())
53 if (!data.impl())
54 return v8::Null(isolate); 53 return v8::Null(isolate);
55 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, 54 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2,
56 "BufferValueType should be 2 bytes"); 55 "BufferValueType should be 2 bytes");
57 data.ensure16Bit();
58 // FIXME: SerializedScriptValue shouldn't use String for its underlying 56 // FIXME: SerializedScriptValue shouldn't use String for its underlying
59 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The 57 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
60 // information stored in m_data isn't even encoded in UTF-16. Instead, 58 // information stored in m_data isn't even encoded in UTF-16. Instead,
61 // unicode characters are encoded as UTF-8 with two code units per UChar. 59 // unicode characters are encoded as UTF-8 with two code units per UChar.
62 SerializedScriptValueReaderForModules reader( 60 SerializedScriptValueReaderForModules reader(
63 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), 61 value->data(), value->dataLengthInBytes(), blobInfo,
64 2 * data.length(), blobInfo, value->blobDataHandles(), 62 value->blobDataHandles(), ScriptState::current(isolate));
65 ScriptState::current(isolate));
66 ScriptValueDeserializerForModules deserializer( 63 ScriptValueDeserializerForModules deserializer(
67 reader, messagePorts, value->getArrayBufferContentsArray(), 64 reader, messagePorts, value->getArrayBufferContentsArray(),
68 value->getImageBitmapContentsArray()); 65 value->getImageBitmapContentsArray());
69 return deserializer.deserialize(); 66 return deserializer.deserialize();
70 } 67 }
71 68
72 } // namespace blink 69 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698