| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 case THE_HOLE: | 205 case THE_HOLE: |
| 206 value_ = isolate->factory()->the_hole_value(); | 206 value_ = isolate->factory()->the_hole_value(); |
| 207 break; | 207 break; |
| 208 case UNDEFINED: | 208 case UNDEFINED: |
| 209 value_ = isolate->factory()->undefined_value(); | 209 value_ = isolate->factory()->undefined_value(); |
| 210 break; | 210 break; |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 const AstRawString* AstValueFactory::GetOneByteString( | 215 AstRawString* AstValueFactory::GetOneByteStringInternal( |
| 216 Vector<const uint8_t> literal) { | 216 Vector<const uint8_t> literal) { |
| 217 uint32_t hash = StringHasher::HashSequentialString<uint8_t>( | 217 uint32_t hash = StringHasher::HashSequentialString<uint8_t>( |
| 218 literal.start(), literal.length(), hash_seed_); | 218 literal.start(), literal.length(), hash_seed_); |
| 219 return GetString(hash, true, literal); | 219 return GetString(hash, true, literal); |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 const AstRawString* AstValueFactory::GetTwoByteString( | 223 AstRawString* AstValueFactory::GetTwoByteStringInternal( |
| 224 Vector<const uint16_t> literal) { | 224 Vector<const uint16_t> literal) { |
| 225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( | 225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( |
| 226 literal.start(), literal.length(), hash_seed_); | 226 literal.start(), literal.length(), hash_seed_); |
| 227 return GetString(hash, false, Vector<const byte>::cast(literal)); | 227 return GetString(hash, false, Vector<const byte>::cast(literal)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { | 231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { |
| 232 DisallowHeapAllocation no_gc; | 232 // For the FlatContent to stay valid, we shouldn't do any heap |
| 233 String::FlatContent content = literal->GetFlatContent(); | 233 // allocation. Make sure we won't try to internalize the string in GetString. |
| 234 if (content.IsOneByte()) { | 234 AstRawString* result = NULL; |
| 235 return GetOneByteString(content.ToOneByteVector()); | 235 Isolate* saved_isolate = isolate_; |
| 236 isolate_ = NULL; |
| 237 { |
| 238 DisallowHeapAllocation no_gc; |
| 239 String::FlatContent content = literal->GetFlatContent(); |
| 240 if (content.IsOneByte()) { |
| 241 result = GetOneByteStringInternal(content.ToOneByteVector()); |
| 242 } else { |
| 243 DCHECK(content.IsTwoByte()); |
| 244 result = GetTwoByteStringInternal(content.ToUC16Vector()); |
| 245 } |
| 236 } | 246 } |
| 237 DCHECK(content.IsTwoByte()); | 247 isolate_ = saved_isolate; |
| 238 return GetTwoByteString(content.ToUC16Vector()); | 248 if (isolate_) result->Internalize(isolate_); |
| 249 return result; |
| 239 } | 250 } |
| 240 | 251 |
| 241 | 252 |
| 242 const AstConsString* AstValueFactory::NewConsString( | 253 const AstConsString* AstValueFactory::NewConsString( |
| 243 const AstString* left, const AstString* right) { | 254 const AstString* left, const AstString* right) { |
| 244 // 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 |
| 245 // the AstRawString will not be moved). | 256 // the AstRawString will not be moved). |
| 246 AstConsString* new_string = new (zone_) AstConsString(left, right); | 257 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 247 strings_.Add(new_string); | 258 strings_.Add(new_string); |
| 248 if (isolate_) { | 259 if (isolate_) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 352 } |
| 342 | 353 |
| 343 | 354 |
| 344 const AstValue* AstValueFactory::NewTheHole() { | 355 const AstValue* AstValueFactory::NewTheHole() { |
| 345 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); | 356 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); |
| 346 } | 357 } |
| 347 | 358 |
| 348 | 359 |
| 349 #undef GENERATE_VALUE_GETTER | 360 #undef GENERATE_VALUE_GETTER |
| 350 | 361 |
| 351 const AstRawString* AstValueFactory::GetString( | 362 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, |
| 352 uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) { | 363 Vector<const byte> literal_bytes) { |
| 353 // literal_bytes here points to whatever the user passed, and this is OK | 364 // literal_bytes here points to whatever the user passed, and this is OK |
| 354 // because we use vector_compare (which checks the contents) to compare | 365 // because we use vector_compare (which checks the contents) to compare |
| 355 // against the AstRawStrings which are in the string_table_. We should not | 366 // against the AstRawStrings which are in the string_table_. We should not |
| 356 // return this AstRawString. | 367 // return this AstRawString. |
| 357 AstRawString key(is_one_byte, literal_bytes, hash); | 368 AstRawString key(is_one_byte, literal_bytes, hash); |
| 358 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 369 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); |
| 359 if (entry->value == NULL) { | 370 if (entry->value == NULL) { |
| 360 // Copy literal contents for later comparison. | 371 // Copy literal contents for later comparison. |
| 361 int length = literal_bytes.length(); | 372 int length = literal_bytes.length(); |
| 362 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 373 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 363 memcpy(new_literal_bytes, literal_bytes.start(), length); | 374 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 364 AstRawString* new_string = new (zone_) AstRawString( | 375 AstRawString* new_string = new (zone_) AstRawString( |
| 365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 376 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 366 entry->key = new_string; | 377 entry->key = new_string; |
| 367 strings_.Add(new_string); | 378 strings_.Add(new_string); |
| 368 if (isolate_) { | 379 if (isolate_) { |
| 369 new_string->Internalize(isolate_); | 380 new_string->Internalize(isolate_); |
| 370 } | 381 } |
| 371 entry->value = reinterpret_cast<void*>(1); | 382 entry->value = reinterpret_cast<void*>(1); |
| 372 } | 383 } |
| 373 return reinterpret_cast<AstRawString*>(entry->key); | 384 return reinterpret_cast<AstRawString*>(entry->key); |
| 374 } | 385 } |
| 375 | 386 |
| 376 | 387 |
| 377 } } // namespace v8::internal | 388 } } // namespace v8::internal |
| OLD | NEW |