| 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 return SerializedScriptValueFactory::create(isolate, value, writer, transfer
ables, blobInfo, exceptionState); |
| 18 } | 18 } |
| 19 | 19 |
| 20 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, const String& data) | |
| 21 { | |
| 22 SerializedScriptValueWriterForModules writer; | |
| 23 writer.writeWebCoreString(data); | |
| 24 String wireData = writer.takeWireString(); | |
| 25 return createFromWire(wireData); | |
| 26 } | |
| 27 | |
| 28 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) | 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) |
| 29 { | 21 { |
| 30 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
blobDataHandles, tryCatch, ScriptState::current(isolate)); | 22 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
blobDataHandles, tryCatch, ScriptState::current(isolate)); |
| 31 ScriptValueSerializer::Status status = serializer.serialize(value); | 23 ScriptValueSerializer::Status status = serializer.serialize(value); |
| 32 errorMessage = serializer.errorMessage(); | 24 errorMessage = serializer.errorMessage(); |
| 33 return status; | 25 return status; |
| 34 } | 26 } |
| 35 | 27 |
| 36 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 28 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
| 37 { | 29 { |
| 38 if (!data.impl()) | 30 if (!data.impl()) |
| 39 return v8::Null(isolate); | 31 return v8::Null(isolate); |
| 40 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); | 32 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); |
| 41 data.ensure16Bit(); | 33 data.ensure16Bit(); |
| 42 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 34 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
| 43 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 35 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
| 44 // information stored in m_data isn't even encoded in UTF-16. Instead, | 36 // information stored in m_data isn't even encoded in UTF-16. Instead, |
| 45 // unicode characters are encoded as UTF-8 with two code units per UChar. | 37 // unicode characters are encoded as UTF-8 with two code units per UChar. |
| 46 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); | 38 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); |
| 47 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); | 39 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); |
| 48 return deserializer.deserialize(); | 40 return deserializer.deserialize(); |
| 49 } | 41 } |
| 50 | 42 |
| 51 } // namespace blink | 43 } // namespace blink |
| 52 | |
| OLD | NEW |