OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 | 1117 |
1118 | 1118 |
1119 Object* JSObject::ReplaceConstantFunctionProperty(String* name, | 1119 Object* JSObject::ReplaceConstantFunctionProperty(String* name, |
1120 Object* value) { | 1120 Object* value) { |
1121 // There are two situations to handle here: | 1121 // There are two situations to handle here: |
1122 // 1: Replace a constant function with another function. | 1122 // 1: Replace a constant function with another function. |
1123 // 2: Replace a constant function with an object. | 1123 // 2: Replace a constant function with an object. |
1124 if (value->IsJSFunction()) { | 1124 if (value->IsJSFunction()) { |
1125 JSFunction* function = JSFunction::cast(value); | 1125 JSFunction* function = JSFunction::cast(value); |
1126 | 1126 |
1127 Object* new_map = | 1127 Object* new_map = map()->CopyDropTransitions(); |
1128 map()->CopyDropTransitions(); | |
1129 if (new_map->IsFailure()) return new_map; | 1128 if (new_map->IsFailure()) return new_map; |
1130 set_map(Map::cast(new_map)); | 1129 set_map(Map::cast(new_map)); |
1131 | 1130 |
1132 // Replace the function entry | 1131 // Replace the function entry |
1133 int index = map()->instance_descriptors()->Search(name); | 1132 int index = map()->instance_descriptors()->Search(name); |
1134 ASSERT(index != DescriptorArray::kNotFound); | 1133 ASSERT(index != DescriptorArray::kNotFound); |
1135 map()->instance_descriptors()->ReplaceConstantFunction(index, function); | 1134 map()->instance_descriptors()->ReplaceConstantFunction(index, function); |
1136 } else { | 1135 } else { |
1137 // Allocate new instance descriptors with updated property index. | 1136 // Allocate new instance descriptors with updated property index. |
1138 int index = map()->NextFreePropertyIndex(); | 1137 int index = map()->NextFreePropertyIndex(); |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2639 if (r.IsNullDescriptor()) null_descriptors++; | 2638 if (r.IsNullDescriptor()) null_descriptors++; |
2640 } | 2639 } |
2641 } else { | 2640 } else { |
2642 for (DescriptorReader r(this); !r.eos(); r.advance()) { | 2641 for (DescriptorReader r(this); !r.eos(); r.advance()) { |
2643 if (r.IsNullDescriptor()) null_descriptors++; | 2642 if (r.IsNullDescriptor()) null_descriptors++; |
2644 } | 2643 } |
2645 } | 2644 } |
2646 int new_size = number_of_descriptors() - transitions - null_descriptors; | 2645 int new_size = number_of_descriptors() - transitions - null_descriptors; |
2647 | 2646 |
2648 // If key is in descriptor, we replace it in-place when filtering. | 2647 // If key is in descriptor, we replace it in-place when filtering. |
2649 int index = Search(descriptor->key()); | 2648 int index = Search(descriptor->GetKey()); |
2650 const bool inserting = (index == kNotFound); | 2649 const bool inserting = (index == kNotFound); |
2651 const bool replacing = !inserting; | 2650 const bool replacing = !inserting; |
2652 bool keep_enumeration_index = false; | 2651 bool keep_enumeration_index = false; |
2653 if (inserting) { | 2652 if (inserting) { |
2654 ++new_size; | 2653 ++new_size; |
2655 } | 2654 } |
2656 if (replacing) { | 2655 if (replacing) { |
2657 // We are replacing an existing descriptor. We keep the enumeration | 2656 // We are replacing an existing descriptor. We keep the enumeration |
2658 // index of a visible property. | 2657 // index of a visible property. |
2659 PropertyType t = PropertyDetails(GetDetails(index)).type(); | 2658 PropertyType t = PropertyDetails(GetDetails(index)).type(); |
(...skipping 22 matching lines...) Expand all Loading... |
2682 descriptor->SetEnumerationIndex(enumeration_index); | 2681 descriptor->SetEnumerationIndex(enumeration_index); |
2683 ++enumeration_index; | 2682 ++enumeration_index; |
2684 } | 2683 } |
2685 } | 2684 } |
2686 new_descriptors->SetNextEnumerationIndex(enumeration_index); | 2685 new_descriptors->SetNextEnumerationIndex(enumeration_index); |
2687 | 2686 |
2688 // Copy the descriptors, filtering out transitions and null descriptors, | 2687 // Copy the descriptors, filtering out transitions and null descriptors, |
2689 // and inserting or replacing a descriptor. | 2688 // and inserting or replacing a descriptor. |
2690 DescriptorWriter w(new_descriptors); | 2689 DescriptorWriter w(new_descriptors); |
2691 DescriptorReader r(this); | 2690 DescriptorReader r(this); |
2692 uint32_t descriptor_hash = descriptor->key()->Hash(); | 2691 uint32_t descriptor_hash = descriptor->GetKey()->Hash(); |
2693 | 2692 |
2694 for (; !r.eos(); r.advance()) { | 2693 for (; !r.eos(); r.advance()) { |
2695 if (r.GetKey()->Hash() > descriptor_hash || | 2694 if (r.GetKey()->Hash() > descriptor_hash || |
2696 r.GetKey() == descriptor->GetKey()) break; | 2695 r.GetKey() == descriptor->GetKey()) break; |
2697 if (r.IsNullDescriptor()) continue; | 2696 if (r.IsNullDescriptor()) continue; |
2698 if (remove_transitions && r.IsTransition()) continue; | 2697 if (remove_transitions && r.IsTransition()) continue; |
2699 w.WriteFrom(&r); | 2698 w.WriteFrom(&r); |
2700 } | 2699 } |
2701 w.Write(descriptor); | 2700 w.Write(descriptor); |
2702 if (replacing) { | 2701 if (replacing) { |
(...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5378 } | 5377 } |
5379 | 5378 |
5380 bool IsMatch(Object* other) { | 5379 bool IsMatch(Object* other) { |
5381 if (!other->IsString()) return false; | 5380 if (!other->IsString()) return false; |
5382 return String::cast(other)->Equals(string_); | 5381 return String::cast(other)->Equals(string_); |
5383 } | 5382 } |
5384 | 5383 |
5385 uint32_t Hash() { return string_->Hash(); } | 5384 uint32_t Hash() { return string_->Hash(); } |
5386 | 5385 |
5387 Object* GetObject() { | 5386 Object* GetObject() { |
| 5387 // If the string is a cons string, attempt to flatten it so that |
| 5388 // symbols will most often be flat strings. |
| 5389 if (string_->IsConsString()) { |
| 5390 ConsString* cons_string = ConsString::cast(string_); |
| 5391 cons_string->TryFlatten(); |
| 5392 if (cons_string->second() == Heap::empty_string()) { |
| 5393 string_ = String::cast(cons_string->first()); |
| 5394 } |
| 5395 } |
5388 // Transform string to symbol if possible. | 5396 // Transform string to symbol if possible. |
5389 Map* map = Heap::SymbolMapForString(string_); | 5397 Map* map = Heap::SymbolMapForString(string_); |
5390 if (map != NULL) { | 5398 if (map != NULL) { |
5391 string_->set_map(map); | 5399 string_->set_map(map); |
5392 return string_; | 5400 return string_; |
5393 } | 5401 } |
5394 // Otherwise allocate a new symbol. | 5402 // Otherwise allocate a new symbol. |
5395 StringInputBuffer buffer(string_); | 5403 StringInputBuffer buffer(string_); |
5396 return Heap::AllocateSymbol(&buffer, string_->length(), string_->Hash()); | 5404 return Heap::AllocateSymbol(&buffer, string_->length(), string_->Hash()); |
5397 } | 5405 } |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6252 // No break point. | 6260 // No break point. |
6253 if (break_point_objects()->IsUndefined()) return 0; | 6261 if (break_point_objects()->IsUndefined()) return 0; |
6254 // Single beak point. | 6262 // Single beak point. |
6255 if (!break_point_objects()->IsFixedArray()) return 1; | 6263 if (!break_point_objects()->IsFixedArray()) return 1; |
6256 // Multiple break points. | 6264 // Multiple break points. |
6257 return FixedArray::cast(break_point_objects())->length(); | 6265 return FixedArray::cast(break_point_objects())->length(); |
6258 } | 6266 } |
6259 | 6267 |
6260 | 6268 |
6261 } } // namespace v8::internal | 6269 } } // namespace v8::internal |
OLD | NEW |