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

Side by Side Diff: src/objects.cc

Issue 10105026: Version 3.10.3 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 8 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-debug.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 } 1331 }
1332 1332
1333 switch (type) { 1333 switch (type) {
1334 case FIXED_ARRAY_TYPE: 1334 case FIXED_ARRAY_TYPE:
1335 FixedArray::BodyDescriptor::IterateBody(this, object_size, v); 1335 FixedArray::BodyDescriptor::IterateBody(this, object_size, v);
1336 break; 1336 break;
1337 case FIXED_DOUBLE_ARRAY_TYPE: 1337 case FIXED_DOUBLE_ARRAY_TYPE:
1338 break; 1338 break;
1339 case JS_OBJECT_TYPE: 1339 case JS_OBJECT_TYPE:
1340 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: 1340 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
1341 case JS_MODULE_TYPE:
1341 case JS_VALUE_TYPE: 1342 case JS_VALUE_TYPE:
1342 case JS_DATE_TYPE: 1343 case JS_DATE_TYPE:
1343 case JS_ARRAY_TYPE: 1344 case JS_ARRAY_TYPE:
1344 case JS_SET_TYPE: 1345 case JS_SET_TYPE:
1345 case JS_MAP_TYPE: 1346 case JS_MAP_TYPE:
1346 case JS_WEAK_MAP_TYPE: 1347 case JS_WEAK_MAP_TYPE:
1347 case JS_REGEXP_TYPE: 1348 case JS_REGEXP_TYPE:
1348 case JS_GLOBAL_PROXY_TYPE: 1349 case JS_GLOBAL_PROXY_TYPE:
1349 case JS_GLOBAL_OBJECT_TYPE: 1350 case JS_GLOBAL_OBJECT_TYPE:
1350 case JS_BUILTINS_OBJECT_TYPE: 1351 case JS_BUILTINS_OBJECT_TYPE:
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 // Get the cached index for the descriptors lookup, or find and cache it. 2315 // Get the cached index for the descriptors lookup, or find and cache it.
2315 DescriptorArray* descriptors = instance_descriptors(); 2316 DescriptorArray* descriptors = instance_descriptors();
2316 DescriptorLookupCache* cache = GetIsolate()->descriptor_lookup_cache(); 2317 DescriptorLookupCache* cache = GetIsolate()->descriptor_lookup_cache();
2317 int index = cache->Lookup(descriptors, sentinel_name); 2318 int index = cache->Lookup(descriptors, sentinel_name);
2318 if (index == DescriptorLookupCache::kAbsent) { 2319 if (index == DescriptorLookupCache::kAbsent) {
2319 index = descriptors->Search(sentinel_name); 2320 index = descriptors->Search(sentinel_name);
2320 cache->Update(descriptors, sentinel_name, index); 2321 cache->Update(descriptors, sentinel_name, index);
2321 } 2322 }
2322 // If the transition already exists, return its descriptor. 2323 // If the transition already exists, return its descriptor.
2323 if (index != DescriptorArray::kNotFound) { 2324 if (index != DescriptorArray::kNotFound) {
2324 PropertyDetails details(descriptors->GetDetails(index)); 2325 PropertyDetails details = descriptors->GetDetails(index);
2325 if (details.type() == ELEMENTS_TRANSITION) { 2326 if (details.type() == ELEMENTS_TRANSITION) {
2326 return descriptors->GetValue(index); 2327 return descriptors->GetValue(index);
2327 } else { 2328 } else {
2328 if (safe_to_add_transition != NULL) { 2329 if (safe_to_add_transition != NULL) {
2329 *safe_to_add_transition = false; 2330 *safe_to_add_transition = false;
2330 } 2331 }
2331 } 2332 }
2332 } 2333 }
2333 return NULL; 2334 return NULL;
2334 } 2335 }
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 object->GetIsolate(), 3019 object->GetIsolate(),
3019 object->SetLocalPropertyIgnoreAttributes(*key, *value, attributes), 3020 object->SetLocalPropertyIgnoreAttributes(*key, *value, attributes),
3020 Object); 3021 Object);
3021 } 3022 }
3022 3023
3023 3024
3024 MaybeObject* JSObject::SetLocalPropertyIgnoreAttributes( 3025 MaybeObject* JSObject::SetLocalPropertyIgnoreAttributes(
3025 String* name, 3026 String* name,
3026 Object* value, 3027 Object* value,
3027 PropertyAttributes attributes) { 3028 PropertyAttributes attributes) {
3028
3029 // Make sure that the top context does not change when doing callbacks or 3029 // Make sure that the top context does not change when doing callbacks or
3030 // interceptor calls. 3030 // interceptor calls.
3031 AssertNoContextChange ncc; 3031 AssertNoContextChange ncc;
3032 Isolate* isolate = GetIsolate(); 3032 Isolate* isolate = GetIsolate();
3033 LookupResult result(isolate); 3033 LookupResult result(isolate);
3034 LocalLookup(name, &result); 3034 LocalLookup(name, &result);
3035 // Check access rights if needed. 3035 // Check access rights if needed.
3036 if (IsAccessCheckNeeded()) { 3036 if (IsAccessCheckNeeded()) {
3037 if (!isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { 3037 if (!isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) {
3038 return SetPropertyWithFailedAccessCheck(&result, 3038 return SetPropertyWithFailedAccessCheck(&result,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 return ConvertDescriptorToField(name, value, attributes); 3087 return ConvertDescriptorToField(name, value, attributes);
3088 case CONSTANT_TRANSITION: 3088 case CONSTANT_TRANSITION:
3089 // Replace with a MAP_TRANSITION to a new map with a FIELD, even 3089 // Replace with a MAP_TRANSITION to a new map with a FIELD, even
3090 // if the value is a function. 3090 // if the value is a function.
3091 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); 3091 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes);
3092 case NULL_DESCRIPTOR: 3092 case NULL_DESCRIPTOR:
3093 case ELEMENTS_TRANSITION: 3093 case ELEMENTS_TRANSITION:
3094 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); 3094 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes);
3095 case HANDLER: 3095 case HANDLER:
3096 UNREACHABLE(); 3096 UNREACHABLE();
3097 return value;
3098 } 3097 }
3099 UNREACHABLE(); // keep the compiler happy 3098 UNREACHABLE(); // keep the compiler happy
3100 return value; 3099 return value;
3101 } 3100 }
3102 3101
3103 3102
3104 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( 3103 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor(
3105 JSObject* receiver, 3104 JSObject* receiver,
3106 String* name, 3105 String* name,
3107 bool continue_search) { 3106 bool continue_search) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
3338 } else { 3337 } else {
3339 property_count += 2; // Make space for two more properties. 3338 property_count += 2; // Make space for two more properties.
3340 } 3339 }
3341 StringDictionary* dictionary; 3340 StringDictionary* dictionary;
3342 { MaybeObject* maybe_dictionary = StringDictionary::Allocate(property_count); 3341 { MaybeObject* maybe_dictionary = StringDictionary::Allocate(property_count);
3343 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3342 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3344 } 3343 }
3345 3344
3346 DescriptorArray* descs = map_of_this->instance_descriptors(); 3345 DescriptorArray* descs = map_of_this->instance_descriptors();
3347 for (int i = 0; i < descs->number_of_descriptors(); i++) { 3346 for (int i = 0; i < descs->number_of_descriptors(); i++) {
3348 PropertyDetails details(descs->GetDetails(i)); 3347 PropertyDetails details = descs->GetDetails(i);
3349 switch (details.type()) { 3348 switch (details.type()) {
3350 case CONSTANT_FUNCTION: { 3349 case CONSTANT_FUNCTION: {
3351 PropertyDetails d = 3350 PropertyDetails d =
3352 PropertyDetails(details.attributes(), NORMAL, details.index()); 3351 PropertyDetails(details.attributes(), NORMAL, details.index());
3353 Object* value = descs->GetConstantFunction(i); 3352 Object* value = descs->GetConstantFunction(i);
3354 MaybeObject* maybe_dictionary = 3353 MaybeObject* maybe_dictionary =
3355 dictionary->Add(descs->GetKey(i), value, d); 3354 dictionary->Add(descs->GetKey(i), value, d);
3356 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3355 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3357 break; 3356 break;
3358 } 3357 }
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
4200 } 4199 }
4201 } 4200 }
4202 return true; 4201 return true;
4203 } 4202 }
4204 4203
4205 4204
4206 int Map::NumberOfDescribedProperties(PropertyAttributes filter) { 4205 int Map::NumberOfDescribedProperties(PropertyAttributes filter) {
4207 int result = 0; 4206 int result = 0;
4208 DescriptorArray* descs = instance_descriptors(); 4207 DescriptorArray* descs = instance_descriptors();
4209 for (int i = 0; i < descs->number_of_descriptors(); i++) { 4208 for (int i = 0; i < descs->number_of_descriptors(); i++) {
4210 PropertyDetails details(descs->GetDetails(i)); 4209 PropertyDetails details = descs->GetDetails(i);
4211 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) { 4210 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) {
4212 result++; 4211 result++;
4213 } 4212 }
4214 } 4213 }
4215 return result; 4214 return result;
4216 } 4215 }
4217 4216
4218 4217
4219 int Map::PropertyIndexFor(String* name) { 4218 int Map::PropertyIndexFor(String* name) {
4220 DescriptorArray* descs = instance_descriptors(); 4219 DescriptorArray* descs = instance_descriptors();
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
5681 CALL_HEAP_FUNCTION_VOID(dst->GetIsolate(), 5680 CALL_HEAP_FUNCTION_VOID(dst->GetIsolate(),
5682 dst->CopyFrom(dst_index, *src, src_index, witness)); 5681 dst->CopyFrom(dst_index, *src, src_index, witness));
5683 } 5682 }
5684 5683
5685 5684
5686 MaybeObject* DescriptorArray::CopyFrom(int dst_index, 5685 MaybeObject* DescriptorArray::CopyFrom(int dst_index,
5687 DescriptorArray* src, 5686 DescriptorArray* src,
5688 int src_index, 5687 int src_index,
5689 const WhitenessWitness& witness) { 5688 const WhitenessWitness& witness) {
5690 Object* value = src->GetValue(src_index); 5689 Object* value = src->GetValue(src_index);
5691 PropertyDetails details(src->GetDetails(src_index)); 5690 PropertyDetails details = src->GetDetails(src_index);
5692 if (details.type() == CALLBACKS && value->IsAccessorPair()) { 5691 if (details.type() == CALLBACKS && value->IsAccessorPair()) {
5693 MaybeObject* maybe_copy = 5692 MaybeObject* maybe_copy =
5694 AccessorPair::cast(value)->CopyWithoutTransitions(); 5693 AccessorPair::cast(value)->CopyWithoutTransitions();
5695 if (!maybe_copy->To(&value)) return maybe_copy; 5694 if (!maybe_copy->To(&value)) return maybe_copy;
5696 } 5695 }
5697 Descriptor desc(src->GetKey(src_index), value, details); 5696 Descriptor desc(src->GetKey(src_index), value, details);
5698 Set(dst_index, &desc, witness); 5697 Set(dst_index, &desc, witness);
5699 return this; 5698 return this;
5700 } 5699 }
5701 5700
(...skipping 22 matching lines...) Expand all
5724 } 5723 }
5725 5724
5726 // If key is in descriptor, we replace it in-place when filtering. 5725 // If key is in descriptor, we replace it in-place when filtering.
5727 // Count a null descriptor for key as inserted, not replaced. 5726 // Count a null descriptor for key as inserted, not replaced.
5728 int index = Search(descriptor->GetKey()); 5727 int index = Search(descriptor->GetKey());
5729 const bool replacing = (index != kNotFound); 5728 const bool replacing = (index != kNotFound);
5730 bool keep_enumeration_index = false; 5729 bool keep_enumeration_index = false;
5731 if (replacing) { 5730 if (replacing) {
5732 // We are replacing an existing descriptor. We keep the enumeration 5731 // We are replacing an existing descriptor. We keep the enumeration
5733 // index of a visible property. 5732 // index of a visible property.
5734 PropertyType t = PropertyDetails(GetDetails(index)).type(); 5733 PropertyType t = GetDetails(index).type();
5735 if (t == CONSTANT_FUNCTION || 5734 if (t == CONSTANT_FUNCTION ||
5736 t == FIELD || 5735 t == FIELD ||
5737 t == CALLBACKS || 5736 t == CALLBACKS ||
5738 t == INTERCEPTOR) { 5737 t == INTERCEPTOR) {
5739 keep_enumeration_index = true; 5738 keep_enumeration_index = true;
5740 } else if (remove_transitions) { 5739 } else if (remove_transitions) {
5741 // Replaced descriptor has been counted as removed if it is 5740 // Replaced descriptor has been counted as removed if it is
5742 // a transition that will be replaced. Adjust count in this case. 5741 // a transition that will be replaced. Adjust count in this case.
5743 ++new_size; 5742 ++new_size;
5744 } 5743 }
5745 } else { 5744 } else {
5746 ++new_size; 5745 ++new_size;
5747 } 5746 }
5748 5747
5749 DescriptorArray* new_descriptors; 5748 DescriptorArray* new_descriptors;
5750 { MaybeObject* maybe_result = Allocate(new_size); 5749 { MaybeObject* maybe_result = Allocate(new_size);
5751 if (!maybe_result->To(&new_descriptors)) return maybe_result; 5750 if (!maybe_result->To(&new_descriptors)) return maybe_result;
5752 } 5751 }
5753 5752
5754 DescriptorArray::WhitenessWitness witness(new_descriptors); 5753 DescriptorArray::WhitenessWitness witness(new_descriptors);
5755 5754
5756 // Set the enumeration index in the descriptors and set the enumeration index 5755 // Set the enumeration index in the descriptors and set the enumeration index
5757 // in the result. 5756 // in the result.
5758 int enumeration_index = NextEnumerationIndex(); 5757 int enumeration_index = NextEnumerationIndex();
5759 if (!descriptor->ContainsTransition()) { 5758 if (!descriptor->ContainsTransition()) {
5760 if (keep_enumeration_index) { 5759 if (keep_enumeration_index) {
5761 descriptor->SetEnumerationIndex( 5760 descriptor->SetEnumerationIndex(GetDetails(index).index());
5762 PropertyDetails(GetDetails(index)).index());
5763 } else { 5761 } else {
5764 descriptor->SetEnumerationIndex(enumeration_index); 5762 descriptor->SetEnumerationIndex(enumeration_index);
5765 ++enumeration_index; 5763 ++enumeration_index;
5766 } 5764 }
5767 } 5765 }
5768 new_descriptors->SetNextEnumerationIndex(enumeration_index); 5766 new_descriptors->SetNextEnumerationIndex(enumeration_index);
5769 5767
5770 // Copy the descriptors, filtering out transitions and null descriptors, 5768 // Copy the descriptors, filtering out transitions and null descriptors,
5771 // and inserting or replacing a descriptor. 5769 // and inserting or replacing a descriptor.
5772 int to_index = 0; 5770 int to_index = 0;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5896 continue; 5894 continue;
5897 } 5895 }
5898 if (mid_hash < hash) { 5896 if (mid_hash < hash) {
5899 low = mid + 1; 5897 low = mid + 1;
5900 continue; 5898 continue;
5901 } 5899 }
5902 // Found an element with the same hash-code. 5900 // Found an element with the same hash-code.
5903 ASSERT(hash == mid_hash); 5901 ASSERT(hash == mid_hash);
5904 // There might be more, so we find the first one and 5902 // There might be more, so we find the first one and
5905 // check them all to see if we have a match. 5903 // check them all to see if we have a match.
5906 if (name == mid_name && !is_null_descriptor(mid)) return mid; 5904 if (name == mid_name && !IsNullDescriptor(mid)) return mid;
5907 while ((mid > low) && (GetKey(mid - 1)->Hash() == hash)) mid--; 5905 while ((mid > low) && (GetKey(mid - 1)->Hash() == hash)) mid--;
5908 for (; (mid <= high) && (GetKey(mid)->Hash() == hash); mid++) { 5906 for (; (mid <= high) && (GetKey(mid)->Hash() == hash); mid++) {
5909 if (GetKey(mid)->Equals(name) && !is_null_descriptor(mid)) return mid; 5907 if (GetKey(mid)->Equals(name) && !IsNullDescriptor(mid)) return mid;
5910 } 5908 }
5911 break; 5909 break;
5912 } 5910 }
5913 return kNotFound; 5911 return kNotFound;
5914 } 5912 }
5915 5913
5916 5914
5917 int DescriptorArray::LinearSearch(String* name, int len) { 5915 int DescriptorArray::LinearSearch(String* name, int len) {
5918 uint32_t hash = name->Hash(); 5916 uint32_t hash = name->Hash();
5919 for (int number = 0; number < len; number++) { 5917 for (int number = 0; number < len; number++) {
5920 String* entry = GetKey(number); 5918 String* entry = GetKey(number);
5921 if ((entry->Hash() == hash) && 5919 if ((entry->Hash() == hash) &&
5922 name->Equals(entry) && 5920 name->Equals(entry) &&
5923 !is_null_descriptor(number)) { 5921 !IsNullDescriptor(number)) {
5924 return number; 5922 return number;
5925 } 5923 }
5926 } 5924 }
5927 return kNotFound; 5925 return kNotFound;
5928 } 5926 }
5929 5927
5930 5928
5931 MaybeObject* AccessorPair::CopyWithoutTransitions() { 5929 MaybeObject* AccessorPair::CopyWithoutTransitions() {
5932 Heap* heap = GetHeap(); 5930 Heap* heap = GetHeap();
5933 AccessorPair* copy; 5931 AccessorPair* copy;
(...skipping 7031 matching lines...) Expand 10 before | Expand all | Expand 10 after
12965 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 12963 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
12966 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 12964 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
12967 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 12965 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
12968 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 12966 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
12969 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 12967 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
12970 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 12968 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
12971 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 12969 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
12972 } 12970 }
12973 12971
12974 } } // namespace v8::internal 12972 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698