| 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 "src/base/logging.h" | 9 #include "src/base/logging.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 Handle<Object> transfer_map_handle; | 675 Handle<Object> transfer_map_handle; |
| 676 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) { | 676 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) { |
| 677 GlobalHandles::Destroy(transfer_map_handle.location()); | 677 GlobalHandles::Destroy(transfer_map_handle.location()); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 | 680 |
| 681 Maybe<bool> ValueDeserializer::ReadHeader() { | 681 Maybe<bool> ValueDeserializer::ReadHeader() { |
| 682 if (position_ < end_ && | 682 if (position_ < end_ && |
| 683 *position_ == static_cast<uint8_t>(SerializationTag::kVersion)) { | 683 *position_ == static_cast<uint8_t>(SerializationTag::kVersion)) { |
| 684 ReadTag().ToChecked(); | 684 ReadTag().ToChecked(); |
| 685 if (!ReadVarint<uint32_t>().To(&version_)) return Nothing<bool>(); | 685 if (!ReadVarint<uint32_t>().To(&version_) || version_ > kLatestVersion) { |
| 686 if (version_ > kLatestVersion) return Nothing<bool>(); | 686 isolate_->Throw(*isolate_->factory()->NewError( |
| 687 MessageTemplate::kDataCloneDeserializationVersionError)); |
| 688 return Nothing<bool>(); |
| 689 } |
| 687 } | 690 } |
| 688 return Just(true); | 691 return Just(true); |
| 689 } | 692 } |
| 690 | 693 |
| 691 Maybe<SerializationTag> ValueDeserializer::PeekTag() const { | 694 Maybe<SerializationTag> ValueDeserializer::PeekTag() const { |
| 692 const uint8_t* peek_position = position_; | 695 const uint8_t* peek_position = position_; |
| 693 SerializationTag tag; | 696 SerializationTag tag; |
| 694 do { | 697 do { |
| 695 if (peek_position >= end_) return Nothing<SerializationTag>(); | 698 if (peek_position >= end_) return Nothing<SerializationTag>(); |
| 696 tag = static_cast<SerializationTag>(*peek_position); | 699 tag = static_cast<SerializationTag>(*peek_position); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 // ArrayBufferView is special in that it consumes the value before it, even | 800 // ArrayBufferView is special in that it consumes the value before it, even |
| 798 // after format version 0. | 801 // after format version 0. |
| 799 Handle<Object> object; | 802 Handle<Object> object; |
| 800 SerializationTag tag; | 803 SerializationTag tag; |
| 801 if (result.ToHandle(&object) && V8_UNLIKELY(object->IsJSArrayBuffer()) && | 804 if (result.ToHandle(&object) && V8_UNLIKELY(object->IsJSArrayBuffer()) && |
| 802 PeekTag().To(&tag) && tag == SerializationTag::kArrayBufferView) { | 805 PeekTag().To(&tag) && tag == SerializationTag::kArrayBufferView) { |
| 803 ConsumeTag(SerializationTag::kArrayBufferView); | 806 ConsumeTag(SerializationTag::kArrayBufferView); |
| 804 result = ReadJSArrayBufferView(Handle<JSArrayBuffer>::cast(object)); | 807 result = ReadJSArrayBufferView(Handle<JSArrayBuffer>::cast(object)); |
| 805 } | 808 } |
| 806 | 809 |
| 810 if (result.is_null() && !isolate_->has_pending_exception()) { |
| 811 isolate_->Throw(*isolate_->factory()->NewError( |
| 812 MessageTemplate::kDataCloneDeserializationError)); |
| 813 } |
| 814 |
| 807 return result; | 815 return result; |
| 808 } | 816 } |
| 809 | 817 |
| 810 MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() { | 818 MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() { |
| 811 SerializationTag tag; | 819 SerializationTag tag; |
| 812 if (!ReadTag().To(&tag)) return MaybeHandle<Object>(); | 820 if (!ReadTag().To(&tag)) return MaybeHandle<Object>(); |
| 813 switch (tag) { | 821 switch (tag) { |
| 814 case SerializationTag::kVerifyObjectCount: | 822 case SerializationTag::kVerifyObjectCount: |
| 815 // Read the count and ignore it. | 823 // Read the count and ignore it. |
| 816 if (ReadVarint<uint32_t>().IsNothing()) return MaybeHandle<Object>(); | 824 if (ReadVarint<uint32_t>().IsNothing()) return MaybeHandle<Object>(); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE) | 1300 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE) |
| 1293 .is_null()) { | 1301 .is_null()) { |
| 1294 return Nothing<bool>(); | 1302 return Nothing<bool>(); |
| 1295 } | 1303 } |
| 1296 } | 1304 } |
| 1297 return Just(true); | 1305 return Just(true); |
| 1298 } | 1306 } |
| 1299 | 1307 |
| 1300 MaybeHandle<Object> | 1308 MaybeHandle<Object> |
| 1301 ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { | 1309 ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { |
| 1302 if (version_ > 0) return MaybeHandle<Object>(); | 1310 DCHECK_EQ(version_, 0); |
| 1303 | |
| 1304 HandleScope scope(isolate_); | 1311 HandleScope scope(isolate_); |
| 1305 std::vector<Handle<Object>> stack; | 1312 std::vector<Handle<Object>> stack; |
| 1306 while (position_ < end_) { | 1313 while (position_ < end_) { |
| 1307 SerializationTag tag; | 1314 SerializationTag tag; |
| 1308 if (!PeekTag().To(&tag)) break; | 1315 if (!PeekTag().To(&tag)) break; |
| 1309 | 1316 |
| 1310 Handle<Object> new_object; | 1317 Handle<Object> new_object; |
| 1311 switch (tag) { | 1318 switch (tag) { |
| 1312 case SerializationTag::kEndJSObject: { | 1319 case SerializationTag::kEndJSObject: { |
| 1313 ConsumeTag(SerializationTag::kEndJSObject); | 1320 ConsumeTag(SerializationTag::kEndJSObject); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 !SetPropertiesFromKeyValuePairs( | 1362 !SetPropertiesFromKeyValuePairs( |
| 1356 isolate_, js_array, &stack[begin_properties], num_properties) | 1363 isolate_, js_array, &stack[begin_properties], num_properties) |
| 1357 .FromMaybe(false)) { | 1364 .FromMaybe(false)) { |
| 1358 return MaybeHandle<Object>(); | 1365 return MaybeHandle<Object>(); |
| 1359 } | 1366 } |
| 1360 | 1367 |
| 1361 stack.resize(begin_properties); | 1368 stack.resize(begin_properties); |
| 1362 new_object = js_array; | 1369 new_object = js_array; |
| 1363 break; | 1370 break; |
| 1364 } | 1371 } |
| 1365 case SerializationTag::kEndDenseJSArray: | 1372 case SerializationTag::kEndDenseJSArray: { |
| 1366 // This was already broken in Chromium, and apparently wasn't missed. | 1373 // This was already broken in Chromium, and apparently wasn't missed. |
| 1374 isolate_->Throw(*isolate_->factory()->NewError( |
| 1375 MessageTemplate::kDataCloneDeserializationError)); |
| 1367 return MaybeHandle<Object>(); | 1376 return MaybeHandle<Object>(); |
| 1377 } |
| 1368 default: | 1378 default: |
| 1369 if (!ReadObject().ToHandle(&new_object)) return MaybeHandle<Object>(); | 1379 if (!ReadObject().ToHandle(&new_object)) return MaybeHandle<Object>(); |
| 1370 break; | 1380 break; |
| 1371 } | 1381 } |
| 1372 stack.push_back(new_object); | 1382 stack.push_back(new_object); |
| 1373 } | 1383 } |
| 1374 | 1384 |
| 1375 // Nothing remains but padding. | 1385 // Nothing remains but padding. |
| 1376 #ifdef DEBUG | 1386 #ifdef DEBUG |
| 1377 while (position_ < end_) { | 1387 while (position_ < end_) { |
| 1378 DCHECK(*position_++ == static_cast<uint8_t>(SerializationTag::kPadding)); | 1388 DCHECK(*position_++ == static_cast<uint8_t>(SerializationTag::kPadding)); |
| 1379 } | 1389 } |
| 1380 #endif | 1390 #endif |
| 1381 position_ = end_; | 1391 position_ = end_; |
| 1382 | 1392 |
| 1383 if (stack.size() != 1) return MaybeHandle<Object>(); | 1393 if (stack.size() != 1) { |
| 1394 isolate_->Throw(*isolate_->factory()->NewError( |
| 1395 MessageTemplate::kDataCloneDeserializationError)); |
| 1396 return MaybeHandle<Object>(); |
| 1397 } |
| 1384 return scope.CloseAndEscape(stack[0]); | 1398 return scope.CloseAndEscape(stack[0]); |
| 1385 } | 1399 } |
| 1386 | 1400 |
| 1387 } // namespace internal | 1401 } // namespace internal |
| 1388 } // namespace v8 | 1402 } // namespace v8 |
| OLD | NEW |