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

Side by Side Diff: src/elements.cc

Issue 228333003: Handlefy Descriptor and other code in objects.cc (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Last comments. Created 6 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
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 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 class DictionaryElementsAccessor 1451 class DictionaryElementsAccessor
1452 : public ElementsAccessorBase<DictionaryElementsAccessor, 1452 : public ElementsAccessorBase<DictionaryElementsAccessor,
1453 ElementsKindTraits<DICTIONARY_ELEMENTS> > { 1453 ElementsKindTraits<DICTIONARY_ELEMENTS> > {
1454 public: 1454 public:
1455 explicit DictionaryElementsAccessor(const char* name) 1455 explicit DictionaryElementsAccessor(const char* name)
1456 : ElementsAccessorBase<DictionaryElementsAccessor, 1456 : ElementsAccessorBase<DictionaryElementsAccessor,
1457 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} 1457 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
1458 1458
1459 // Adjusts the length of the dictionary backing store and returns the new 1459 // Adjusts the length of the dictionary backing store and returns the new
1460 // length according to ES5 section 15.4.5.2 behavior. 1460 // length according to ES5 section 15.4.5.2 behavior.
1461 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( 1461 MUST_USE_RESULT static Handle<Object> SetLengthWithoutNormalize(
Toon Verwaest 2014/04/09 13:49:24 Remove MUST_USE_RESULT
mvstanton 2014/04/09 14:26:06 Done.
1462 FixedArrayBase* store, 1462 Handle<FixedArrayBase> store,
1463 JSArray* array, 1463 Handle<JSArray> array,
1464 Object* length_object, 1464 Handle<Object> length_object,
1465 uint32_t length) { 1465 uint32_t length) {
1466 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); 1466 Handle<SeededNumberDictionary> dict =
1467 Heap* heap = array->GetHeap(); 1467 Handle<SeededNumberDictionary>::cast(store);
1468 Isolate* isolate = array->GetIsolate();
1468 int capacity = dict->Capacity(); 1469 int capacity = dict->Capacity();
1469 uint32_t new_length = length; 1470 uint32_t new_length = length;
1470 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); 1471 uint32_t old_length = static_cast<uint32_t>(array->length()->Number());
1471 if (new_length < old_length) { 1472 if (new_length < old_length) {
1472 // Find last non-deletable element in range of elements to be 1473 // Find last non-deletable element in range of elements to be
1473 // deleted and adjust range accordingly. 1474 // deleted and adjust range accordingly.
1474 for (int i = 0; i < capacity; i++) { 1475 for (int i = 0; i < capacity; i++) {
1476 DisallowHeapAllocation no_gc;
1475 Object* key = dict->KeyAt(i); 1477 Object* key = dict->KeyAt(i);
1476 if (key->IsNumber()) { 1478 if (key->IsNumber()) {
1477 uint32_t number = static_cast<uint32_t>(key->Number()); 1479 uint32_t number = static_cast<uint32_t>(key->Number());
1478 if (new_length <= number && number < old_length) { 1480 if (new_length <= number && number < old_length) {
1479 PropertyDetails details = dict->DetailsAt(i); 1481 PropertyDetails details = dict->DetailsAt(i);
1480 if (details.IsDontDelete()) new_length = number + 1; 1482 if (details.IsDontDelete()) new_length = number + 1;
1481 } 1483 }
1482 } 1484 }
1483 } 1485 }
1484 if (new_length != length) { 1486 if (new_length != length) {
1485 MaybeObject* maybe_object = heap->NumberFromUint32(new_length); 1487 length_object = isolate->factory()->NewNumberFromUint(new_length);
1486 if (!maybe_object->To(&length_object)) return maybe_object;
1487 } 1488 }
1488 } 1489 }
1489 1490
1490 if (new_length == 0) { 1491 if (new_length == 0) {
1491 // If the length of a slow array is reset to zero, we clear 1492 // If the length of a slow array is reset to zero, we clear
1492 // the array and flush backing storage. This has the added 1493 // the array and flush backing storage. This has the added
1493 // benefit that the array returns to fast mode. 1494 // benefit that the array returns to fast mode.
1494 Object* obj; 1495 JSObject::ResetElements(array);
1495 MaybeObject* maybe_obj = array->ResetElements();
1496 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1497 } else { 1496 } else {
1497 DisallowHeapAllocation no_gc;
1498 // Remove elements that should be deleted. 1498 // Remove elements that should be deleted.
1499 int removed_entries = 0; 1499 int removed_entries = 0;
1500 Object* the_hole_value = heap->the_hole_value(); 1500 Object* the_hole_value = isolate->heap()->the_hole_value();
1501 for (int i = 0; i < capacity; i++) { 1501 for (int i = 0; i < capacity; i++) {
1502 Object* key = dict->KeyAt(i); 1502 Object* key = dict->KeyAt(i);
1503 if (key->IsNumber()) { 1503 if (key->IsNumber()) {
1504 uint32_t number = static_cast<uint32_t>(key->Number()); 1504 uint32_t number = static_cast<uint32_t>(key->Number());
1505 if (new_length <= number && number < old_length) { 1505 if (new_length <= number && number < old_length) {
1506 dict->SetEntry(i, the_hole_value, the_hole_value); 1506 dict->SetEntry(i, the_hole_value, the_hole_value);
1507 removed_entries++; 1507 removed_entries++;
1508 } 1508 }
1509 } 1509 }
1510 } 1510 }
1511 1511
1512 // Update the number of elements. 1512 // Update the number of elements.
1513 dict->ElementsRemoved(removed_entries); 1513 dict->ElementsRemoved(removed_entries);
1514 } 1514 }
1515 return length_object; 1515 return length_object;
1516 } 1516 }
1517 1517
1518 // TODO(ishell): Temporary wrapper until handlified.
1519 MUST_USE_RESULT static Handle<Object> SetLengthWithoutNormalize(
1520 Handle<FixedArrayBase> store,
1521 Handle<JSArray> array,
1522 Handle<Object> length_object,
1523 uint32_t length) {
1524 CALL_HEAP_FUNCTION(array->GetIsolate(),
1525 SetLengthWithoutNormalize(
1526 *store, *array, *length_object, length),
1527 Object);
1528 }
1529
1530 MUST_USE_RESULT static MaybeObject* DeleteCommon( 1518 MUST_USE_RESULT static MaybeObject* DeleteCommon(
1531 JSObject* obj, 1519 JSObject* obj,
1532 uint32_t key, 1520 uint32_t key,
1533 JSReceiver::DeleteMode mode) { 1521 JSReceiver::DeleteMode mode) {
1534 Isolate* isolate = obj->GetIsolate(); 1522 Isolate* isolate = obj->GetIsolate();
1535 Heap* heap = isolate->heap(); 1523 Heap* heap = isolate->heap();
1536 FixedArray* backing_store = FixedArray::cast(obj->elements()); 1524 FixedArray* backing_store = FixedArray::cast(obj->elements());
1537 bool is_arguments = 1525 bool is_arguments =
1538 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1526 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1539 if (is_arguments) { 1527 if (is_arguments) {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 UNREACHABLE(); 2052 UNREACHABLE();
2065 break; 2053 break;
2066 } 2054 }
2067 2055
2068 array->set_elements(*elms); 2056 array->set_elements(*elms);
2069 array->set_length(Smi::FromInt(number_of_elements)); 2057 array->set_length(Smi::FromInt(number_of_elements));
2070 return array; 2058 return array;
2071 } 2059 }
2072 2060
2073 } } // namespace v8::internal 2061 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/factory.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698