Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/value-serializer.h

Issue 2643723010: [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) (Closed)
Patch Set: forgot hash_combine Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 * Publicly exposed wire format writing methods. 79 * Publicly exposed wire format writing methods.
80 * These are intended for use within the delegate's WriteHostObject method. 80 * These are intended for use within the delegate's WriteHostObject method.
81 */ 81 */
82 void WriteUint32(uint32_t value); 82 void WriteUint32(uint32_t value);
83 void WriteUint64(uint64_t value); 83 void WriteUint64(uint64_t value);
84 void WriteRawBytes(const void* source, size_t length); 84 void WriteRawBytes(const void* source, size_t length);
85 void WriteDouble(double value); 85 void WriteDouble(double value);
86 86
87 private: 87 private:
88 // Managing allocations of the internal buffer. 88 // Managing allocations of the internal buffer.
89 void ExpandBuffer(size_t required_capacity); 89 Maybe<bool> ExpandBuffer(size_t required_capacity);
90 90
91 // Writing the wire format. 91 // Writing the wire format.
92 void WriteTag(SerializationTag tag); 92 void WriteTag(SerializationTag tag);
93 template <typename T> 93 template <typename T>
94 void WriteVarint(T value); 94 void WriteVarint(T value);
95 template <typename T> 95 template <typename T>
96 void WriteZigZag(T value); 96 void WriteZigZag(T value);
97 void WriteOneByteString(Vector<const uint8_t> chars); 97 void WriteOneByteString(Vector<const uint8_t> chars);
98 void WriteTwoByteString(Vector<const uc16> chars); 98 void WriteTwoByteString(Vector<const uc16> chars);
99 uint8_t* ReserveRawBytes(size_t bytes); 99 Maybe<uint8_t*> ReserveRawBytes(size_t bytes);
100 100
101 // Writing V8 objects of various kinds. 101 // Writing V8 objects of various kinds.
102 void WriteOddball(Oddball* oddball); 102 void WriteOddball(Oddball* oddball);
103 void WriteSmi(Smi* smi); 103 void WriteSmi(Smi* smi);
104 void WriteHeapNumber(HeapNumber* number); 104 void WriteHeapNumber(HeapNumber* number);
105 void WriteString(Handle<String> string); 105 void WriteString(Handle<String> string);
106 Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver) WARN_UNUSED_RESULT; 106 Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver) WARN_UNUSED_RESULT;
107 Maybe<bool> WriteJSObject(Handle<JSObject> object) WARN_UNUSED_RESULT; 107 Maybe<bool> WriteJSObject(Handle<JSObject> object) WARN_UNUSED_RESULT;
108 Maybe<bool> WriteJSObjectSlow(Handle<JSObject> object) WARN_UNUSED_RESULT; 108 Maybe<bool> WriteJSObjectSlow(Handle<JSObject> object) WARN_UNUSED_RESULT;
109 Maybe<bool> WriteJSArray(Handle<JSArray> array) WARN_UNUSED_RESULT; 109 Maybe<bool> WriteJSArray(Handle<JSArray> array) WARN_UNUSED_RESULT;
(...skipping 17 matching lines...) Expand all
127 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT; 127 Handle<JSObject> object, Handle<FixedArray> keys) WARN_UNUSED_RESULT;
128 128
129 /* 129 /*
130 * Asks the delegate to handle an error that occurred during data cloning, by 130 * Asks the delegate to handle an error that occurred during data cloning, by
131 * throwing an exception appropriate for the host. 131 * throwing an exception appropriate for the host.
132 */ 132 */
133 void ThrowDataCloneError(MessageTemplate::Template template_index); 133 void ThrowDataCloneError(MessageTemplate::Template template_index);
134 V8_NOINLINE void ThrowDataCloneError(MessageTemplate::Template template_index, 134 V8_NOINLINE void ThrowDataCloneError(MessageTemplate::Template template_index,
135 Handle<Object> arg0); 135 Handle<Object> arg0);
136 136
137 Maybe<bool> ThrowIfOutOfMemory();
138
137 Isolate* const isolate_; 139 Isolate* const isolate_;
138 v8::ValueSerializer::Delegate* const delegate_; 140 v8::ValueSerializer::Delegate* const delegate_;
139 uint8_t* buffer_ = nullptr; 141 uint8_t* buffer_ = nullptr;
140 size_t buffer_size_ = 0; 142 size_t buffer_size_ = 0;
141 size_t buffer_capacity_ = 0; 143 size_t buffer_capacity_ = 0;
144 bool out_of_memory_ = false;
142 Zone zone_; 145 Zone zone_;
143 146
144 // To avoid extra lookups in the identity map, ID+1 is actually stored in the 147 // To avoid extra lookups in the identity map, ID+1 is actually stored in the
145 // map (checking if the used identity is zero is the fast way of checking if 148 // map (checking if the used identity is zero is the fast way of checking if
146 // the entry is new). 149 // the entry is new).
147 IdentityMap<uint32_t> id_map_; 150 IdentityMap<uint32_t> id_map_;
148 uint32_t next_id_ = 0; 151 uint32_t next_id_ = 0;
149 152
150 // A similar map, for transferred array buffers. 153 // A similar map, for transferred array buffers.
151 IdentityMap<uint32_t> array_buffer_transfer_map_; 154 IdentityMap<uint32_t> array_buffer_transfer_map_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 Handle<FixedArray> id_map_; 274 Handle<FixedArray> id_map_;
272 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_; 275 MaybeHandle<SeededNumberDictionary> array_buffer_transfer_map_;
273 276
274 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); 277 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer);
275 }; 278 };
276 279
277 } // namespace internal 280 } // namespace internal
278 } // namespace v8 281 } // namespace v8
279 282
280 #endif // V8_VALUE_SERIALIZER_H_ 283 #endif // V8_VALUE_SERIALIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698