OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 AstRawString* AstValueFactory::GetTwoByteStringInternal( | 231 AstRawString* AstValueFactory::GetTwoByteStringInternal( |
232 Vector<const uint16_t> literal) { | 232 Vector<const uint16_t> literal) { |
233 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( | 233 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( |
234 literal.start(), literal.length(), hash_seed_); | 234 literal.start(), literal.length(), hash_seed_); |
235 return GetString(hash, false, Vector<const byte>::cast(literal)); | 235 return GetString(hash, false, Vector<const byte>::cast(literal)); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { | 239 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { |
240 // For the FlatContent to stay valid, we shouldn't do any heap | |
241 // allocation. Make sure we won't try to internalize the string in GetString. | |
242 AstRawString* result = NULL; | 240 AstRawString* result = NULL; |
243 Isolate* saved_isolate = isolate_; | 241 DisallowHeapAllocation no_gc; |
244 isolate_ = NULL; | 242 String::FlatContent content = literal->GetFlatContent(); |
245 { | 243 if (content.IsOneByte()) { |
246 DisallowHeapAllocation no_gc; | 244 result = GetOneByteStringInternal(content.ToOneByteVector()); |
247 String::FlatContent content = literal->GetFlatContent(); | 245 } else { |
248 if (content.IsOneByte()) { | 246 DCHECK(content.IsTwoByte()); |
249 result = GetOneByteStringInternal(content.ToOneByteVector()); | 247 result = GetTwoByteStringInternal(content.ToUC16Vector()); |
250 } else { | |
251 DCHECK(content.IsTwoByte()); | |
252 result = GetTwoByteStringInternal(content.ToUC16Vector()); | |
253 } | |
254 } | |
255 isolate_ = saved_isolate; | |
256 if (strings_ != nullptr && isolate_) { | |
257 // Only the string we are creating is uninternalized at this point. | |
258 DCHECK_EQ(result, strings_); | |
259 DCHECK_NULL(strings_->next()); | |
260 result->Internalize(isolate_); | |
261 ResetStrings(); | |
262 } | 248 } |
263 return result; | 249 return result; |
264 } | 250 } |
265 | 251 |
266 | 252 |
267 const AstConsString* AstValueFactory::NewConsString( | 253 const AstConsString* AstValueFactory::NewConsString( |
268 const AstString* left, const AstString* right) { | 254 const AstString* left, const AstString* right) { |
269 // This Vector will be valid as long as the Collector is alive (meaning that | 255 // This Vector will be valid as long as the Collector is alive (meaning that |
270 // the AstRawString will not be moved). | 256 // the AstRawString will not be moved). |
271 AstConsString* new_string = new (zone_) AstConsString(left, right); | 257 AstConsString* new_string = new (zone_) AstConsString(left, right); |
272 CHECK(new_string != nullptr); | 258 CHECK(new_string != nullptr); |
273 AddString(new_string); | 259 AddString(new_string); |
274 return new_string; | 260 return new_string; |
275 } | 261 } |
276 | 262 |
277 | 263 |
278 void AstValueFactory::Internalize(Isolate* isolate) { | 264 void AstValueFactory::Internalize(Isolate* isolate) { |
279 if (isolate_) { | |
280 DCHECK_NULL(strings_); | |
281 DCHECK_NULL(values_); | |
282 // Everything is already internalized. | |
283 return; | |
284 } | |
285 | |
286 // Strings need to be internalized before values, because values refer to | 265 // Strings need to be internalized before values, because values refer to |
287 // strings. | 266 // strings. |
288 for (AstString* current = strings_; current != nullptr;) { | 267 for (AstString* current = strings_; current != nullptr;) { |
289 AstString* next = current->next(); | 268 AstString* next = current->next(); |
290 current->Internalize(isolate); | 269 current->Internalize(isolate); |
291 current = next; | 270 current = next; |
292 } | 271 } |
293 for (AstValue* current = values_; current != nullptr;) { | 272 for (AstValue* current = values_; current != nullptr;) { |
294 AstValue* next = current->next(); | 273 AstValue* next = current->next(); |
295 current->Internalize(isolate); | 274 current->Internalize(isolate); |
296 current = next; | 275 current = next; |
297 } | 276 } |
298 isolate_ = isolate; | |
299 ResetStrings(); | 277 ResetStrings(); |
300 values_ = nullptr; | 278 values_ = nullptr; |
301 } | 279 } |
302 | 280 |
303 | 281 |
304 const AstValue* AstValueFactory::NewString(const AstRawString* string) { | 282 const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
305 AstValue* value = new (zone_) AstValue(string); | 283 AstValue* value = new (zone_) AstValue(string); |
306 CHECK(string != nullptr); | 284 CHECK(string != nullptr); |
307 return AddValue(value); | 285 return AddValue(value); |
308 } | 286 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 length) == 0; | 385 length) == 0; |
408 } else { | 386 } else { |
409 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), | 387 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
410 reinterpret_cast<const uint16_t*>(r), | 388 reinterpret_cast<const uint16_t*>(r), |
411 length) == 0; | 389 length) == 0; |
412 } | 390 } |
413 } | 391 } |
414 } | 392 } |
415 } // namespace internal | 393 } // namespace internal |
416 } // namespace v8 | 394 } // namespace v8 |
OLD | NEW |