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

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

Issue 2626893005: Revert of Internalize strings in-place (Closed)
Patch Set: rebased Created 3 years, 11 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
« no previous file with comments | « src/s390/codegen-s390.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 return ReadHostObject(); 1128 return ReadHostObject();
1129 } 1129 }
1130 } 1130 }
1131 1131
1132 MaybeHandle<String> ValueDeserializer::ReadUtf8String() { 1132 MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
1133 uint32_t utf8_length; 1133 uint32_t utf8_length;
1134 Vector<const uint8_t> utf8_bytes; 1134 Vector<const uint8_t> utf8_bytes;
1135 if (!ReadVarint<uint32_t>().To(&utf8_length) || 1135 if (!ReadVarint<uint32_t>().To(&utf8_length) ||
1136 utf8_length > 1136 utf8_length >
1137 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) || 1137 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
1138 !ReadRawBytes(utf8_length).To(&utf8_bytes)) { 1138 !ReadRawBytes(utf8_length).To(&utf8_bytes))
1139 return MaybeHandle<String>(); 1139 return MaybeHandle<String>();
1140 }
1141 return isolate_->factory()->NewStringFromUtf8( 1140 return isolate_->factory()->NewStringFromUtf8(
1142 Vector<const char>::cast(utf8_bytes), pretenure_); 1141 Vector<const char>::cast(utf8_bytes), pretenure_);
1143 } 1142 }
1144 1143
1145 MaybeHandle<String> ValueDeserializer::ReadTwoByteString() { 1144 MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
1146 uint32_t byte_length; 1145 uint32_t byte_length;
1147 Vector<const uint8_t> bytes; 1146 Vector<const uint8_t> bytes;
1148 if (!ReadVarint<uint32_t>().To(&byte_length) || 1147 if (!ReadVarint<uint32_t>().To(&byte_length) ||
1149 byte_length > 1148 byte_length >
1150 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) || 1149 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
1151 byte_length % sizeof(uc16) != 0 || 1150 byte_length % sizeof(uc16) != 0 || !ReadRawBytes(byte_length).To(&bytes))
1152 !ReadRawBytes(byte_length).To(&bytes)) {
1153 return MaybeHandle<String>(); 1151 return MaybeHandle<String>();
1154 }
1155 1152
1156 // Allocate an uninitialized string so that we can do a raw memcpy into the 1153 // Allocate an uninitialized string so that we can do a raw memcpy into the
1157 // string on the heap (regardless of alignment). 1154 // string on the heap (regardless of alignment).
1158 if (byte_length == 0) return isolate_->factory()->empty_string();
1159 Handle<SeqTwoByteString> string; 1155 Handle<SeqTwoByteString> string;
1160 if (!isolate_->factory() 1156 if (!isolate_->factory()
1161 ->NewRawTwoByteString(byte_length / sizeof(uc16), pretenure_) 1157 ->NewRawTwoByteString(byte_length / sizeof(uc16), pretenure_)
1162 .ToHandle(&string)) { 1158 .ToHandle(&string))
1163 return MaybeHandle<String>(); 1159 return MaybeHandle<String>();
1164 }
1165 1160
1166 // Copy the bytes directly into the new string. 1161 // Copy the bytes directly into the new string.
1167 // Warning: this uses host endianness. 1162 // Warning: this uses host endianness.
1168 memcpy(string->GetChars(), bytes.begin(), bytes.length()); 1163 memcpy(string->GetChars(), bytes.begin(), bytes.length());
1169 return string; 1164 return string;
1170 } 1165 }
1171 1166
1172 bool ValueDeserializer::ReadExpectedString(Handle<String> expected) { 1167 bool ValueDeserializer::ReadExpectedString(Handle<String> expected) {
1173 // In the case of failure, the position in the stream is reset. 1168 // In the case of failure, the position in the stream is reset.
1174 const uint8_t* original_position = position_; 1169 const uint8_t* original_position = position_;
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 if (stack.size() != 1) { 1870 if (stack.size() != 1) {
1876 isolate_->Throw(*isolate_->factory()->NewError( 1871 isolate_->Throw(*isolate_->factory()->NewError(
1877 MessageTemplate::kDataCloneDeserializationError)); 1872 MessageTemplate::kDataCloneDeserializationError));
1878 return MaybeHandle<Object>(); 1873 return MaybeHandle<Object>();
1879 } 1874 }
1880 return scope.CloseAndEscape(stack[0]); 1875 return scope.CloseAndEscape(stack[0]);
1881 } 1876 }
1882 1877
1883 } // namespace internal 1878 } // namespace internal
1884 } // namespace v8 1879 } // namespace v8
OLDNEW
« no previous file with comments | « src/s390/codegen-s390.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698