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

Side by Side Diff: src/objects.cc

Issue 119357: Make Array.sort safely generic on JSObject types. Fix bug 346 http://code.go... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 6 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') | test/mjsunit/array-sort.js » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 6418 matching lines...) Expand 10 before | Expand all | Expand 10 after
6429 result_double = HeapNumber::cast(new_double); 6429 result_double = HeapNumber::cast(new_double);
6430 } 6430 }
6431 6431
6432 int capacity = dict->Capacity(); 6432 int capacity = dict->Capacity();
6433 Object* obj = Dictionary::Allocate(dict->Capacity()); 6433 Object* obj = Dictionary::Allocate(dict->Capacity());
6434 if (obj->IsFailure()) return obj; 6434 if (obj->IsFailure()) return obj;
6435 Dictionary* new_dict = Dictionary::cast(obj); 6435 Dictionary* new_dict = Dictionary::cast(obj);
6436 6436
6437 AssertNoAllocation no_alloc; 6437 AssertNoAllocation no_alloc;
6438 6438
6439 // Loose all details on properties when moving them around.
6440 // Elements do not have special details like properties.
6441 PropertyDetails no_details = PropertyDetails(NONE, NORMAL);
6442
6443 uint32_t pos = 0; 6439 uint32_t pos = 0;
6444 uint32_t undefs = 0; 6440 uint32_t undefs = 0;
6445 for (int i = 0; i < capacity; i++) { 6441 for (int i = 0; i < capacity; i++) {
6446 Object* k = dict->KeyAt(i); 6442 Object* k = dict->KeyAt(i);
6447 if (dict->IsKey(k)) { 6443 if (dict->IsKey(k)) {
6448 ASSERT(k->IsNumber()); 6444 ASSERT(k->IsNumber());
6449 ASSERT(!k->IsSmi() || Smi::cast(k)->value() >= 0); 6445 ASSERT(!k->IsSmi() || Smi::cast(k)->value() >= 0);
6450 ASSERT(!k->IsHeapNumber() || HeapNumber::cast(k)->value() >= 0); 6446 ASSERT(!k->IsHeapNumber() || HeapNumber::cast(k)->value() >= 0);
6451 ASSERT(!k->IsHeapNumber() || HeapNumber::cast(k)->value() <= kMaxUInt32); 6447 ASSERT(!k->IsHeapNumber() || HeapNumber::cast(k)->value() <= kMaxUInt32);
6452 Object* value = dict->ValueAt(i); 6448 Object* value = dict->ValueAt(i);
6449 PropertyDetails details = dict->DetailsAt(i);
6450 if (details.type() == CALLBACKS) {
6451 // Bail out and do the sorting of undefineds and array holes in JS.
6452 return Smi::FromInt(-1);
6453 }
6453 uint32_t key = NumberToUint32(k); 6454 uint32_t key = NumberToUint32(k);
6454 if (key < limit) { 6455 if (key < limit) {
6455 if (value->IsUndefined()) { 6456 if (value->IsUndefined()) {
6456 undefs++; 6457 undefs++;
6457 } else { 6458 } else {
6458 new_dict->AddNumberEntry(pos, value, no_details); 6459 new_dict->AddNumberEntry(pos, value, details);
6459 pos++; 6460 pos++;
6460 } 6461 }
6461 } else { 6462 } else {
6462 new_dict->AddNumberEntry(key, value, no_details); 6463 new_dict->AddNumberEntry(key, value, details);
6463 } 6464 }
6464 } 6465 }
6465 } 6466 }
6466 6467
6467 uint32_t result = pos; 6468 uint32_t result = pos;
6469 PropertyDetails no_details = PropertyDetails(NONE, NORMAL);
6468 while (undefs > 0) { 6470 while (undefs > 0) {
6469 new_dict->AddNumberEntry(pos, Heap::undefined_value(), no_details); 6471 new_dict->AddNumberEntry(pos, Heap::undefined_value(), no_details);
6470 pos++; 6472 pos++;
6471 undefs--; 6473 undefs--;
6472 } 6474 }
6473 6475
6474 set_elements(new_dict); 6476 set_elements(new_dict);
6475 6477
6476 if (result <= static_cast<uint32_t>(Smi::kMaxValue)) { 6478 if (result <= static_cast<uint32_t>(Smi::kMaxValue)) {
6477 return Smi::FromInt(static_cast<int>(result)); 6479 return Smi::FromInt(static_cast<int>(result));
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
7558 // No break point. 7560 // No break point.
7559 if (break_point_objects()->IsUndefined()) return 0; 7561 if (break_point_objects()->IsUndefined()) return 0;
7560 // Single beak point. 7562 // Single beak point.
7561 if (!break_point_objects()->IsFixedArray()) return 1; 7563 if (!break_point_objects()->IsFixedArray()) return 1;
7562 // Multiple break points. 7564 // Multiple break points.
7563 return FixedArray::cast(break_point_objects())->length(); 7565 return FixedArray::cast(break_point_objects())->length();
7564 } 7566 }
7565 #endif 7567 #endif
7566 7568
7567 } } // namespace v8::internal 7569 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/array-sort.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698