| OLD | NEW |
| 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 return SerializedScriptValueFactory::create(isolate, value, writer, transfer
ables, blobInfo, exceptionState); | 17 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
ScriptState::current(isolate)); |
| 18 } | 18 return serializer.serialize(value, transferables, exceptionState); |
| 19 | |
| 20 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ
e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, Transferables
* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles,
v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate) | |
| 21 { | |
| 22 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
blobDataHandles, tryCatch, ScriptState::current(isolate)); | |
| 23 ScriptValueSerializer::Status status = serializer.serialize(value); | |
| 24 errorMessage = serializer.errorMessage(); | |
| 25 return status; | |
| 26 } | 19 } |
| 27 | 20 |
| 28 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) |
| 29 { | 22 { |
| 30 if (!data.impl()) | 23 if (!data.impl()) |
| 31 return v8::Null(isolate); | 24 return v8::Null(isolate); |
| 32 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"); |
| 33 data.ensure16Bit(); | 26 data.ensure16Bit(); |
| 34 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 27 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
| 35 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 28 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
| 36 // 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, |
| 37 // 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. |
| 38 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)); |
| 39 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); | 32 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); |
| 40 return deserializer.deserialize(); | 33 return deserializer.deserialize(); |
| 41 } | 34 } |
| 42 | 35 |
| 43 } // namespace blink | 36 } // namespace blink |
| OLD | NEW |