| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 AstValue* value = | 323 AstValue* value = |
| 324 new (zone_) AstValue(AstValue::SMI, number); | 324 new (zone_) AstValue(AstValue::SMI, number); |
| 325 if (isolate_) { | 325 if (isolate_) { |
| 326 value->Internalize(isolate_); | 326 value->Internalize(isolate_); |
| 327 } | 327 } |
| 328 values_.Add(value); | 328 values_.Add(value); |
| 329 return value; | 329 return value; |
| 330 } | 330 } |
| 331 | 331 |
| 332 | 332 |
| 333 #define GENERATE_VALUE_GETTER(value, initializer) \ |
| 334 if (!value) { \ |
| 335 value = new (zone_) AstValue(initializer); \ |
| 336 if (isolate_) { \ |
| 337 value->Internalize(isolate_); \ |
| 338 } \ |
| 339 values_.Add(value); \ |
| 340 } \ |
| 341 return value; |
| 342 |
| 343 |
| 333 const AstValue* AstValueFactory::NewBoolean(bool b) { | 344 const AstValue* AstValueFactory::NewBoolean(bool b) { |
| 334 AstValue* value = new (zone_) AstValue(b); | 345 if (b) { |
| 335 if (isolate_) { | 346 GENERATE_VALUE_GETTER(true_value_, true); |
| 336 value->Internalize(isolate_); | 347 } else { |
| 348 GENERATE_VALUE_GETTER(false_value_, false); |
| 337 } | 349 } |
| 338 values_.Add(value); | |
| 339 return value; | |
| 340 } | 350 } |
| 341 | 351 |
| 342 | 352 |
| 343 const AstValue* AstValueFactory::NewStringList( | 353 const AstValue* AstValueFactory::NewStringList( |
| 344 ZoneList<const AstRawString*>* strings) { | 354 ZoneList<const AstRawString*>* strings) { |
| 345 AstValue* value = new (zone_) AstValue(strings); | 355 AstValue* value = new (zone_) AstValue(strings); |
| 346 if (isolate_) { | 356 if (isolate_) { |
| 347 value->Internalize(isolate_); | 357 value->Internalize(isolate_); |
| 348 } | 358 } |
| 349 values_.Add(value); | 359 values_.Add(value); |
| 350 return value; | 360 return value; |
| 351 } | 361 } |
| 352 | 362 |
| 353 | 363 |
| 354 const AstValue* AstValueFactory::NewNull() { | 364 const AstValue* AstValueFactory::NewNull() { |
| 355 AstValue* value = new (zone_) AstValue(AstValue::NULL_TYPE); | 365 GENERATE_VALUE_GETTER(null_value_, AstValue::NULL_TYPE); |
| 356 if (isolate_) { | |
| 357 value->Internalize(isolate_); | |
| 358 } | |
| 359 values_.Add(value); | |
| 360 return value; | |
| 361 } | 366 } |
| 362 | 367 |
| 363 | 368 |
| 364 const AstValue* AstValueFactory::NewUndefined() { | 369 const AstValue* AstValueFactory::NewUndefined() { |
| 365 AstValue* value = new (zone_) AstValue(AstValue::UNDEFINED); | 370 GENERATE_VALUE_GETTER(undefined_value_, AstValue::UNDEFINED); |
| 366 if (isolate_) { | |
| 367 value->Internalize(isolate_); | |
| 368 } | |
| 369 values_.Add(value); | |
| 370 return value; | |
| 371 } | 371 } |
| 372 | 372 |
| 373 | 373 |
| 374 const AstValue* AstValueFactory::NewTheHole() { | 374 const AstValue* AstValueFactory::NewTheHole() { |
| 375 AstValue* value = new (zone_) AstValue(AstValue::THE_HOLE); | 375 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); |
| 376 if (isolate_) { | |
| 377 value->Internalize(isolate_); | |
| 378 } | |
| 379 values_.Add(value); | |
| 380 return value; | |
| 381 } | 376 } |
| 382 | 377 |
| 383 | 378 |
| 379 #undef GENERATE_VALUE_GETTER |
| 380 |
| 384 const AstRawString* AstValueFactory::GetString( | 381 const AstRawString* AstValueFactory::GetString( |
| 385 uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) { | 382 uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) { |
| 386 // literal_bytes here points to whatever the user passed, and this is OK | 383 // literal_bytes here points to whatever the user passed, and this is OK |
| 387 // because we use vector_compare (which checks the contents) to compare | 384 // because we use vector_compare (which checks the contents) to compare |
| 388 // against the AstRawStrings which are in the string_table_. We should not | 385 // against the AstRawStrings which are in the string_table_. We should not |
| 389 // return this AstRawString. | 386 // return this AstRawString. |
| 390 AstRawString key(is_one_byte, literal_bytes, hash); | 387 AstRawString key(is_one_byte, literal_bytes, hash); |
| 391 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 388 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); |
| 392 if (entry->value == NULL) { | 389 if (entry->value == NULL) { |
| 393 // Copy literal contents for later comparison. | 390 // Copy literal contents for later comparison. |
| 394 int length = literal_bytes.length(); | 391 int length = literal_bytes.length(); |
| 395 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 392 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 396 memcpy(new_literal_bytes, literal_bytes.start(), length); | 393 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 397 AstRawString* new_string = new (zone_) AstRawString( | 394 AstRawString* new_string = new (zone_) AstRawString( |
| 398 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 395 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 399 entry->key = new_string; | 396 entry->key = new_string; |
| 400 strings_.Add(new_string); | 397 strings_.Add(new_string); |
| 401 if (isolate_) { | 398 if (isolate_) { |
| 402 new_string->Internalize(isolate_); | 399 new_string->Internalize(isolate_); |
| 403 } | 400 } |
| 404 entry->value = reinterpret_cast<void*>(1); | 401 entry->value = reinterpret_cast<void*>(1); |
| 405 } | 402 } |
| 406 return reinterpret_cast<AstRawString*>(entry->key); | 403 return reinterpret_cast<AstRawString*>(entry->key); |
| 407 } | 404 } |
| 408 | 405 |
| 409 | 406 |
| 410 } } // namespace v8::internal | 407 } } // namespace v8::internal |
| OLD | NEW |