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 4870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4881 } else { | 4881 } else { |
4882 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); | 4882 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); |
4883 if (obj->IsFailure()) return obj; | 4883 if (obj->IsFailure()) return obj; |
4884 new_elements = FixedArray::cast(obj); | 4884 new_elements = FixedArray::cast(obj); |
4885 } | 4885 } |
4886 set_elements(new_elements); | 4886 set_elements(new_elements); |
4887 return this; | 4887 return this; |
4888 } | 4888 } |
4889 | 4889 |
4890 | 4890 |
| 4891 void JSArray::EnsureSize(int required_size) { |
| 4892 Handle<JSArray> self(this); |
| 4893 ASSERT(HasFastElements()); |
| 4894 if (elements()->length() >= required_size) return; |
| 4895 Handle<FixedArray> old_backing(elements()); |
| 4896 int old_size = old_backing->length(); |
| 4897 // Doubling in size would be overkill, but leave some slack to avoid |
| 4898 // constantly growing. |
| 4899 int new_size = required_size + (required_size >> 3); |
| 4900 Handle<FixedArray> new_backing = Factory::NewFixedArray(new_size); |
| 4901 // Can't use this any more now because we may have had a GC! |
| 4902 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i)); |
| 4903 self->SetContent(*new_backing); |
| 4904 } |
| 4905 |
| 4906 |
4891 // Computes the new capacity when expanding the elements of a JSObject. | 4907 // Computes the new capacity when expanding the elements of a JSObject. |
4892 static int NewElementsCapacity(int old_capacity) { | 4908 static int NewElementsCapacity(int old_capacity) { |
4893 // (old_capacity + 50%) + 16 | 4909 // (old_capacity + 50%) + 16 |
4894 return old_capacity + (old_capacity >> 1) + 16; | 4910 return old_capacity + (old_capacity >> 1) + 16; |
4895 } | 4911 } |
4896 | 4912 |
4897 | 4913 |
4898 static Object* ArrayLengthRangeError() { | 4914 static Object* ArrayLengthRangeError() { |
4899 HandleScope scope; | 4915 HandleScope scope; |
4900 return Top::Throw(*Factory::NewRangeError("invalid_array_length", | 4916 return Top::Throw(*Factory::NewRangeError("invalid_array_length", |
(...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7198 // No break point. | 7214 // No break point. |
7199 if (break_point_objects()->IsUndefined()) return 0; | 7215 if (break_point_objects()->IsUndefined()) return 0; |
7200 // Single beak point. | 7216 // Single beak point. |
7201 if (!break_point_objects()->IsFixedArray()) return 1; | 7217 if (!break_point_objects()->IsFixedArray()) return 1; |
7202 // Multiple break points. | 7218 // Multiple break points. |
7203 return FixedArray::cast(break_point_objects())->length(); | 7219 return FixedArray::cast(break_point_objects())->length(); |
7204 } | 7220 } |
7205 | 7221 |
7206 | 7222 |
7207 } } // namespace v8::internal | 7223 } } // namespace v8::internal |
OLD | NEW |