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 #include "src/value-serializer.h" | 5 #include "src/value-serializer.h" |
6 | 6 |
7 #include <type_traits> | 7 #include <type_traits> |
8 | 8 |
| 9 #include "include/v8-value-serializer-version.h" |
9 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
10 #include "src/conversions.h" | 11 #include "src/conversions.h" |
11 #include "src/factory.h" | 12 #include "src/factory.h" |
12 #include "src/flags.h" | 13 #include "src/flags.h" |
13 #include "src/handles-inl.h" | 14 #include "src/handles-inl.h" |
14 #include "src/isolate.h" | 15 #include "src/isolate.h" |
15 #include "src/objects-inl.h" | 16 #include "src/objects-inl.h" |
16 #include "src/objects.h" | 17 #include "src/objects.h" |
17 #include "src/snapshot/code-serializer.h" | 18 #include "src/snapshot/code-serializer.h" |
18 #include "src/transitions.h" | 19 #include "src/transitions.h" |
19 #include "src/wasm/wasm-module.h" | 20 #include "src/wasm/wasm-module.h" |
20 #include "src/wasm/wasm-objects.h" | 21 #include "src/wasm/wasm-objects.h" |
21 #include "src/wasm/wasm-result.h" | 22 #include "src/wasm/wasm-result.h" |
22 | 23 |
23 namespace v8 { | 24 namespace v8 { |
24 namespace internal { | 25 namespace internal { |
25 | 26 |
26 // Version 9: (imported from Blink) | 27 // Version 9: (imported from Blink) |
27 // Version 10: one-byte (Latin-1) strings | 28 // Version 10: one-byte (Latin-1) strings |
28 // Version 11: properly separate undefined from the hole in arrays | 29 // Version 11: properly separate undefined from the hole in arrays |
29 // Version 12: regexp and string objects share normal string encoding | 30 // Version 12: regexp and string objects share normal string encoding |
30 // Version 13: host objects have an explicit tag (rather than handling all | 31 // Version 13: host objects have an explicit tag (rather than handling all |
31 // unknown tags) | 32 // unknown tags) |
32 static const uint32_t kLatestVersion = 13; | 33 static const uint32_t kLatestVersion = 13; |
| 34 static_assert(kLatestVersion == v8::CurrentValueSerializerFormatVersion(), |
| 35 "Exported format version must match latest version."); |
33 | 36 |
34 static const int kPretenureThreshold = 100 * KB; | 37 static const int kPretenureThreshold = 100 * KB; |
35 | 38 |
36 template <typename T> | 39 template <typename T> |
37 static size_t BytesNeededForVarint(T value) { | 40 static size_t BytesNeededForVarint(T value) { |
38 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, | 41 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, |
39 "Only unsigned integer types can be written as varints."); | 42 "Only unsigned integer types can be written as varints."); |
40 size_t result = 0; | 43 size_t result = 0; |
41 do { | 44 do { |
42 result++; | 45 result++; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 kFloat64Array = 'F', | 150 kFloat64Array = 'F', |
148 kDataView = '?', | 151 kDataView = '?', |
149 }; | 152 }; |
150 | 153 |
151 enum class WasmEncodingTag : uint8_t { | 154 enum class WasmEncodingTag : uint8_t { |
152 kRawBytes = 'y', | 155 kRawBytes = 'y', |
153 }; | 156 }; |
154 | 157 |
155 } // namespace | 158 } // namespace |
156 | 159 |
157 // static | |
158 uint32_t ValueSerializer::GetCurrentDataFormatVersion() { | |
159 return kLatestVersion; | |
160 } | |
161 | |
162 ValueSerializer::ValueSerializer(Isolate* isolate, | 160 ValueSerializer::ValueSerializer(Isolate* isolate, |
163 v8::ValueSerializer::Delegate* delegate) | 161 v8::ValueSerializer::Delegate* delegate) |
164 : isolate_(isolate), | 162 : isolate_(isolate), |
165 delegate_(delegate), | 163 delegate_(delegate), |
166 zone_(isolate->allocator(), ZONE_NAME), | 164 zone_(isolate->allocator(), ZONE_NAME), |
167 id_map_(isolate->heap(), ZoneAllocationPolicy(&zone_)), | 165 id_map_(isolate->heap(), ZoneAllocationPolicy(&zone_)), |
168 array_buffer_transfer_map_(isolate->heap(), | 166 array_buffer_transfer_map_(isolate->heap(), |
169 ZoneAllocationPolicy(&zone_)) {} | 167 ZoneAllocationPolicy(&zone_)) {} |
170 | 168 |
171 ValueSerializer::~ValueSerializer() { | 169 ValueSerializer::~ValueSerializer() { |
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2020 if (stack.size() != 1) { | 2018 if (stack.size() != 1) { |
2021 isolate_->Throw(*isolate_->factory()->NewError( | 2019 isolate_->Throw(*isolate_->factory()->NewError( |
2022 MessageTemplate::kDataCloneDeserializationError)); | 2020 MessageTemplate::kDataCloneDeserializationError)); |
2023 return MaybeHandle<Object>(); | 2021 return MaybeHandle<Object>(); |
2024 } | 2022 } |
2025 return scope.CloseAndEscape(stack[0]); | 2023 return scope.CloseAndEscape(stack[0]); |
2026 } | 2024 } |
2027 | 2025 |
2028 } // namespace internal | 2026 } // namespace internal |
2029 } // namespace v8 | 2027 } // namespace v8 |
OLD | NEW |