| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (content.IsOneByte()) { | 234 if (content.IsOneByte()) { |
| 235 return GetOneByteString(content.ToOneByteVector()); | 235 return GetOneByteString(content.ToOneByteVector()); |
| 236 } | 236 } |
| 237 DCHECK(content.IsTwoByte()); | 237 DCHECK(content.IsTwoByte()); |
| 238 return GetTwoByteString(content.ToUC16Vector()); | 238 return GetTwoByteString(content.ToUC16Vector()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 | 241 |
| 242 const AstConsString* AstValueFactory::NewConsString( | 242 const AstConsString* AstValueFactory::NewConsString( |
| 243 const AstString* left, const AstString* right) { | 243 const AstString* left, const AstString* right) { |
| 244 // This Vector will be valid as long as the Collector is alive (meaning that | |
| 245 // the AstRawString will not be moved). | |
| 246 AstConsString* new_string = new (zone_) AstConsString(left, right); | 244 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 247 strings_.Add(new_string); | |
| 248 if (isolate_) { | 245 if (isolate_) { |
| 249 new_string->Internalize(isolate_); | 246 new_string->Internalize(isolate_); |
| 247 } else { |
| 248 strings_.Add(new_string); |
| 250 } | 249 } |
| 251 return new_string; | 250 return new_string; |
| 252 } | 251 } |
| 253 | 252 |
| 254 | 253 |
| 255 void AstValueFactory::Internalize(Isolate* isolate) { | 254 void AstValueFactory::Internalize(Isolate* isolate) { |
| 256 if (isolate_) { | 255 if (isolate_) { |
| 257 // Everything is already internalized. | 256 // Everything is already internalized. |
| 258 return; | 257 return; |
| 259 } | 258 } |
| 260 // Strings need to be internalized before values, because values refer to | 259 // Strings need to be internalized before values, because values refer to |
| 261 // strings. | 260 // strings. |
| 262 for (int i = 0; i < strings_.length(); ++i) { | 261 for (int i = 0; i < strings_.length(); ++i) { |
| 263 strings_[i]->Internalize(isolate); | 262 strings_[i]->Internalize(isolate); |
| 264 } | 263 } |
| 265 for (int i = 0; i < values_.length(); ++i) { | 264 for (int i = 0; i < values_.length(); ++i) { |
| 266 values_[i]->Internalize(isolate); | 265 values_[i]->Internalize(isolate); |
| 267 } | 266 } |
| 268 isolate_ = isolate; | 267 isolate_ = isolate; |
| 269 } | 268 } |
| 270 | 269 |
| 271 | 270 |
| 272 const AstValue* AstValueFactory::NewString(const AstRawString* string) { | 271 const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
| 273 AstValue* value = new (zone_) AstValue(string); | 272 AstValue* value = new (zone_) AstValue(string); |
| 274 DCHECK(string != NULL); | 273 DCHECK(string != NULL); |
| 275 if (isolate_) { | 274 if (isolate_) { |
| 276 value->Internalize(isolate_); | 275 // If we're creating immediately-internalized AstValues, the underlying |
| 276 // strings must already be internalized at this point. |
| 277 DCHECK(!string->string_.is_null()); |
| 277 } | 278 } |
| 278 values_.Add(value); | 279 // These AstValues don't need to be added to values_, since the AstRawStrings |
| 280 // will be insternalized separately. |
| 279 return value; | 281 return value; |
| 280 } | 282 } |
| 281 | 283 |
| 282 | 284 |
| 283 const AstValue* AstValueFactory::NewSymbol(const char* name) { | 285 const AstValue* AstValueFactory::NewSymbol(const char* name) { |
| 284 AstValue* value = new (zone_) AstValue(name); | 286 AstValue* value = new (zone_) AstValue(name); |
| 285 if (isolate_) { | 287 if (isolate_) { |
| 286 value->Internalize(isolate_); | 288 value->Internalize(isolate_); |
| 289 } else { |
| 290 values_.Add(value); |
| 287 } | 291 } |
| 288 values_.Add(value); | |
| 289 return value; | 292 return value; |
| 290 } | 293 } |
| 291 | 294 |
| 292 | 295 |
| 293 const AstValue* AstValueFactory::NewNumber(double number) { | 296 const AstValue* AstValueFactory::NewNumber(double number) { |
| 294 AstValue* value = new (zone_) AstValue(number); | 297 AstValue* value = new (zone_) AstValue(number); |
| 295 if (isolate_) { | 298 if (isolate_) { |
| 296 value->Internalize(isolate_); | 299 value->Internalize(isolate_); |
| 300 } else { |
| 301 values_.Add(value); |
| 297 } | 302 } |
| 298 values_.Add(value); | |
| 299 return value; | 303 return value; |
| 300 } | 304 } |
| 301 | 305 |
| 302 | 306 |
| 303 const AstValue* AstValueFactory::NewSmi(int number) { | 307 const AstValue* AstValueFactory::NewSmi(int number) { |
| 304 AstValue* value = | 308 AstValue* value = |
| 305 new (zone_) AstValue(AstValue::SMI, number); | 309 new (zone_) AstValue(AstValue::SMI, number); |
| 306 if (isolate_) { | 310 if (isolate_) { |
| 307 value->Internalize(isolate_); | 311 value->Internalize(isolate_); |
| 312 } else { |
| 313 values_.Add(value); |
| 308 } | 314 } |
| 309 values_.Add(value); | |
| 310 return value; | 315 return value; |
| 311 } | 316 } |
| 312 | 317 |
| 313 | 318 |
| 314 #define GENERATE_VALUE_GETTER(value, initializer) \ | 319 #define GENERATE_VALUE_GETTER(value, initializer) \ |
| 315 if (!value) { \ | 320 if (!value) { \ |
| 316 value = new (zone_) AstValue(initializer); \ | 321 value = new (zone_) AstValue(initializer); \ |
| 317 if (isolate_) { \ | 322 if (isolate_) { \ |
| 318 value->Internalize(isolate_); \ | 323 value->Internalize(isolate_); \ |
| 324 } else { \ |
| 325 values_.Add(value); \ |
| 319 } \ | 326 } \ |
| 320 values_.Add(value); \ | |
| 321 } \ | 327 } \ |
| 322 return value; | 328 return value; |
| 323 | 329 |
| 324 | 330 |
| 325 const AstValue* AstValueFactory::NewBoolean(bool b) { | 331 const AstValue* AstValueFactory::NewBoolean(bool b) { |
| 326 if (b) { | 332 if (b) { |
| 327 GENERATE_VALUE_GETTER(true_value_, true); | 333 GENERATE_VALUE_GETTER(true_value_, true); |
| 328 } else { | 334 } else { |
| 329 GENERATE_VALUE_GETTER(false_value_, false); | 335 GENERATE_VALUE_GETTER(false_value_, false); |
| 330 } | 336 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 357 AstRawString key(is_one_byte, literal_bytes, hash); | 363 AstRawString key(is_one_byte, literal_bytes, hash); |
| 358 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 364 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); |
| 359 if (entry->value == NULL) { | 365 if (entry->value == NULL) { |
| 360 // Copy literal contents for later comparison. | 366 // Copy literal contents for later comparison. |
| 361 int length = literal_bytes.length(); | 367 int length = literal_bytes.length(); |
| 362 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 368 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 363 memcpy(new_literal_bytes, literal_bytes.start(), length); | 369 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 364 AstRawString* new_string = new (zone_) AstRawString( | 370 AstRawString* new_string = new (zone_) AstRawString( |
| 365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 371 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 366 entry->key = new_string; | 372 entry->key = new_string; |
| 367 strings_.Add(new_string); | |
| 368 if (isolate_) { | 373 if (isolate_) { |
| 369 new_string->Internalize(isolate_); | 374 new_string->Internalize(isolate_); |
| 375 } else { |
| 376 strings_.Add(new_string); |
| 370 } | 377 } |
| 371 entry->value = reinterpret_cast<void*>(1); | 378 entry->value = reinterpret_cast<void*>(1); |
| 372 } | 379 } |
| 373 return reinterpret_cast<AstRawString*>(entry->key); | 380 return reinterpret_cast<AstRawString*>(entry->key); |
| 374 } | 381 } |
| 375 | 382 |
| 376 | 383 |
| 377 } } // namespace v8::internal | 384 } } // namespace v8::internal |
| OLD | NEW |