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 13 matching lines...) Expand all Loading... |
24 class JSArrayBuffer; | 24 class JSArrayBuffer; |
25 class JSArrayBufferView; | 25 class JSArrayBufferView; |
26 class JSDate; | 26 class JSDate; |
27 class JSMap; | 27 class JSMap; |
28 class JSRegExp; | 28 class JSRegExp; |
29 class JSSet; | 29 class JSSet; |
30 class JSValue; | 30 class JSValue; |
31 class Object; | 31 class Object; |
32 class Oddball; | 32 class Oddball; |
33 class Smi; | 33 class Smi; |
34 class WasmModuleObject; | |
35 | 34 |
36 enum class SerializationTag : uint8_t; | 35 enum class SerializationTag : uint8_t; |
37 | 36 |
38 /** | 37 /** |
39 * Writes V8 objects in a binary format that allows the objects to be cloned | 38 * Writes V8 objects in a binary format that allows the objects to be cloned |
40 * according to the HTML structured clone algorithm. | 39 * according to the HTML structured clone algorithm. |
41 * | 40 * |
42 * Format is based on Blink's previous serialization logic. | 41 * Format is based on Blink's previous serialization logic. |
43 */ | 42 */ |
44 class ValueSerializer { | 43 class ValueSerializer { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 Handle<JSArrayBuffer> array_buffer); | 211 Handle<JSArrayBuffer> array_buffer); |
213 | 212 |
214 /* | 213 /* |
215 * Publicly exposed wire format writing methods. | 214 * Publicly exposed wire format writing methods. |
216 * These are intended for use within the delegate's WriteHostObject method. | 215 * These are intended for use within the delegate's WriteHostObject method. |
217 */ | 216 */ |
218 bool ReadUint32(uint32_t* value) WARN_UNUSED_RESULT; | 217 bool ReadUint32(uint32_t* value) WARN_UNUSED_RESULT; |
219 bool ReadUint64(uint64_t* value) WARN_UNUSED_RESULT; | 218 bool ReadUint64(uint64_t* value) WARN_UNUSED_RESULT; |
220 bool ReadDouble(double* value) WARN_UNUSED_RESULT; | 219 bool ReadDouble(double* value) WARN_UNUSED_RESULT; |
221 bool ReadRawBytes(size_t length, const void** data) WARN_UNUSED_RESULT; | 220 bool ReadRawBytes(size_t length, const void** data) WARN_UNUSED_RESULT; |
222 void set_expect_inline_wasm(bool expect_inline_wasm) { | |
223 expect_inline_wasm_ = expect_inline_wasm; | |
224 } | |
225 | 221 |
226 private: | 222 private: |
227 // Reading the wire format. | 223 // Reading the wire format. |
228 Maybe<SerializationTag> PeekTag() const WARN_UNUSED_RESULT; | 224 Maybe<SerializationTag> PeekTag() const WARN_UNUSED_RESULT; |
229 void ConsumeTag(SerializationTag peeked_tag); | 225 void ConsumeTag(SerializationTag peeked_tag); |
230 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT; | 226 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT; |
231 template <typename T> | 227 template <typename T> |
232 Maybe<T> ReadVarint() WARN_UNUSED_RESULT; | 228 Maybe<T> ReadVarint() WARN_UNUSED_RESULT; |
233 template <typename T> | 229 template <typename T> |
234 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT; | 230 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT; |
235 Maybe<double> ReadDouble() WARN_UNUSED_RESULT; | 231 Maybe<double> ReadDouble() WARN_UNUSED_RESULT; |
236 Maybe<Vector<const uint8_t>> ReadRawBytes(int size) WARN_UNUSED_RESULT; | 232 Maybe<Vector<const uint8_t>> ReadRawBytes(int size) WARN_UNUSED_RESULT; |
237 bool expect_inline_wasm() const { return expect_inline_wasm_; } | |
238 | 233 |
239 // Reads a string if it matches the one provided. | 234 // Reads a string if it matches the one provided. |
240 // Returns true if this was the case. Otherwise, nothing is consumed. | 235 // Returns true if this was the case. Otherwise, nothing is consumed. |
241 bool ReadExpectedString(Handle<String> expected) WARN_UNUSED_RESULT; | 236 bool ReadExpectedString(Handle<String> expected) WARN_UNUSED_RESULT; |
242 | 237 |
243 // Like ReadObject, but skips logic for special cases in simulating the | 238 // Like ReadObject, but skips logic for special cases in simulating the |
244 // "stack machine". | 239 // "stack machine". |
245 MaybeHandle<Object> ReadObjectInternal() WARN_UNUSED_RESULT; | 240 MaybeHandle<Object> ReadObjectInternal() WARN_UNUSED_RESULT; |
246 | 241 |
247 // Reads a string intended to be part of a more complicated object. | 242 // Reads a string intended to be part of a more complicated object. |
(...skipping 13 matching lines...) Expand all Loading... |
261 MaybeHandle<JSValue> ReadJSValue(SerializationTag tag) WARN_UNUSED_RESULT; | 256 MaybeHandle<JSValue> ReadJSValue(SerializationTag tag) WARN_UNUSED_RESULT; |
262 MaybeHandle<JSRegExp> ReadJSRegExp() WARN_UNUSED_RESULT; | 257 MaybeHandle<JSRegExp> ReadJSRegExp() WARN_UNUSED_RESULT; |
263 MaybeHandle<JSMap> ReadJSMap() WARN_UNUSED_RESULT; | 258 MaybeHandle<JSMap> ReadJSMap() WARN_UNUSED_RESULT; |
264 MaybeHandle<JSSet> ReadJSSet() WARN_UNUSED_RESULT; | 259 MaybeHandle<JSSet> ReadJSSet() WARN_UNUSED_RESULT; |
265 MaybeHandle<JSArrayBuffer> ReadJSArrayBuffer() WARN_UNUSED_RESULT; | 260 MaybeHandle<JSArrayBuffer> ReadJSArrayBuffer() WARN_UNUSED_RESULT; |
266 MaybeHandle<JSArrayBuffer> ReadTransferredJSArrayBuffer(bool is_shared) | 261 MaybeHandle<JSArrayBuffer> ReadTransferredJSArrayBuffer(bool is_shared) |
267 WARN_UNUSED_RESULT; | 262 WARN_UNUSED_RESULT; |
268 MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView( | 263 MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView( |
269 Handle<JSArrayBuffer> buffer) WARN_UNUSED_RESULT; | 264 Handle<JSArrayBuffer> buffer) WARN_UNUSED_RESULT; |
270 MaybeHandle<JSObject> ReadWasmModule() WARN_UNUSED_RESULT; | 265 MaybeHandle<JSObject> ReadWasmModule() WARN_UNUSED_RESULT; |
271 MaybeHandle<JSObject> ReadWasmModuleTransfer() WARN_UNUSED_RESULT; | |
272 MaybeHandle<JSObject> ReadHostObject() WARN_UNUSED_RESULT; | 266 MaybeHandle<JSObject> ReadHostObject() WARN_UNUSED_RESULT; |
273 | 267 |
274 /* | 268 /* |
275 * Reads key-value pairs into the object until the specified end tag is | 269 * Reads key-value pairs into the object until the specified end tag is |
276 * encountered. If successful, returns the number of properties read. | 270 * encountered. If successful, returns the number of properties read. |
277 */ | 271 */ |
278 Maybe<uint32_t> ReadJSObjectProperties(Handle<JSObject> object, | 272 Maybe<uint32_t> ReadJSObjectProperties(Handle<JSObject> object, |
279 SerializationTag end_tag, | 273 SerializationTag end_tag, |
280 bool can_use_transitions); | 274 bool can_use_transitions); |
281 | 275 |
282 // Manipulating the map from IDs to reified objects. | 276 // Manipulating the map from IDs to reified objects. |
283 bool HasObjectWithID(uint32_t id); | 277 bool HasObjectWithID(uint32_t id); |
284 MaybeHandle<JSReceiver> GetObjectWithID(uint32_t id); | 278 MaybeHandle<JSReceiver> GetObjectWithID(uint32_t id); |
285 void AddObjectWithID(uint32_t id, Handle<JSReceiver> object); | 279 void AddObjectWithID(uint32_t id, Handle<JSReceiver> object); |
286 | 280 |
287 Isolate* const isolate_; | 281 Isolate* const isolate_; |
288 v8::ValueDeserializer::Delegate* const delegate_; | 282 v8::ValueDeserializer::Delegate* const delegate_; |
289 const uint8_t* position_; | 283 const uint8_t* position_; |
290 const uint8_t* const end_; | 284 const uint8_t* const end_; |
291 PretenureFlag pretenure_; | 285 PretenureFlag pretenure_; |
292 uint32_t version_ = 0; | 286 uint32_t version_ = 0; |
293 uint32_t next_id_ = 0; | 287 uint32_t next_id_ = 0; |
294 bool expect_inline_wasm_ = false; | |
295 | 288 |
296 // Always global handles. | 289 // Always global handles. |
297 Handle<FixedArray> id_map_; | 290 Handle<FixedArray> id_map_; |
298 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; | 291 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; |
299 | 292 |
300 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); | 293 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); |
301 }; | 294 }; |
302 | 295 |
303 } // namespace internal | 296 } // namespace internal |
304 } // namespace v8 | 297 } // namespace v8 |
305 | 298 |
306 #endif // V8_VALUE_SERIALIZER_H_ | 299 #endif // V8_VALUE_SERIALIZER_H_ |
OLD | NEW |