| 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 |
| 11 #include "include/v8.h" | 11 #include "include/v8.h" |
| 12 #include "src/base/compiler-specific.h" | 12 #include "src/base/compiler-specific.h" |
| 13 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
| 14 #include "src/identity-map.h" | 14 #include "src/identity-map.h" |
| 15 #include "src/messages.h" |
| 15 #include "src/vector.h" | 16 #include "src/vector.h" |
| 16 #include "src/zone.h" | 17 #include "src/zone.h" |
| 17 | 18 |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 namespace internal { | 20 namespace internal { |
| 20 | 21 |
| 21 class HeapNumber; | 22 class HeapNumber; |
| 22 class Isolate; | 23 class Isolate; |
| 23 class JSArrayBuffer; | 24 class JSArrayBuffer; |
| 24 class JSArrayBufferView; | 25 class JSArrayBufferView; |
| 25 class JSDate; | 26 class JSDate; |
| 26 class JSMap; | 27 class JSMap; |
| 27 class JSRegExp; | 28 class JSRegExp; |
| 28 class JSSet; | 29 class JSSet; |
| 29 class JSValue; | 30 class JSValue; |
| 30 class Object; | 31 class Object; |
| 31 class Oddball; | 32 class Oddball; |
| 32 class Smi; | 33 class Smi; |
| 33 | 34 |
| 34 enum class SerializationTag : uint8_t; | 35 enum class SerializationTag : uint8_t; |
| 35 | 36 |
| 36 /** | 37 /** |
| 37 * 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 |
| 38 * according to the HTML structured clone algorithm. | 39 * according to the HTML structured clone algorithm. |
| 39 * | 40 * |
| 40 * Format is based on Blink's previous serialization logic. | 41 * Format is based on Blink's previous serialization logic. |
| 41 */ | 42 */ |
| 42 class ValueSerializer { | 43 class ValueSerializer { |
| 43 public: | 44 public: |
| 44 explicit ValueSerializer(Isolate* isolate); | 45 ValueSerializer(Isolate* isolate, v8::ValueSerializer::Delegate* delegate); |
| 45 ~ValueSerializer(); | 46 ~ValueSerializer(); |
| 46 | 47 |
| 47 /* | 48 /* |
| 48 * Writes out a header, which includes the format version. | 49 * Writes out a header, which includes the format version. |
| 49 */ | 50 */ |
| 50 void WriteHeader(); | 51 void WriteHeader(); |
| 51 | 52 |
| 52 /* | 53 /* |
| 53 * Serializes a V8 object into the buffer. | 54 * Serializes a V8 object into the buffer. |
| 54 */ | 55 */ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 Maybe<bool> WriteJSArrayBufferView(JSArrayBufferView* array_buffer); | 99 Maybe<bool> WriteJSArrayBufferView(JSArrayBufferView* array_buffer); |
| 99 | 100 |
| 100 /* | 101 /* |
| 101 * Reads the specified keys from the object and writes key-value pairs to the | 102 * Reads the specified keys from the object and writes key-value pairs to the |
| 102 * buffer. Returns the number of keys actually written, which may be smaller | 103 * buffer. Returns the number of keys actually written, which may be smaller |
| 103 * if some keys are not own properties when accessed. | 104 * if some keys are not own properties when accessed. |
| 104 */ | 105 */ |
| 105 Maybe<uint32_t> WriteJSObjectProperties( | 106 Maybe<uint32_t> WriteJSObjectProperties( |
| 106 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT; | 107 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT; |
| 107 | 108 |
| 109 /* |
| 110 * Asks the delegate to handle an error that occurred during data cloning, by |
| 111 * throwing an exception appropriate for the host. |
| 112 */ |
| 113 void ThrowDataCloneError(MessageTemplate::Template template_index); |
| 114 V8_NOINLINE void ThrowDataCloneError(MessageTemplate::Template template_index, |
| 115 Handle<Object> arg0); |
| 116 |
| 108 Isolate* const isolate_; | 117 Isolate* const isolate_; |
| 118 v8::ValueSerializer::Delegate* const delegate_; |
| 109 std::vector<uint8_t> buffer_; | 119 std::vector<uint8_t> buffer_; |
| 110 Zone zone_; | 120 Zone zone_; |
| 111 | 121 |
| 112 // To avoid extra lookups in the identity map, ID+1 is actually stored in the | 122 // To avoid extra lookups in the identity map, ID+1 is actually stored in the |
| 113 // map (checking if the used identity is zero is the fast way of checking if | 123 // map (checking if the used identity is zero is the fast way of checking if |
| 114 // the entry is new). | 124 // the entry is new). |
| 115 IdentityMap<uint32_t> id_map_; | 125 IdentityMap<uint32_t> id_map_; |
| 116 uint32_t next_id_ = 0; | 126 uint32_t next_id_ = 0; |
| 117 | 127 |
| 118 // A similar map, for transferred array buffers. | 128 // A similar map, for transferred array buffers. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Handle<SeededNumberDictionary> id_map_; | 230 Handle<SeededNumberDictionary> id_map_; |
| 221 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; | 231 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; |
| 222 | 232 |
| 223 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); | 233 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); |
| 224 }; | 234 }; |
| 225 | 235 |
| 226 } // namespace internal | 236 } // namespace internal |
| 227 } // namespace v8 | 237 } // namespace v8 |
| 228 | 238 |
| 229 #endif // V8_VALUE_SERIALIZER_H_ | 239 #endif // V8_VALUE_SERIALIZER_H_ |
| OLD | NEW |