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 2946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2957 PrintF("Object elements have been normalized:\n"); | 2957 PrintF("Object elements have been normalized:\n"); |
2958 Print(); | 2958 Print(); |
2959 } | 2959 } |
2960 #endif | 2960 #endif |
2961 | 2961 |
2962 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); | 2962 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); |
2963 return dictionary; | 2963 return dictionary; |
2964 } | 2964 } |
2965 | 2965 |
2966 | 2966 |
| 2967 MaybeObject* JSObject::GetHiddenProperties(HiddenPropertiesFlag flag) { |
| 2968 Isolate* isolate = GetIsolate(); |
| 2969 Heap* heap = isolate->heap(); |
| 2970 Object* holder = BypassGlobalProxy(); |
| 2971 if (holder->IsUndefined()) return heap->undefined_value(); |
| 2972 JSObject* obj = JSObject::cast(holder); |
| 2973 if (obj->HasFastProperties()) { |
| 2974 // If the object has fast properties, check whether the first slot |
| 2975 // in the descriptor array matches the hidden symbol. Since the |
| 2976 // hidden symbols hash code is zero (and no other string has hash |
| 2977 // code zero) it will always occupy the first entry if present. |
| 2978 DescriptorArray* descriptors = obj->map()->instance_descriptors(); |
| 2979 if ((descriptors->number_of_descriptors() > 0) && |
| 2980 (descriptors->GetKey(0) == heap->hidden_symbol()) && |
| 2981 descriptors->IsProperty(0)) { |
| 2982 ASSERT(descriptors->GetType(0) == FIELD); |
| 2983 return obj->FastPropertyAt(descriptors->GetFieldIndex(0)); |
| 2984 } |
| 2985 } |
| 2986 |
| 2987 // Only attempt to find the hidden properties in the local object and not |
| 2988 // in the prototype chain. |
| 2989 if (!obj->HasHiddenPropertiesObject()) { |
| 2990 // Hidden properties object not found. Allocate a new hidden properties |
| 2991 // object if requested. Otherwise return the undefined value. |
| 2992 if (flag == ALLOW_CREATION) { |
| 2993 Object* hidden_obj; |
| 2994 { MaybeObject* maybe_obj = heap->AllocateJSObject( |
| 2995 isolate->context()->global_context()->object_function()); |
| 2996 if (!maybe_obj->ToObject(&hidden_obj)) return maybe_obj; |
| 2997 } |
| 2998 return obj->SetHiddenPropertiesObject(hidden_obj); |
| 2999 } else { |
| 3000 return heap->undefined_value(); |
| 3001 } |
| 3002 } |
| 3003 return obj->GetHiddenPropertiesObject(); |
| 3004 } |
| 3005 |
| 3006 |
| 3007 MaybeObject* JSObject::GetIdentityHash(HiddenPropertiesFlag flag) { |
| 3008 Isolate* isolate = GetIsolate(); |
| 3009 Object* hidden_props_obj; |
| 3010 { MaybeObject* maybe_obj = GetHiddenProperties(flag); |
| 3011 if (!maybe_obj->ToObject(&hidden_props_obj)) return maybe_obj; |
| 3012 } |
| 3013 if (!hidden_props_obj->IsJSObject()) { |
| 3014 // We failed to create hidden properties. That's a detached |
| 3015 // global proxy. |
| 3016 ASSERT(hidden_props_obj->IsUndefined()); |
| 3017 return Smi::FromInt(0); |
| 3018 } |
| 3019 JSObject* hidden_props = JSObject::cast(hidden_props_obj); |
| 3020 String* hash_symbol = isolate->heap()->identity_hash_symbol(); |
| 3021 { |
| 3022 // Note that HasLocalProperty() can cause a GC in the general case in the |
| 3023 // presence of interceptors. |
| 3024 AssertNoAllocation no_alloc; |
| 3025 if (hidden_props->HasLocalProperty(hash_symbol)) { |
| 3026 MaybeObject* hash = hidden_props->GetProperty(hash_symbol); |
| 3027 return Smi::cast(hash->ToObjectChecked()); |
| 3028 } |
| 3029 } |
| 3030 |
| 3031 int hash_value; |
| 3032 int attempts = 0; |
| 3033 do { |
| 3034 // Generate a random 32-bit hash value but limit range to fit |
| 3035 // within a smi. |
| 3036 hash_value = V8::Random(isolate) & Smi::kMaxValue; |
| 3037 attempts++; |
| 3038 } while (hash_value == 0 && attempts < 30); |
| 3039 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
| 3040 |
| 3041 Smi* hash = Smi::FromInt(hash_value); |
| 3042 { MaybeObject* result = hidden_props->SetLocalPropertyIgnoreAttributes( |
| 3043 hash_symbol, |
| 3044 hash, |
| 3045 static_cast<PropertyAttributes>(None)); |
| 3046 if (result->IsFailure()) return result; |
| 3047 } |
| 3048 return hash; |
| 3049 } |
| 3050 |
| 3051 |
2967 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name, | 3052 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name, |
2968 DeleteMode mode) { | 3053 DeleteMode mode) { |
2969 // Check local property, ignore interceptor. | 3054 // Check local property, ignore interceptor. |
2970 LookupResult result; | 3055 LookupResult result; |
2971 LocalLookupRealNamedProperty(name, &result); | 3056 LocalLookupRealNamedProperty(name, &result); |
2972 if (!result.IsProperty()) return GetHeap()->true_value(); | 3057 if (!result.IsProperty()) return GetHeap()->true_value(); |
2973 | 3058 |
2974 // Normalize object if needed. | 3059 // Normalize object if needed. |
2975 Object* obj; | 3060 Object* obj; |
2976 { MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); | 3061 { MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); |
(...skipping 7385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10362 | 10447 |
10363 // Force instantiation of template instances class. | 10448 // Force instantiation of template instances class. |
10364 // Please note this list is compiler dependent. | 10449 // Please note this list is compiler dependent. |
10365 | 10450 |
10366 template class HashTable<SymbolTableShape, HashTableKey*>; | 10451 template class HashTable<SymbolTableShape, HashTableKey*>; |
10367 | 10452 |
10368 template class HashTable<CompilationCacheShape, HashTableKey*>; | 10453 template class HashTable<CompilationCacheShape, HashTableKey*>; |
10369 | 10454 |
10370 template class HashTable<MapCacheShape, HashTableKey*>; | 10455 template class HashTable<MapCacheShape, HashTableKey*>; |
10371 | 10456 |
| 10457 template class HashTable<ObjectHashTableShape, JSObject*>; |
| 10458 |
10372 template class Dictionary<StringDictionaryShape, String*>; | 10459 template class Dictionary<StringDictionaryShape, String*>; |
10373 | 10460 |
10374 template class Dictionary<NumberDictionaryShape, uint32_t>; | 10461 template class Dictionary<NumberDictionaryShape, uint32_t>; |
10375 | 10462 |
10376 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Allocate( | 10463 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Allocate( |
10377 int); | 10464 int); |
10378 | 10465 |
10379 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Allocate( | 10466 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Allocate( |
10380 int); | 10467 int); |
10381 | 10468 |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11673 ASSERT(obj->IsJSObject()); | 11760 ASSERT(obj->IsJSObject()); |
11674 | 11761 |
11675 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); | 11762 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); |
11676 // Check that it really works. | 11763 // Check that it really works. |
11677 ASSERT(obj->HasFastProperties()); | 11764 ASSERT(obj->HasFastProperties()); |
11678 | 11765 |
11679 return obj; | 11766 return obj; |
11680 } | 11767 } |
11681 | 11768 |
11682 | 11769 |
| 11770 Object* ObjectHashTable::Lookup(JSObject* key) { |
| 11771 // If the object does not have an identity hash, it was never used as a key. |
| 11772 MaybeObject* maybe_hash = key->GetIdentityHash(JSObject::OMIT_CREATION); |
| 11773 if (maybe_hash->IsFailure()) return GetHeap()->undefined_value(); |
| 11774 int entry = FindEntry(key); |
| 11775 if (entry == kNotFound) return GetHeap()->undefined_value(); |
| 11776 return get(EntryToIndex(entry) + 1); |
| 11777 } |
| 11778 |
| 11779 |
| 11780 MaybeObject* ObjectHashTable::Put(JSObject* key, Object* value) { |
| 11781 // Make sure the key object has an identity hash code. |
| 11782 int hash; |
| 11783 { MaybeObject* maybe_hash = key->GetIdentityHash(JSObject::ALLOW_CREATION); |
| 11784 if (maybe_hash->IsFailure()) return maybe_hash; |
| 11785 hash = Smi::cast(maybe_hash->ToObjectUnchecked())->value(); |
| 11786 } |
| 11787 int entry = FindEntry(key); |
| 11788 |
| 11789 // Check whether to perform removal operation. |
| 11790 if (value->IsUndefined()) { |
| 11791 if (entry == kNotFound) return this; |
| 11792 RemoveEntry(entry); |
| 11793 return Shrink(key); |
| 11794 } |
| 11795 |
| 11796 // Key is already in table, just overwrite value. |
| 11797 if (entry != kNotFound) { |
| 11798 set(EntryToIndex(entry) + 1, value); |
| 11799 return this; |
| 11800 } |
| 11801 |
| 11802 // Check whether the hash table should be extended. |
| 11803 Object* obj; |
| 11804 { MaybeObject* maybe_obj = EnsureCapacity(1, key); |
| 11805 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 11806 } |
| 11807 ObjectHashTable* table = ObjectHashTable::cast(obj); |
| 11808 table->AddEntry(table->FindInsertionEntry(hash), key, value); |
| 11809 return table; |
| 11810 } |
| 11811 |
| 11812 |
| 11813 void ObjectHashTable::AddEntry(int entry, JSObject* key, Object* value) { |
| 11814 set(EntryToIndex(entry), key); |
| 11815 set(EntryToIndex(entry) + 1, value); |
| 11816 ElementAdded(); |
| 11817 } |
| 11818 |
| 11819 |
| 11820 void ObjectHashTable::RemoveEntry(int entry) { |
| 11821 Object* null_value = GetHeap()->null_value(); |
| 11822 set(EntryToIndex(entry), null_value); |
| 11823 set(EntryToIndex(entry) + 1, null_value); |
| 11824 ElementRemoved(); |
| 11825 } |
| 11826 |
| 11827 |
11683 #ifdef ENABLE_DEBUGGER_SUPPORT | 11828 #ifdef ENABLE_DEBUGGER_SUPPORT |
11684 // Check if there is a break point at this code position. | 11829 // Check if there is a break point at this code position. |
11685 bool DebugInfo::HasBreakPoint(int code_position) { | 11830 bool DebugInfo::HasBreakPoint(int code_position) { |
11686 // Get the break point info object for this code position. | 11831 // Get the break point info object for this code position. |
11687 Object* break_point_info = GetBreakPointInfo(code_position); | 11832 Object* break_point_info = GetBreakPointInfo(code_position); |
11688 | 11833 |
11689 // If there is no break point info object or no break points in the break | 11834 // If there is no break point info object or no break points in the break |
11690 // point info object there is no break point at this code position. | 11835 // point info object there is no break point at this code position. |
11691 if (break_point_info->IsUndefined()) return false; | 11836 if (break_point_info->IsUndefined()) return false; |
11692 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; | 11837 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11927 if (break_point_objects()->IsUndefined()) return 0; | 12072 if (break_point_objects()->IsUndefined()) return 0; |
11928 // Single beak point. | 12073 // Single beak point. |
11929 if (!break_point_objects()->IsFixedArray()) return 1; | 12074 if (!break_point_objects()->IsFixedArray()) return 1; |
11930 // Multiple break points. | 12075 // Multiple break points. |
11931 return FixedArray::cast(break_point_objects())->length(); | 12076 return FixedArray::cast(break_point_objects())->length(); |
11932 } | 12077 } |
11933 #endif | 12078 #endif |
11934 | 12079 |
11935 | 12080 |
11936 } } // namespace v8::internal | 12081 } } // namespace v8::internal |
OLD | NEW |