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, TransferableArray* transferab
les, 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 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::create(); | 16 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::create(); |
17 SerializedScriptValueWriterForModules writer; | 17 SerializedScriptValueWriterForModules writer; |
18 ScriptValueSerializer::Status status; | 18 ScriptValueSerializer::Status status; |
19 String errorMessage; | 19 String errorMessage; |
20 { | 20 { |
21 v8::TryCatch tryCatch(isolate); | 21 v8::TryCatch tryCatch(isolate); |
22 status = SerializedScriptValueFactory::doSerialize(value, writer, transf
erables, blobInfo, serializedValue.get(), tryCatch, errorMessage, isolate); | 22 status = SerializedScriptValueFactory::doSerialize(value, writer, transf
erables, blobInfo, serializedValue.get(), tryCatch, errorMessage, isolate); |
23 if (status == ScriptValueSerializer::JSException) { | 23 if (status == ScriptValueSerializer::JSException) { |
24 // If there was a JS exception thrown, re-throw it. | 24 // If there was a JS exception thrown, re-throw it. |
(...skipping 18 matching lines...) Expand all Loading... |
43 } | 43 } |
44 | 44 |
45 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, const String& data) | 45 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, const String& data) |
46 { | 46 { |
47 SerializedScriptValueWriterForModules writer; | 47 SerializedScriptValueWriterForModules writer; |
48 writer.writeWebCoreString(data); | 48 writer.writeWebCoreString(data); |
49 String wireData = writer.takeWireString(); | 49 String wireData = writer.takeWireString(); |
50 return createFromWire(wireData); | 50 return createFromWire(wireData); |
51 } | 51 } |
52 | 52 |
53 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ
e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, TransferableA
rray* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHand
les, v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate) | 53 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) |
54 { | 54 { |
55 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
blobDataHandles, tryCatch, ScriptState::current(isolate)); | 55 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo,
blobDataHandles, tryCatch, ScriptState::current(isolate)); |
56 ScriptValueSerializer::Status status = serializer.serialize(value); | 56 ScriptValueSerializer::Status status = serializer.serialize(value); |
57 errorMessage = serializer.errorMessage(); | 57 errorMessage = serializer.errorMessage(); |
58 return status; | 58 return status; |
59 } | 59 } |
60 | 60 |
61 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 61 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
62 { | 62 { |
63 if (!data.impl()) | 63 if (!data.impl()) |
64 return v8::Null(isolate); | 64 return v8::Null(isolate); |
65 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); | 65 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); |
66 data.ensure16Bit(); | 66 data.ensure16Bit(); |
67 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 67 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
68 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 68 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
69 // information stored in m_data isn't even encoded in UTF-16. Instead, | 69 // information stored in m_data isn't even encoded in UTF-16. Instead, |
70 // unicode characters are encoded as UTF-8 with two code units per UChar. | 70 // unicode characters are encoded as UTF-8 with two code units per UChar. |
71 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); | 71 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); |
72 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); | 72 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); |
73 return deserializer.deserialize(); | 73 return deserializer.deserialize(); |
74 } | 74 } |
75 | 75 |
76 } // namespace blink | 76 } // namespace blink |
77 | 77 |
OLD | NEW |