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

Side by Side Diff: src/objects.cc

Issue 40108: Put 'this' in a handle in EnsureSize to avoid crash caused by GC at... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4865 matching lines...) Expand 10 before | Expand all | Expand 10 after
4876 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); 4876 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity);
4877 if (obj->IsFailure()) return obj; 4877 if (obj->IsFailure()) return obj;
4878 new_elements = FixedArray::cast(obj); 4878 new_elements = FixedArray::cast(obj);
4879 } 4879 }
4880 set_elements(new_elements); 4880 set_elements(new_elements);
4881 return this; 4881 return this;
4882 } 4882 }
4883 4883
4884 4884
4885 void JSArray::EnsureSize(int required_size) { 4885 void JSArray::EnsureSize(int required_size) {
4886 Handle<JSArray> self(this);
4886 ASSERT(HasFastElements()); 4887 ASSERT(HasFastElements());
4887 if (elements()->length() >= required_size) return; 4888 if (elements()->length() >= required_size) return;
4888 Handle<FixedArray> old_backing(elements()); 4889 Handle<FixedArray> old_backing(elements());
4889 int old_size = old_backing->length(); 4890 int old_size = old_backing->length();
4890 // Doubling in size would be overkill, but leave some slack to avoid 4891 // Doubling in size would be overkill, but leave some slack to avoid
4891 // constantly growing. 4892 // constantly growing.
4892 int new_size = required_size + (required_size >> 3); 4893 int new_size = required_size + (required_size >> 3);
4893 Handle<FixedArray> new_backing = Factory::NewFixedArray(new_size); 4894 Handle<FixedArray> new_backing = Factory::NewFixedArray(new_size);
4895 // Can't use this any more now because we may have had a GC!
4894 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i)); 4896 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i));
4895 SetContent(*new_backing); 4897 self->SetContent(*new_backing);
4896 } 4898 }
4897 4899
4898 4900
4899 // Computes the new capacity when expanding the elements of a JSObject. 4901 // Computes the new capacity when expanding the elements of a JSObject.
4900 static int NewElementsCapacity(int old_capacity) { 4902 static int NewElementsCapacity(int old_capacity) {
4901 // (old_capacity + 50%) + 16 4903 // (old_capacity + 50%) + 16
4902 return old_capacity + (old_capacity >> 1) + 16; 4904 return old_capacity + (old_capacity >> 1) + 16;
4903 } 4905 }
4904 4906
4905 4907
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
7275 // No break point. 7277 // No break point.
7276 if (break_point_objects()->IsUndefined()) return 0; 7278 if (break_point_objects()->IsUndefined()) return 0;
7277 // Single beak point. 7279 // Single beak point.
7278 if (!break_point_objects()->IsFixedArray()) return 1; 7280 if (!break_point_objects()->IsFixedArray()) return 1;
7279 // Multiple break points. 7281 // Multiple break points.
7280 return FixedArray::cast(break_point_objects())->length(); 7282 return FixedArray::cast(break_point_objects())->length();
7281 } 7283 }
7282 7284
7283 7285
7284 } } // namespace v8::internal 7286 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698