| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 V8_VALUE_SERIALIZER_H_ | 5 #ifndef V8_VALUE_SERIALIZER_H_ |
| 6 #define V8_VALUE_SERIALIZER_H_ | 6 #define V8_VALUE_SERIALIZER_H_ |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 std::vector<uint8_t> ReleaseBuffer() { return std::move(buffer_); } | 62 std::vector<uint8_t> ReleaseBuffer() { return std::move(buffer_); } |
| 63 | 63 |
| 64 /* | 64 /* |
| 65 * Marks an ArrayBuffer as havings its contents transferred out of band. | 65 * Marks an ArrayBuffer as havings its contents transferred out of band. |
| 66 * Pass the corresponding JSArrayBuffer in the deserializing context to | 66 * Pass the corresponding JSArrayBuffer in the deserializing context to |
| 67 * ValueDeserializer::TransferArrayBuffer. | 67 * ValueDeserializer::TransferArrayBuffer. |
| 68 */ | 68 */ |
| 69 void TransferArrayBuffer(uint32_t transfer_id, | 69 void TransferArrayBuffer(uint32_t transfer_id, |
| 70 Handle<JSArrayBuffer> array_buffer); | 70 Handle<JSArrayBuffer> array_buffer); |
| 71 | 71 |
| 72 /* |
| 73 * Publicly exposed wire format writing methods. |
| 74 * These are intended for use within the delegate's WriteHostObject method. |
| 75 */ |
| 76 void WriteUint32(uint32_t value); |
| 77 void WriteUint64(uint64_t value); |
| 78 void WriteRawBytes(const void* source, size_t length); |
| 79 |
| 72 private: | 80 private: |
| 73 // Writing the wire format. | 81 // Writing the wire format. |
| 74 void WriteTag(SerializationTag tag); | 82 void WriteTag(SerializationTag tag); |
| 75 template <typename T> | 83 template <typename T> |
| 76 void WriteVarint(T value); | 84 void WriteVarint(T value); |
| 77 template <typename T> | 85 template <typename T> |
| 78 void WriteZigZag(T value); | 86 void WriteZigZag(T value); |
| 79 void WriteDouble(double value); | 87 void WriteDouble(double value); |
| 80 void WriteOneByteString(Vector<const uint8_t> chars); | 88 void WriteOneByteString(Vector<const uint8_t> chars); |
| 81 void WriteTwoByteString(Vector<const uc16> chars); | 89 void WriteTwoByteString(Vector<const uc16> chars); |
| 82 void WriteRawBytes(const void* source, size_t length); | |
| 83 uint8_t* ReserveRawBytes(size_t bytes); | 90 uint8_t* ReserveRawBytes(size_t bytes); |
| 84 | 91 |
| 85 // Writing V8 objects of various kinds. | 92 // Writing V8 objects of various kinds. |
| 86 void WriteOddball(Oddball* oddball); | 93 void WriteOddball(Oddball* oddball); |
| 87 void WriteSmi(Smi* smi); | 94 void WriteSmi(Smi* smi); |
| 88 void WriteHeapNumber(HeapNumber* number); | 95 void WriteHeapNumber(HeapNumber* number); |
| 89 void WriteString(Handle<String> string); | 96 void WriteString(Handle<String> string); |
| 90 Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver) WARN_UNUSED_RESULT; | 97 Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver) WARN_UNUSED_RESULT; |
| 91 Maybe<bool> WriteJSObject(Handle<JSObject> object) WARN_UNUSED_RESULT; | 98 Maybe<bool> WriteJSObject(Handle<JSObject> object) WARN_UNUSED_RESULT; |
| 92 Maybe<bool> WriteJSObjectSlow(Handle<JSObject> object) WARN_UNUSED_RESULT; | 99 Maybe<bool> WriteJSObjectSlow(Handle<JSObject> object) WARN_UNUSED_RESULT; |
| 93 Maybe<bool> WriteJSArray(Handle<JSArray> array) WARN_UNUSED_RESULT; | 100 Maybe<bool> WriteJSArray(Handle<JSArray> array) WARN_UNUSED_RESULT; |
| 94 void WriteJSDate(JSDate* date); | 101 void WriteJSDate(JSDate* date); |
| 95 Maybe<bool> WriteJSValue(Handle<JSValue> value) WARN_UNUSED_RESULT; | 102 Maybe<bool> WriteJSValue(Handle<JSValue> value) WARN_UNUSED_RESULT; |
| 96 void WriteJSRegExp(JSRegExp* regexp); | 103 void WriteJSRegExp(JSRegExp* regexp); |
| 97 Maybe<bool> WriteJSMap(Handle<JSMap> map) WARN_UNUSED_RESULT; | 104 Maybe<bool> WriteJSMap(Handle<JSMap> map) WARN_UNUSED_RESULT; |
| 98 Maybe<bool> WriteJSSet(Handle<JSSet> map) WARN_UNUSED_RESULT; | 105 Maybe<bool> WriteJSSet(Handle<JSSet> map) WARN_UNUSED_RESULT; |
| 99 Maybe<bool> WriteJSArrayBuffer(JSArrayBuffer* array_buffer); | 106 Maybe<bool> WriteJSArrayBuffer(JSArrayBuffer* array_buffer); |
| 100 Maybe<bool> WriteJSArrayBufferView(JSArrayBufferView* array_buffer); | 107 Maybe<bool> WriteJSArrayBufferView(JSArrayBufferView* array_buffer); |
| 108 Maybe<bool> WriteHostObject(Handle<JSObject> object) WARN_UNUSED_RESULT; |
| 101 | 109 |
| 102 /* | 110 /* |
| 103 * Reads the specified keys from the object and writes key-value pairs to the | 111 * Reads the specified keys from the object and writes key-value pairs to the |
| 104 * buffer. Returns the number of keys actually written, which may be smaller | 112 * buffer. Returns the number of keys actually written, which may be smaller |
| 105 * if some keys are not own properties when accessed. | 113 * if some keys are not own properties when accessed. |
| 106 */ | 114 */ |
| 107 Maybe<uint32_t> WriteJSObjectPropertiesSlow( | 115 Maybe<uint32_t> WriteJSObjectPropertiesSlow( |
| 108 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT; | 116 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT; |
| 109 | 117 |
| 110 /* | 118 /* |
| (...skipping 20 matching lines...) Expand all Loading... |
| 131 | 139 |
| 132 DISALLOW_COPY_AND_ASSIGN(ValueSerializer); | 140 DISALLOW_COPY_AND_ASSIGN(ValueSerializer); |
| 133 }; | 141 }; |
| 134 | 142 |
| 135 /* | 143 /* |
| 136 * Deserializes values from data written with ValueSerializer, or a compatible | 144 * Deserializes values from data written with ValueSerializer, or a compatible |
| 137 * implementation. | 145 * implementation. |
| 138 */ | 146 */ |
| 139 class ValueDeserializer { | 147 class ValueDeserializer { |
| 140 public: | 148 public: |
| 141 ValueDeserializer(Isolate* isolate, Vector<const uint8_t> data); | 149 ValueDeserializer(Isolate* isolate, Vector<const uint8_t> data, |
| 150 v8::ValueDeserializer::Delegate* delegate); |
| 142 ~ValueDeserializer(); | 151 ~ValueDeserializer(); |
| 143 | 152 |
| 144 /* | 153 /* |
| 145 * Runs version detection logic, which may fail if the format is invalid. | 154 * Runs version detection logic, which may fail if the format is invalid. |
| 146 */ | 155 */ |
| 147 Maybe<bool> ReadHeader() WARN_UNUSED_RESULT; | 156 Maybe<bool> ReadHeader() WARN_UNUSED_RESULT; |
| 148 | 157 |
| 149 /* | 158 /* |
| 150 * Reads the underlying wire format version. Likely mostly to be useful to | 159 * Reads the underlying wire format version. Likely mostly to be useful to |
| 151 * legacy code reading old wire format versions. Must be called after | 160 * legacy code reading old wire format versions. Must be called after |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 MaybeHandle<Object> ReadObjectUsingEntireBufferForLegacyFormat() | 177 MaybeHandle<Object> ReadObjectUsingEntireBufferForLegacyFormat() |
| 169 WARN_UNUSED_RESULT; | 178 WARN_UNUSED_RESULT; |
| 170 | 179 |
| 171 /* | 180 /* |
| 172 * Accepts the array buffer corresponding to the one passed previously to | 181 * Accepts the array buffer corresponding to the one passed previously to |
| 173 * ValueSerializer::TransferArrayBuffer. | 182 * ValueSerializer::TransferArrayBuffer. |
| 174 */ | 183 */ |
| 175 void TransferArrayBuffer(uint32_t transfer_id, | 184 void TransferArrayBuffer(uint32_t transfer_id, |
| 176 Handle<JSArrayBuffer> array_buffer); | 185 Handle<JSArrayBuffer> array_buffer); |
| 177 | 186 |
| 187 /* |
| 188 * Publicly exposed wire format writing methods. |
| 189 * These are intended for use within the delegate's WriteHostObject method. |
| 190 */ |
| 191 bool ReadUint32(uint32_t* value) WARN_UNUSED_RESULT; |
| 192 bool ReadUint64(uint64_t* value) WARN_UNUSED_RESULT; |
| 193 bool ReadRawBytes(size_t length, const void** data) WARN_UNUSED_RESULT; |
| 194 |
| 178 private: | 195 private: |
| 179 // Reading the wire format. | 196 // Reading the wire format. |
| 180 Maybe<SerializationTag> PeekTag() const WARN_UNUSED_RESULT; | 197 Maybe<SerializationTag> PeekTag() const WARN_UNUSED_RESULT; |
| 181 void ConsumeTag(SerializationTag peeked_tag); | 198 void ConsumeTag(SerializationTag peeked_tag); |
| 182 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT; | 199 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT; |
| 183 template <typename T> | 200 template <typename T> |
| 184 Maybe<T> ReadVarint() WARN_UNUSED_RESULT; | 201 Maybe<T> ReadVarint() WARN_UNUSED_RESULT; |
| 185 template <typename T> | 202 template <typename T> |
| 186 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT; | 203 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT; |
| 187 Maybe<double> ReadDouble() WARN_UNUSED_RESULT; | 204 Maybe<double> ReadDouble() WARN_UNUSED_RESULT; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 201 MaybeHandle<JSDate> ReadJSDate() WARN_UNUSED_RESULT; | 218 MaybeHandle<JSDate> ReadJSDate() WARN_UNUSED_RESULT; |
| 202 MaybeHandle<JSValue> ReadJSValue(SerializationTag tag) WARN_UNUSED_RESULT; | 219 MaybeHandle<JSValue> ReadJSValue(SerializationTag tag) WARN_UNUSED_RESULT; |
| 203 MaybeHandle<JSRegExp> ReadJSRegExp() WARN_UNUSED_RESULT; | 220 MaybeHandle<JSRegExp> ReadJSRegExp() WARN_UNUSED_RESULT; |
| 204 MaybeHandle<JSMap> ReadJSMap() WARN_UNUSED_RESULT; | 221 MaybeHandle<JSMap> ReadJSMap() WARN_UNUSED_RESULT; |
| 205 MaybeHandle<JSSet> ReadJSSet() WARN_UNUSED_RESULT; | 222 MaybeHandle<JSSet> ReadJSSet() WARN_UNUSED_RESULT; |
| 206 MaybeHandle<JSArrayBuffer> ReadJSArrayBuffer() WARN_UNUSED_RESULT; | 223 MaybeHandle<JSArrayBuffer> ReadJSArrayBuffer() WARN_UNUSED_RESULT; |
| 207 MaybeHandle<JSArrayBuffer> ReadTransferredJSArrayBuffer(bool is_shared) | 224 MaybeHandle<JSArrayBuffer> ReadTransferredJSArrayBuffer(bool is_shared) |
| 208 WARN_UNUSED_RESULT; | 225 WARN_UNUSED_RESULT; |
| 209 MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView( | 226 MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView( |
| 210 Handle<JSArrayBuffer> buffer) WARN_UNUSED_RESULT; | 227 Handle<JSArrayBuffer> buffer) WARN_UNUSED_RESULT; |
| 228 MaybeHandle<JSObject> ReadHostObject() WARN_UNUSED_RESULT; |
| 211 | 229 |
| 212 /* | 230 /* |
| 213 * Reads key-value pairs into the object until the specified end tag is | 231 * Reads key-value pairs into the object until the specified end tag is |
| 214 * encountered. If successful, returns the number of properties read. | 232 * encountered. If successful, returns the number of properties read. |
| 215 */ | 233 */ |
| 216 Maybe<uint32_t> ReadJSObjectProperties(Handle<JSObject> object, | 234 Maybe<uint32_t> ReadJSObjectProperties(Handle<JSObject> object, |
| 217 SerializationTag end_tag); | 235 SerializationTag end_tag); |
| 218 | 236 |
| 219 // Manipulating the map from IDs to reified objects. | 237 // Manipulating the map from IDs to reified objects. |
| 220 bool HasObjectWithID(uint32_t id); | 238 bool HasObjectWithID(uint32_t id); |
| 221 MaybeHandle<JSReceiver> GetObjectWithID(uint32_t id); | 239 MaybeHandle<JSReceiver> GetObjectWithID(uint32_t id); |
| 222 void AddObjectWithID(uint32_t id, Handle<JSReceiver> object); | 240 void AddObjectWithID(uint32_t id, Handle<JSReceiver> object); |
| 223 | 241 |
| 224 Isolate* const isolate_; | 242 Isolate* const isolate_; |
| 243 v8::ValueDeserializer::Delegate* const delegate_; |
| 225 const uint8_t* position_; | 244 const uint8_t* position_; |
| 226 const uint8_t* const end_; | 245 const uint8_t* const end_; |
| 227 uint32_t version_ = 0; | 246 uint32_t version_ = 0; |
| 228 uint32_t next_id_ = 0; | 247 uint32_t next_id_ = 0; |
| 229 | 248 |
| 230 // Always global handles. | 249 // Always global handles. |
| 231 Handle<SeededNumberDictionary> id_map_; | 250 Handle<SeededNumberDictionary> id_map_; |
| 232 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; | 251 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; |
| 233 | 252 |
| 234 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); | 253 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); |
| 235 }; | 254 }; |
| 236 | 255 |
| 237 } // namespace internal | 256 } // namespace internal |
| 238 } // namespace v8 | 257 } // namespace v8 |
| 239 | 258 |
| 240 #endif // V8_VALUE_SERIALIZER_H_ | 259 #endif // V8_VALUE_SERIALIZER_H_ |
| OLD | NEW |