OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 hash); | 3582 hash); |
3583 if (maybe->IsFailure()) return maybe; | 3583 if (maybe->IsFailure()) return maybe; |
3584 return this; | 3584 return this; |
3585 } | 3585 } |
3586 | 3586 |
3587 | 3587 |
3588 MaybeObject* JSObject::GetIdentityHash(CreationFlag flag) { | 3588 MaybeObject* JSObject::GetIdentityHash(CreationFlag flag) { |
3589 Object* stored_value = GetHiddenProperty(GetHeap()->identity_hash_symbol()); | 3589 Object* stored_value = GetHiddenProperty(GetHeap()->identity_hash_symbol()); |
3590 if (stored_value->IsSmi()) return stored_value; | 3590 if (stored_value->IsSmi()) return stored_value; |
3591 | 3591 |
| 3592 // Do not generate permanent identity hash code if not requested. |
| 3593 if (flag == OMIT_CREATION) return GetHeap()->undefined_value(); |
| 3594 |
3592 Smi* hash = GenerateIdentityHash(); | 3595 Smi* hash = GenerateIdentityHash(); |
3593 MaybeObject* result = SetHiddenProperty(GetHeap()->identity_hash_symbol(), | 3596 MaybeObject* result = SetHiddenProperty(GetHeap()->identity_hash_symbol(), |
3594 hash); | 3597 hash); |
3595 if (result->IsFailure()) return result; | 3598 if (result->IsFailure()) return result; |
3596 if (result->ToObjectUnchecked()->IsUndefined()) { | 3599 if (result->ToObjectUnchecked()->IsUndefined()) { |
3597 // Trying to get hash of detached proxy. | 3600 // Trying to get hash of detached proxy. |
3598 return Smi::FromInt(0); | 3601 return Smi::FromInt(0); |
3599 } | 3602 } |
3600 return hash; | 3603 return hash; |
3601 } | 3604 } |
(...skipping 8781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12383 // Check that it really works. | 12386 // Check that it really works. |
12384 ASSERT(obj->HasFastProperties()); | 12387 ASSERT(obj->HasFastProperties()); |
12385 | 12388 |
12386 return obj; | 12389 return obj; |
12387 } | 12390 } |
12388 | 12391 |
12389 | 12392 |
12390 bool ObjectHashSet::Contains(Object* key) { | 12393 bool ObjectHashSet::Contains(Object* key) { |
12391 // If the object does not have an identity hash, it was never used as a key. | 12394 // If the object does not have an identity hash, it was never used as a key. |
12392 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); | 12395 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
12393 if (maybe_hash->IsFailure()) return false; | 12396 if (maybe_hash->ToObjectUnchecked()->IsUndefined()) return false; |
12394 } | 12397 } |
12395 return (FindEntry(key) != kNotFound); | 12398 return (FindEntry(key) != kNotFound); |
12396 } | 12399 } |
12397 | 12400 |
12398 | 12401 |
12399 MaybeObject* ObjectHashSet::Add(Object* key) { | 12402 MaybeObject* ObjectHashSet::Add(Object* key) { |
12400 // Make sure the key object has an identity hash code. | 12403 // Make sure the key object has an identity hash code. |
12401 int hash; | 12404 int hash; |
12402 { MaybeObject* maybe_hash = key->GetHash(ALLOW_CREATION); | 12405 { MaybeObject* maybe_hash = key->GetHash(ALLOW_CREATION); |
12403 if (maybe_hash->IsFailure()) return maybe_hash; | 12406 if (maybe_hash->IsFailure()) return maybe_hash; |
(...skipping 13 matching lines...) Expand all Loading... |
12417 entry = table->FindInsertionEntry(hash); | 12420 entry = table->FindInsertionEntry(hash); |
12418 table->set(EntryToIndex(entry), key); | 12421 table->set(EntryToIndex(entry), key); |
12419 table->ElementAdded(); | 12422 table->ElementAdded(); |
12420 return table; | 12423 return table; |
12421 } | 12424 } |
12422 | 12425 |
12423 | 12426 |
12424 MaybeObject* ObjectHashSet::Remove(Object* key) { | 12427 MaybeObject* ObjectHashSet::Remove(Object* key) { |
12425 // If the object does not have an identity hash, it was never used as a key. | 12428 // If the object does not have an identity hash, it was never used as a key. |
12426 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); | 12429 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
12427 if (maybe_hash->IsFailure()) return this; | 12430 if (maybe_hash->ToObjectUnchecked()->IsUndefined()) return this; |
12428 } | 12431 } |
12429 int entry = FindEntry(key); | 12432 int entry = FindEntry(key); |
12430 | 12433 |
12431 // Check whether key is actually present. | 12434 // Check whether key is actually present. |
12432 if (entry == kNotFound) return this; | 12435 if (entry == kNotFound) return this; |
12433 | 12436 |
12434 // Remove entry and try to shrink this hash set. | 12437 // Remove entry and try to shrink this hash set. |
12435 set_null(EntryToIndex(entry)); | 12438 set_null(EntryToIndex(entry)); |
12436 ElementRemoved(); | 12439 ElementRemoved(); |
12437 return Shrink(key); | 12440 return Shrink(key); |
12438 } | 12441 } |
12439 | 12442 |
12440 | 12443 |
12441 Object* ObjectHashTable::Lookup(Object* key) { | 12444 Object* ObjectHashTable::Lookup(Object* key) { |
12442 // If the object does not have an identity hash, it was never used as a key. | 12445 // If the object does not have an identity hash, it was never used as a key. |
12443 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); | 12446 { MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
12444 if (maybe_hash->IsFailure()) GetHeap()->undefined_value(); | 12447 if (maybe_hash->ToObjectUnchecked()->IsUndefined()) { |
| 12448 return GetHeap()->undefined_value(); |
| 12449 } |
12445 } | 12450 } |
12446 int entry = FindEntry(key); | 12451 int entry = FindEntry(key); |
12447 if (entry == kNotFound) return GetHeap()->undefined_value(); | 12452 if (entry == kNotFound) return GetHeap()->undefined_value(); |
12448 return get(EntryToIndex(entry) + 1); | 12453 return get(EntryToIndex(entry) + 1); |
12449 } | 12454 } |
12450 | 12455 |
12451 | 12456 |
12452 MaybeObject* ObjectHashTable::Put(Object* key, Object* value) { | 12457 MaybeObject* ObjectHashTable::Put(Object* key, Object* value) { |
12453 // Make sure the key object has an identity hash code. | 12458 // Make sure the key object has an identity hash code. |
12454 int hash; | 12459 int hash; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12743 if (break_point_objects()->IsUndefined()) return 0; | 12748 if (break_point_objects()->IsUndefined()) return 0; |
12744 // Single break point. | 12749 // Single break point. |
12745 if (!break_point_objects()->IsFixedArray()) return 1; | 12750 if (!break_point_objects()->IsFixedArray()) return 1; |
12746 // Multiple break points. | 12751 // Multiple break points. |
12747 return FixedArray::cast(break_point_objects())->length(); | 12752 return FixedArray::cast(break_point_objects())->length(); |
12748 } | 12753 } |
12749 #endif // ENABLE_DEBUGGER_SUPPORT | 12754 #endif // ENABLE_DEBUGGER_SUPPORT |
12750 | 12755 |
12751 | 12756 |
12752 } } // namespace v8::internal | 12757 } } // namespace v8::internal |
OLD | NEW |