Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: src/objects.cc

Issue 7351014: Revert r8619 because of Webkit failures. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2872 matching lines...) Expand 10 before | Expand all | Expand 10 after
2883 PrintF("Object elements have been normalized:\n"); 2883 PrintF("Object elements have been normalized:\n");
2884 Print(); 2884 Print();
2885 } 2885 }
2886 #endif 2886 #endif
2887 2887
2888 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); 2888 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements());
2889 return dictionary; 2889 return dictionary;
2890 } 2890 }
2891 2891
2892 2892
2893 MaybeObject* JSObject::GetHiddenProperties(bool create_if_needed) {
2894 Isolate* isolate = GetIsolate();
2895 Heap* heap = isolate->heap();
2896 if (HasFastProperties()) {
2897 // If the object has fast properties, check whether the first slot
2898 // in the descriptor array matches the hidden symbol. Since the
2899 // hidden symbols hash code is zero (and no other string has hash
2900 // code zero) it will always occupy the first entry if present.
2901 DescriptorArray* descriptors = map()->instance_descriptors();
2902 if ((descriptors->number_of_descriptors() > 0) &&
2903 (descriptors->GetKey(0) == heap->hidden_symbol()) &&
2904 descriptors->IsProperty(0)) {
2905 ASSERT(descriptors->GetType(0) == FIELD);
2906 return FastPropertyAt(descriptors->GetFieldIndex(0));
2907 }
2908 }
2909
2910 // Only attempt to find the hidden properties in the local object and not
2911 // in the prototype chain. Note that HasLocalProperty() can cause a GC in
2912 // the general case in the presence of interceptors.
2913 if (!HasHiddenPropertiesObject()) {
2914 // Hidden properties object not found. Allocate a new hidden properties
2915 // object if requested. Otherwise return the undefined value.
2916 if (create_if_needed) {
2917 Object* hidden_obj;
2918 { MaybeObject* maybe_obj = heap->AllocateJSObject(
2919 isolate->context()->global_context()->object_function());
2920 if (!maybe_obj->ToObject(&hidden_obj)) return maybe_obj;
2921 }
2922 return SetHiddenPropertiesObject(hidden_obj);
2923 } else {
2924 return heap->undefined_value();
2925 }
2926 }
2927 return GetHiddenPropertiesObject();
2928 }
2929
2930
2931 MaybeObject* JSObject::GetIdentityHash() {
2932 Isolate* isolate = GetIsolate();
2933 Object* hidden_props_obj;
2934 { MaybeObject* maybe_obj = GetHiddenProperties(true);
2935 if (!maybe_obj->ToObject(&hidden_props_obj)) return maybe_obj;
2936 }
2937 if (!hidden_props_obj->IsJSObject()) {
2938 // We failed to create hidden properties. That's a detached
2939 // global proxy.
2940 ASSERT(hidden_props_obj->IsUndefined());
2941 return Smi::FromInt(0);
2942 }
2943 JSObject* hidden_props = JSObject::cast(hidden_props_obj);
2944 String* hash_symbol = isolate->heap()->identity_hash_symbol();
2945 if (hidden_props->HasLocalProperty(hash_symbol)) {
2946 MaybeObject* hash = hidden_props->GetProperty(hash_symbol);
2947 return Smi::cast(hash->ToObjectChecked());
2948 }
2949
2950 int hash_value;
2951 int attempts = 0;
2952 do {
2953 // Generate a random 32-bit hash value but limit range to fit
2954 // within a smi.
2955 hash_value = V8::Random(isolate) & Smi::kMaxValue;
2956 attempts++;
2957 } while (hash_value == 0 && attempts < 30);
2958 hash_value = hash_value != 0 ? hash_value : 1; // never return 0
2959
2960 Smi* hash = Smi::FromInt(hash_value);
2961 { MaybeObject* result = hidden_props->SetLocalPropertyIgnoreAttributes(
2962 hash_symbol,
2963 hash,
2964 static_cast<PropertyAttributes>(None));
2965 if (result->IsFailure()) return result;
2966 }
2967 return hash;
2968 }
2969
2970
2971 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name, 2893 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name,
2972 DeleteMode mode) { 2894 DeleteMode mode) {
2973 // Check local property, ignore interceptor. 2895 // Check local property, ignore interceptor.
2974 LookupResult result; 2896 LookupResult result;
2975 LocalLookupRealNamedProperty(name, &result); 2897 LocalLookupRealNamedProperty(name, &result);
2976 if (!result.IsProperty()) return GetHeap()->true_value(); 2898 if (!result.IsProperty()) return GetHeap()->true_value();
2977 2899
2978 // Normalize object if needed. 2900 // Normalize object if needed.
2979 Object* obj; 2901 Object* obj;
2980 { MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 2902 { MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
(...skipping 7225 matching lines...) Expand 10 before | Expand all | Expand 10 after
10206 template class HashTable<SymbolTableShape, HashTableKey*>; 10128 template class HashTable<SymbolTableShape, HashTableKey*>;
10207 10129
10208 template class HashTable<CompilationCacheShape, HashTableKey*>; 10130 template class HashTable<CompilationCacheShape, HashTableKey*>;
10209 10131
10210 template class HashTable<MapCacheShape, HashTableKey*>; 10132 template class HashTable<MapCacheShape, HashTableKey*>;
10211 10133
10212 template class Dictionary<StringDictionaryShape, String*>; 10134 template class Dictionary<StringDictionaryShape, String*>;
10213 10135
10214 template class Dictionary<NumberDictionaryShape, uint32_t>; 10136 template class Dictionary<NumberDictionaryShape, uint32_t>;
10215 10137
10216 template class Dictionary<ObjectDictionaryShape, JSObject*>;
10217
10218 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Allocate( 10138 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Allocate(
10219 int); 10139 int);
10220 10140
10221 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Allocate( 10141 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Allocate(
10222 int); 10142 int);
10223 10143
10224 template MaybeObject* Dictionary<ObjectDictionaryShape, JSObject*>::Allocate(
10225 int);
10226
10227 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::AtPut( 10144 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::AtPut(
10228 uint32_t, Object*); 10145 uint32_t, Object*);
10229 10146
10230 template Object* Dictionary<NumberDictionaryShape, uint32_t>::SlowReverseLookup( 10147 template Object* Dictionary<NumberDictionaryShape, uint32_t>::SlowReverseLookup(
10231 Object*); 10148 Object*);
10232 10149
10233 template Object* Dictionary<StringDictionaryShape, String*>::SlowReverseLookup( 10150 template Object* Dictionary<StringDictionaryShape, String*>::SlowReverseLookup(
10234 Object*); 10151 Object*);
10235 10152
10236 template void Dictionary<NumberDictionaryShape, uint32_t>::CopyKeysTo( 10153 template void Dictionary<NumberDictionaryShape, uint32_t>::CopyKeysTo(
(...skipping 17 matching lines...) Expand all
10254 FixedArray*, 10171 FixedArray*,
10255 Dictionary<StringDictionaryShape, String*>::SortMode); 10172 Dictionary<StringDictionaryShape, String*>::SortMode);
10256 10173
10257 template int 10174 template int
10258 Dictionary<StringDictionaryShape, String*>::NumberOfElementsFilterAttributes( 10175 Dictionary<StringDictionaryShape, String*>::NumberOfElementsFilterAttributes(
10259 PropertyAttributes); 10176 PropertyAttributes);
10260 10177
10261 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Add( 10178 template MaybeObject* Dictionary<StringDictionaryShape, String*>::Add(
10262 String*, Object*, PropertyDetails); 10179 String*, Object*, PropertyDetails);
10263 10180
10264 template MaybeObject* Dictionary<ObjectDictionaryShape, JSObject*>::Add(
10265 JSObject*, Object*, PropertyDetails);
10266
10267 template MaybeObject* 10181 template MaybeObject*
10268 Dictionary<StringDictionaryShape, String*>::GenerateNewEnumerationIndices(); 10182 Dictionary<StringDictionaryShape, String*>::GenerateNewEnumerationIndices();
10269 10183
10270 template int 10184 template int
10271 Dictionary<NumberDictionaryShape, uint32_t>::NumberOfElementsFilterAttributes( 10185 Dictionary<NumberDictionaryShape, uint32_t>::NumberOfElementsFilterAttributes(
10272 PropertyAttributes); 10186 PropertyAttributes);
10273 10187
10274 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Add( 10188 template MaybeObject* Dictionary<NumberDictionaryShape, uint32_t>::Add(
10275 uint32_t, Object*, PropertyDetails); 10189 uint32_t, Object*, PropertyDetails);
10276 10190
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
11216 // Insert element at empty or deleted entry 11130 // Insert element at empty or deleted entry
11217 if (!details.IsDeleted() && details.index() == 0 && Shape::kIsEnumerable) { 11131 if (!details.IsDeleted() && details.index() == 0 && Shape::kIsEnumerable) {
11218 // Assign an enumeration index to the property and update 11132 // Assign an enumeration index to the property and update
11219 // SetNextEnumerationIndex. 11133 // SetNextEnumerationIndex.
11220 int index = NextEnumerationIndex(); 11134 int index = NextEnumerationIndex();
11221 details = PropertyDetails(details.attributes(), details.type(), index); 11135 details = PropertyDetails(details.attributes(), details.type(), index);
11222 SetNextEnumerationIndex(index + 1); 11136 SetNextEnumerationIndex(index + 1);
11223 } 11137 }
11224 SetEntry(entry, k, value, details); 11138 SetEntry(entry, k, value, details);
11225 ASSERT((Dictionary<Shape, Key>::KeyAt(entry)->IsNumber() 11139 ASSERT((Dictionary<Shape, Key>::KeyAt(entry)->IsNumber()
11226 || Dictionary<Shape, Key>::KeyAt(entry)->IsString() 11140 || Dictionary<Shape, Key>::KeyAt(entry)->IsString()));
11227 || Dictionary<Shape, Key>::KeyAt(entry)->IsJSObject()));
11228 HashTable<Shape, Key>::ElementAdded(); 11141 HashTable<Shape, Key>::ElementAdded();
11229 return this; 11142 return this;
11230 } 11143 }
11231 11144
11232 11145
11233 void NumberDictionary::UpdateMaxNumberKey(uint32_t key) { 11146 void NumberDictionary::UpdateMaxNumberKey(uint32_t key) {
11234 // If the dictionary requires slow elements an element has already 11147 // If the dictionary requires slow elements an element has already
11235 // been added at a high index. 11148 // been added at a high index.
11236 if (requires_slow_elements()) return; 11149 if (requires_slow_elements()) return;
11237 // Check if this index is high enough that we should require slow 11150 // Check if this index is high enough that we should require slow
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
11522 ASSERT(obj->IsJSObject()); 11435 ASSERT(obj->IsJSObject());
11523 11436
11524 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); 11437 descriptors->SetNextEnumerationIndex(NextEnumerationIndex());
11525 // Check that it really works. 11438 // Check that it really works.
11526 ASSERT(obj->HasFastProperties()); 11439 ASSERT(obj->HasFastProperties());
11527 11440
11528 return obj; 11441 return obj;
11529 } 11442 }
11530 11443
11531 11444
11532 MaybeObject* ObjectDictionary::AddChecked(JSObject* key, Object* value) {
11533 // Make sure the key object has an identity hash code.
11534 MaybeObject* maybe_hash = key->GetIdentityHash();
11535 if (maybe_hash->IsFailure()) return maybe_hash;
11536 PropertyDetails details(NONE, NORMAL);
11537 return Add(key, value, details);
11538 }
11539
11540
11541 #ifdef ENABLE_DEBUGGER_SUPPORT 11445 #ifdef ENABLE_DEBUGGER_SUPPORT
11542 // Check if there is a break point at this code position. 11446 // Check if there is a break point at this code position.
11543 bool DebugInfo::HasBreakPoint(int code_position) { 11447 bool DebugInfo::HasBreakPoint(int code_position) {
11544 // Get the break point info object for this code position. 11448 // Get the break point info object for this code position.
11545 Object* break_point_info = GetBreakPointInfo(code_position); 11449 Object* break_point_info = GetBreakPointInfo(code_position);
11546 11450
11547 // If there is no break point info object or no break points in the break 11451 // If there is no break point info object or no break points in the break
11548 // point info object there is no break point at this code position. 11452 // point info object there is no break point at this code position.
11549 if (break_point_info->IsUndefined()) return false; 11453 if (break_point_info->IsUndefined()) return false;
11550 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; 11454 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
11785 if (break_point_objects()->IsUndefined()) return 0; 11689 if (break_point_objects()->IsUndefined()) return 0;
11786 // Single beak point. 11690 // Single beak point.
11787 if (!break_point_objects()->IsFixedArray()) return 1; 11691 if (!break_point_objects()->IsFixedArray()) return 1;
11788 // Multiple break points. 11692 // Multiple break points.
11789 return FixedArray::cast(break_point_objects())->length(); 11693 return FixedArray::cast(break_point_objects())->length();
11790 } 11694 }
11791 #endif 11695 #endif
11792 11696
11793 11697
11794 } } // namespace v8::internal 11698 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698