OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 15483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15494 if ((attr & filter) == 0) result++; | 15494 if ((attr & filter) == 0) result++; |
15495 } | 15495 } |
15496 } | 15496 } |
15497 return result; | 15497 return result; |
15498 } | 15498 } |
15499 | 15499 |
15500 | 15500 |
15501 template<typename Shape, typename Key> | 15501 template<typename Shape, typename Key> |
15502 int Dictionary<Shape, Key>::NumberOfEnumElements() { | 15502 int Dictionary<Shape, Key>::NumberOfEnumElements() { |
15503 return NumberOfElementsFilterAttributes( | 15503 return NumberOfElementsFilterAttributes( |
15504 static_cast<PropertyAttributes>(DONT_ENUM)); | 15504 static_cast<PropertyAttributes>(DONT_ENUM | SYMBOLIC)); |
15505 } | 15505 } |
15506 | 15506 |
15507 | 15507 |
15508 template<typename Shape, typename Key> | 15508 template<typename Shape, typename Key> |
15509 void Dictionary<Shape, Key>::CopyKeysTo( | 15509 void Dictionary<Shape, Key>::CopyKeysTo( |
15510 FixedArray* storage, | 15510 FixedArray* storage, |
15511 PropertyAttributes filter, | 15511 PropertyAttributes filter, |
15512 typename Dictionary<Shape, Key>::SortMode sort_mode) { | 15512 typename Dictionary<Shape, Key>::SortMode sort_mode) { |
15513 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); | 15513 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); |
15514 int capacity = HashTable<Shape, Key>::Capacity(); | 15514 int capacity = HashTable<Shape, Key>::Capacity(); |
15515 int index = 0; | 15515 int index = 0; |
15516 for (int i = 0; i < capacity; i++) { | 15516 for (int i = 0; i < capacity; i++) { |
15517 Object* k = HashTable<Shape, Key>::KeyAt(i); | 15517 Object* k = HashTable<Shape, Key>::KeyAt(i); |
15518 if (HashTable<Shape, Key>::IsKey(k) && !FilterKey(k, filter)) { | 15518 if (HashTable<Shape, Key>::IsKey(k) && !FilterKey(k, filter)) { |
15519 PropertyDetails details = DetailsAt(i); | 15519 PropertyDetails details = DetailsAt(i); |
15520 if (details.IsDeleted()) continue; | 15520 if (details.IsDeleted()) continue; |
15521 PropertyAttributes attr = details.attributes(); | 15521 PropertyAttributes attr = details.attributes(); |
15522 if ((attr & filter) == 0) storage->set(index++, k); | 15522 if ((attr & filter) == 0) storage->set(index++, k); |
15523 } | 15523 } |
15524 } | 15524 } |
15525 if (sort_mode == Dictionary<Shape, Key>::SORTED) { | 15525 if (sort_mode == Dictionary<Shape, Key>::SORTED) { |
15526 storage->SortPairs(storage, index); | 15526 storage->SortPairs(storage, index); |
15527 } | 15527 } |
15528 ASSERT(storage->length() >= index); | 15528 ASSERT(storage->length() >= index); |
15529 } | 15529 } |
15530 | 15530 |
15531 | 15531 |
15532 FixedArray* NameDictionary::CopyEnumKeysTo(FixedArray* storage) { | 15532 struct EnumIndexComparator { |
| 15533 explicit EnumIndexComparator(NameDictionary* dict) : dict(dict) { } |
| 15534 bool operator() (Smi* a, Smi* b) { |
| 15535 PropertyDetails da(dict->DetailsAt(a->value())); |
| 15536 PropertyDetails db(dict->DetailsAt(b->value())); |
| 15537 return da.dictionary_index() < db.dictionary_index(); |
| 15538 } |
| 15539 NameDictionary* dict; |
| 15540 }; |
| 15541 |
| 15542 |
| 15543 void NameDictionary::CopyEnumKeysTo(FixedArray* storage) { |
15533 int length = storage->length(); | 15544 int length = storage->length(); |
15534 ASSERT(length >= NumberOfEnumElements()); | |
15535 Heap* heap = GetHeap(); | |
15536 Object* undefined_value = heap->undefined_value(); | |
15537 int capacity = Capacity(); | 15545 int capacity = Capacity(); |
15538 int properties = 0; | 15546 int properties = 0; |
15539 | |
15540 // Fill in the enumeration array by assigning enumerable keys at their | |
15541 // enumeration index. This will leave holes in the array if there are keys | |
15542 // that are deleted or not enumerable. | |
15543 for (int i = 0; i < capacity; i++) { | 15547 for (int i = 0; i < capacity; i++) { |
15544 Object* k = KeyAt(i); | 15548 Object* k = KeyAt(i); |
15545 if (IsKey(k) && !k->IsSymbol()) { | 15549 if (IsKey(k) && !k->IsSymbol()) { |
15546 PropertyDetails details = DetailsAt(i); | 15550 PropertyDetails details = DetailsAt(i); |
15547 if (details.IsDeleted() || details.IsDontEnum()) continue; | 15551 if (details.IsDeleted() || details.IsDontEnum()) continue; |
| 15552 storage->set(properties, Smi::FromInt(i)); |
15548 properties++; | 15553 properties++; |
15549 storage->set(details.dictionary_index() - 1, k); | |
15550 if (properties == length) break; | 15554 if (properties == length) break; |
15551 } | 15555 } |
15552 } | 15556 } |
15553 | 15557 EnumIndexComparator cmp(this); |
15554 // There are holes in the enumeration array if less properties were assigned | 15558 Smi** start = reinterpret_cast<Smi**>(storage->GetFirstElementAddress()); |
15555 // than the length of the array. If so, crunch all the existing properties | 15559 std::sort(start, start + length, cmp); |
15556 // together by shifting them to the left (maintaining the enumeration order), | 15560 for (int i = 0; i < length; i++) { |
15557 // and trimming of the right side of the array. | 15561 int index = Smi::cast(storage->get(i))->value(); |
15558 if (properties < length) { | 15562 storage->set(i, KeyAt(index)); |
15559 if (properties == 0) return heap->empty_fixed_array(); | |
15560 properties = 0; | |
15561 for (int i = 0; i < length; ++i) { | |
15562 Object* value = storage->get(i); | |
15563 if (value != undefined_value) { | |
15564 storage->set(properties, value); | |
15565 ++properties; | |
15566 } | |
15567 } | |
15568 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties); | |
15569 } | 15563 } |
15570 return storage; | |
15571 } | 15564 } |
15572 | 15565 |
15573 | 15566 |
15574 template<typename Shape, typename Key> | 15567 template<typename Shape, typename Key> |
15575 void Dictionary<Shape, Key>::CopyKeysTo( | 15568 void Dictionary<Shape, Key>::CopyKeysTo( |
15576 FixedArray* storage, | 15569 FixedArray* storage, |
15577 int index, | 15570 int index, |
15578 PropertyAttributes filter, | 15571 PropertyAttributes filter, |
15579 typename Dictionary<Shape, Key>::SortMode sort_mode) { | 15572 typename Dictionary<Shape, Key>::SortMode sort_mode) { |
15580 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); | 15573 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16475 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16468 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16476 static const char* error_messages_[] = { | 16469 static const char* error_messages_[] = { |
16477 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16470 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16478 }; | 16471 }; |
16479 #undef ERROR_MESSAGES_TEXTS | 16472 #undef ERROR_MESSAGES_TEXTS |
16480 return error_messages_[reason]; | 16473 return error_messages_[reason]; |
16481 } | 16474 } |
16482 | 16475 |
16483 | 16476 |
16484 } } // namespace v8::internal | 16477 } } // namespace v8::internal |
OLD | NEW |