OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef V8ScriptValueSerializer_h | 5 #ifndef V8ScriptValueSerializer_h |
6 #define V8ScriptValueSerializer_h | 6 #define V8ScriptValueSerializer_h |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/SerializationTag.h" | 10 #include "bindings/core/v8/SerializationTag.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // modules types is implemented in a subclass. | 27 // modules types is implemented in a subclass. |
28 // | 28 // |
29 // A serializer cannot be used multiple times; it is expected that its serialize | 29 // A serializer cannot be used multiple times; it is expected that its serialize |
30 // method will be invoked exactly once. | 30 // method will be invoked exactly once. |
31 class GC_PLUGIN_IGNORE("https://crbug.com/644725") | 31 class GC_PLUGIN_IGNORE("https://crbug.com/644725") |
32 CORE_EXPORT V8ScriptValueSerializer : public v8::ValueSerializer::Delegate { | 32 CORE_EXPORT V8ScriptValueSerializer : public v8::ValueSerializer::Delegate { |
33 STACK_ALLOCATED(); | 33 STACK_ALLOCATED(); |
34 WTF_MAKE_NONCOPYABLE(V8ScriptValueSerializer); | 34 WTF_MAKE_NONCOPYABLE(V8ScriptValueSerializer); |
35 | 35 |
36 public: | 36 public: |
37 explicit V8ScriptValueSerializer(RefPtr<ScriptState>); | 37 using Options = SerializedScriptValue::SerializeOptions; |
38 | 38 explicit V8ScriptValueSerializer(RefPtr<ScriptState>, |
39 // If not null, blobs will have info written into this array and be | 39 const Options& = Options()); |
40 // serialized by index. | |
41 void setBlobInfoArray(WebBlobInfoArray* blobInfoArray) { | |
42 m_blobInfoArray = blobInfoArray; | |
43 } | |
44 | 40 |
45 RefPtr<SerializedScriptValue> serialize(v8::Local<v8::Value>, | 41 RefPtr<SerializedScriptValue> serialize(v8::Local<v8::Value>, |
46 Transferables*, | |
47 ExceptionState&); | 42 ExceptionState&); |
48 | 43 |
49 protected: | 44 protected: |
50 // Returns true if the DOM object was successfully written. | 45 // Returns true if the DOM object was successfully written. |
51 // If false is returned and no more specific exception is thrown, a generic | 46 // If false is returned and no more specific exception is thrown, a generic |
52 // DataCloneError message will be used. | 47 // DataCloneError message will be used. |
53 virtual bool writeDOMObject(ScriptWrappable*, ExceptionState&); | 48 virtual bool writeDOMObject(ScriptWrappable*, ExceptionState&); |
54 | 49 |
55 void writeTag(SerializationTag tag) { | 50 void writeTag(SerializationTag tag) { |
56 uint8_t tagByte = tag; | 51 uint8_t tagByte = tag; |
57 m_serializer.WriteRawBytes(&tagByte, 1); | 52 m_serializer.WriteRawBytes(&tagByte, 1); |
58 } | 53 } |
59 void writeUint32(uint32_t value) { m_serializer.WriteUint32(value); } | 54 void writeUint32(uint32_t value) { m_serializer.WriteUint32(value); } |
60 void writeUint64(uint64_t value) { m_serializer.WriteUint64(value); } | 55 void writeUint64(uint64_t value) { m_serializer.WriteUint64(value); } |
61 void writeDouble(double value) { m_serializer.WriteDouble(value); } | 56 void writeDouble(double value) { m_serializer.WriteDouble(value); } |
62 void writeRawBytes(const void* data, size_t size) { | 57 void writeRawBytes(const void* data, size_t size) { |
63 m_serializer.WriteRawBytes(data, size); | 58 m_serializer.WriteRawBytes(data, size); |
64 } | 59 } |
65 void writeUTF8String(const String&); | 60 void writeUTF8String(const String&); |
66 | 61 |
67 private: | 62 private: |
68 // Transfer is split into two phases: scanning the transferables so that we | 63 // Transfer is split into two phases: scanning the transferables so that we |
69 // don't have to serialize the data (just an index), and finalizing (to | 64 // don't have to serialize the data (just an index), and finalizing (to |
70 // neuter objects in the source context). | 65 // neuter objects in the source context). |
71 // This separation is required by the spec (it prevents neutering from | 66 // This separation is required by the spec (it prevents neutering from |
72 // happening if there's a failure earlier in serialization). | 67 // happening if there's a failure earlier in serialization). |
73 void prepareTransfer(Transferables*, ExceptionState&); | 68 void prepareTransfer(ExceptionState&); |
74 void finalizeTransfer(ExceptionState&); | 69 void finalizeTransfer(ExceptionState&); |
75 | 70 |
76 // Shared between File and FileList logic; does not write a leading tag. | 71 // Shared between File and FileList logic; does not write a leading tag. |
77 bool writeFile(File*, ExceptionState&); | 72 bool writeFile(File*, ExceptionState&); |
78 | 73 |
79 // v8::ValueSerializer::Delegate | 74 // v8::ValueSerializer::Delegate |
80 void ThrowDataCloneError(v8::Local<v8::String> message) override; | 75 void ThrowDataCloneError(v8::Local<v8::String> message) override; |
81 v8::Maybe<bool> WriteHostObject(v8::Isolate*, | 76 v8::Maybe<bool> WriteHostObject(v8::Isolate*, |
82 v8::Local<v8::Object> message) override; | 77 v8::Local<v8::Object> message) override; |
83 v8::Maybe<uint32_t> GetSharedArrayBufferId( | 78 v8::Maybe<uint32_t> GetSharedArrayBufferId( |
(...skipping 14 matching lines...) Expand all Loading... |
98 ArrayBufferArray m_sharedArrayBuffers; | 93 ArrayBufferArray m_sharedArrayBuffers; |
99 | 94 |
100 #if DCHECK_IS_ON() | 95 #if DCHECK_IS_ON() |
101 bool m_serializeInvoked = false; | 96 bool m_serializeInvoked = false; |
102 #endif | 97 #endif |
103 }; | 98 }; |
104 | 99 |
105 } // namespace blink | 100 } // namespace blink |
106 | 101 |
107 #endif // V8ScriptValueSerializer_h | 102 #endif // V8ScriptValueSerializer_h |
OLD | NEW |