OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/ast/ast.h" | 5 #include "src/ast/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 | 8 |
9 #include "src/ast/compile-time-value.h" | 9 #include "src/ast/compile-time-value.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 property->SetSlot(spec->AddStoreICSlot(language_mode)); | 483 property->SetSlot(spec->AddStoreICSlot(language_mode)); |
484 } | 484 } |
485 break; | 485 break; |
486 } | 486 } |
487 } | 487 } |
488 | 488 |
489 for (; property_index < properties()->length(); property_index++) { | 489 for (; property_index < properties()->length(); property_index++) { |
490 ObjectLiteral::Property* property = properties()->at(property_index); | 490 ObjectLiteral::Property* property = properties()->at(property_index); |
491 | 491 |
492 Expression* value = property->value(); | 492 Expression* value = property->value(); |
493 if (property->kind() != ObjectLiteral::Property::PROTOTYPE) { | 493 if (!property->IsPrototype()) { |
494 if (FunctionLiteral::NeedsHomeObject(value)) { | 494 if (FunctionLiteral::NeedsHomeObject(value)) { |
495 property->SetSlot(spec->AddStoreICSlot(language_mode)); | 495 property->SetSlot(spec->AddStoreICSlot(language_mode)); |
496 } | 496 } |
497 } | 497 } |
498 property->SetStoreDataPropertySlot( | 498 property->SetStoreDataPropertySlot( |
499 spec->AddStoreDataPropertyInLiteralICSlot()); | 499 spec->AddStoreDataPropertyInLiteralICSlot()); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 | 503 |
504 void ObjectLiteral::CalculateEmitStore(Zone* zone) { | 504 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
505 const auto GETTER = ObjectLiteral::Property::GETTER; | 505 const auto GETTER = ObjectLiteral::Property::GETTER; |
506 const auto SETTER = ObjectLiteral::Property::SETTER; | 506 const auto SETTER = ObjectLiteral::Property::SETTER; |
507 | 507 |
508 ZoneAllocationPolicy allocator(zone); | 508 ZoneAllocationPolicy allocator(zone); |
509 | 509 |
510 CustomMatcherZoneHashMap table( | 510 CustomMatcherZoneHashMap table( |
511 Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); | 511 Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, allocator); |
512 for (int i = properties()->length() - 1; i >= 0; i--) { | 512 for (int i = properties()->length() - 1; i >= 0; i--) { |
513 ObjectLiteral::Property* property = properties()->at(i); | 513 ObjectLiteral::Property* property = properties()->at(i); |
514 if (property->is_computed_name()) continue; | 514 if (property->is_computed_name()) continue; |
515 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) continue; | 515 if (property->IsPrototype()) continue; |
516 Literal* literal = property->key()->AsLiteral(); | 516 Literal* literal = property->key()->AsLiteral(); |
517 DCHECK(!literal->IsNullLiteral()); | 517 DCHECK(!literal->IsNullLiteral()); |
518 | 518 |
519 // If there is an existing entry do not emit a store unless the previous | 519 // If there is an existing entry do not emit a store unless the previous |
520 // entry was also an accessor. | 520 // entry was also an accessor. |
521 uint32_t hash = literal->Hash(); | 521 uint32_t hash = literal->Hash(); |
522 ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator); | 522 ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator); |
523 if (entry->value != NULL) { | 523 if (entry->value != NULL) { |
524 auto previous_kind = | 524 auto previous_kind = |
525 static_cast<ObjectLiteral::Property*>(entry->value)->kind(); | 525 static_cast<ObjectLiteral::Property*>(entry->value)->kind(); |
526 if (!((property->kind() == GETTER && previous_kind == SETTER) || | 526 if (!((property->kind() == GETTER && previous_kind == SETTER) || |
527 (property->kind() == SETTER && previous_kind == GETTER))) { | 527 (property->kind() == SETTER && previous_kind == GETTER))) { |
528 property->set_emit_store(false); | 528 property->set_emit_store(false); |
529 } | 529 } |
530 } | 530 } |
531 entry->value = property; | 531 entry->value = property; |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 | 535 |
536 bool ObjectLiteral::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 536 bool ObjectLiteral::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
537 return property != NULL && | 537 return property != NULL && !property->IsPrototype(); |
538 property->kind() != ObjectLiteral::Property::PROTOTYPE; | |
539 } | 538 } |
540 | 539 |
541 void ObjectLiteral::InitDepthAndFlags() { | 540 void ObjectLiteral::InitDepthAndFlags() { |
542 if (depth_ > 0) return; | 541 if (depth_ > 0) return; |
543 | 542 |
544 int position = 0; | 543 int position = 0; |
545 // Accumulate the value in local variables and store it at the end. | 544 // Accumulate the value in local variables and store it at the end. |
546 bool is_simple = true; | 545 bool is_simple = true; |
547 int depth_acc = 1; | 546 int depth_acc = 1; |
548 uint32_t max_element_index = 0; | 547 uint32_t max_element_index = 0; |
549 uint32_t elements = 0; | 548 uint32_t elements = 0; |
550 for (int i = 0; i < properties()->length(); i++) { | 549 for (int i = 0; i < properties()->length(); i++) { |
551 ObjectLiteral::Property* property = properties()->at(i); | 550 ObjectLiteral::Property* property = properties()->at(i); |
552 if (!IsBoilerplateProperty(property)) { | 551 if (!IsBoilerplateProperty(property)) { |
552 // __proto__:null at the first position has no side-effects and is set | |
adamk
2017/03/13 18:10:44
Why do you say "first position"? The placement of
| |
553 // directly on the boilerplate. | |
554 if (property->IsNullPrototype()) continue; | |
553 is_simple = false; | 555 is_simple = false; |
554 continue; | 556 continue; |
555 } | 557 } |
556 | 558 |
557 if (static_cast<uint32_t>(position) == boilerplate_properties_ * 2) { | 559 if (static_cast<uint32_t>(position) == boilerplate_properties_ * 2) { |
558 DCHECK(property->is_computed_name()); | 560 DCHECK(property->is_computed_name()); |
559 is_simple = false; | 561 is_simple = false; |
560 break; | 562 break; |
561 } | 563 } |
562 DCHECK(!property->is_computed_name()); | 564 DCHECK(!property->is_computed_name()); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1114 #ifdef DEBUG | 1116 #ifdef DEBUG |
1115 return is_jsruntime() ? NameForNativeContextIntrinsicIndex(context_index_) | 1117 return is_jsruntime() ? NameForNativeContextIntrinsicIndex(context_index_) |
1116 : function_->name; | 1118 : function_->name; |
1117 #else | 1119 #else |
1118 return is_jsruntime() ? "(context function)" : function_->name; | 1120 return is_jsruntime() ? "(context function)" : function_->name; |
1119 #endif // DEBUG | 1121 #endif // DEBUG |
1120 } | 1122 } |
1121 | 1123 |
1122 } // namespace internal | 1124 } // namespace internal |
1123 } // namespace v8 | 1125 } // namespace v8 |
OLD | NEW |