| 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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 // See also https://developers.google.com/protocol-buffers/docs/encoding | 813 // See also https://developers.google.com/protocol-buffers/docs/encoding |
| 814 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, | 814 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, |
| 815 "Only unsigned integer types can be read as varints."); | 815 "Only unsigned integer types can be read as varints."); |
| 816 T value = 0; | 816 T value = 0; |
| 817 unsigned shift = 0; | 817 unsigned shift = 0; |
| 818 bool has_another_byte; | 818 bool has_another_byte; |
| 819 do { | 819 do { |
| 820 if (position_ >= end_) return Nothing<T>(); | 820 if (position_ >= end_) return Nothing<T>(); |
| 821 uint8_t byte = *position_; | 821 uint8_t byte = *position_; |
| 822 if (V8_LIKELY(shift < sizeof(T) * 8)) { | 822 if (V8_LIKELY(shift < sizeof(T) * 8)) { |
| 823 value |= (byte & 0x7f) << shift; | 823 value |= static_cast<T>(byte & 0x7f) << shift; |
| 824 shift += 7; | 824 shift += 7; |
| 825 } | 825 } |
| 826 has_another_byte = byte & 0x80; | 826 has_another_byte = byte & 0x80; |
| 827 position_++; | 827 position_++; |
| 828 } while (has_another_byte); | 828 } while (has_another_byte); |
| 829 return Just(value); | 829 return Just(value); |
| 830 } | 830 } |
| 831 | 831 |
| 832 template <typename T> | 832 template <typename T> |
| 833 Maybe<T> ValueDeserializer::ReadZigZag() { | 833 Maybe<T> ValueDeserializer::ReadZigZag() { |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 if (stack.size() != 1) { | 1479 if (stack.size() != 1) { |
| 1480 isolate_->Throw(*isolate_->factory()->NewError( | 1480 isolate_->Throw(*isolate_->factory()->NewError( |
| 1481 MessageTemplate::kDataCloneDeserializationError)); | 1481 MessageTemplate::kDataCloneDeserializationError)); |
| 1482 return MaybeHandle<Object>(); | 1482 return MaybeHandle<Object>(); |
| 1483 } | 1483 } |
| 1484 return scope.CloseAndEscape(stack[0]); | 1484 return scope.CloseAndEscape(stack[0]); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 } // namespace internal | 1487 } // namespace internal |
| 1488 } // namespace v8 | 1488 } // namespace v8 |
| OLD | NEW |