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

Side by Side Diff: src/elements.cc

Issue 1172683003: Use the LookupIterator for SetElement and friends (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 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
« no previous file with comments | « src/elements.h ('k') | src/harmony-array.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/elements.h" 9 #include "src/elements.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 611
612 static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key, 612 static Handle<Object> GetImpl(Handle<JSObject> obj, uint32_t key,
613 Handle<FixedArrayBase> backing_store) { 613 Handle<FixedArrayBase> backing_store) {
614 if (key < ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) { 614 if (key < ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) {
615 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); 615 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
616 } else { 616 } else {
617 return backing_store->GetIsolate()->factory()->the_hole_value(); 617 return backing_store->GetIsolate()->factory()->the_hole_value();
618 } 618 }
619 } 619 }
620 620
621 virtual Handle<Object> Set(Handle<JSObject> holder, uint32_t key,
622 Handle<FixedArrayBase> backing_store,
623 Handle<Object> value) final {
624 return ElementsAccessorSubclass::SetImpl(holder, key, backing_store, value);
625 }
626
627 static Handle<Object> SetImpl(Handle<JSObject> obj, uint32_t key,
628 Handle<FixedArrayBase> backing_store,
629 Handle<Object> value) {
630 CHECK(key <
631 ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store));
632 return BackingStore::SetValue(
633 obj, Handle<BackingStore>::cast(backing_store), key, value);
634 }
635
621 virtual PropertyAttributes GetAttributes( 636 virtual PropertyAttributes GetAttributes(
622 JSObject* holder, uint32_t key, FixedArrayBase* backing_store) final { 637 JSObject* holder, uint32_t key, FixedArrayBase* backing_store) final {
623 return ElementsAccessorSubclass::GetAttributesImpl(holder, key, 638 return ElementsAccessorSubclass::GetAttributesImpl(holder, key,
624 backing_store); 639 backing_store);
625 } 640 }
626 641
627 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key, 642 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key,
628 FixedArrayBase* backing_store) { 643 FixedArrayBase* backing_store) {
629 if (key >= ElementsAccessorSubclass::GetCapacityImpl(obj, backing_store)) { 644 if (key >= ElementsAccessorSubclass::GetCapacityImpl(obj, backing_store)) {
630 return ABSENT; 645 return ABSENT;
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 Handle<FixedArrayBase> backing_store) { 1288 Handle<FixedArrayBase> backing_store) {
1274 if (key < AccessorClass::GetCapacityImpl(*obj, *backing_store)) { 1289 if (key < AccessorClass::GetCapacityImpl(*obj, *backing_store)) {
1275 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); 1290 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
1276 } else { 1291 } else {
1277 return backing_store->GetIsolate()->factory()->undefined_value(); 1292 return backing_store->GetIsolate()->factory()->undefined_value();
1278 } 1293 }
1279 } 1294 }
1280 1295
1281 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key, 1296 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key,
1282 FixedArrayBase* backing_store) { 1297 FixedArrayBase* backing_store) {
1283 return key < AccessorClass::GetCapacityImpl(obj, backing_store) ? NONE 1298 return key < AccessorClass::GetCapacityImpl(obj, backing_store)
1284 : ABSENT; 1299 ? DONT_DELETE
1300 : ABSENT;
1301 }
1302
1303 static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
1304 uint32_t index) {
1305 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell);
1285 } 1306 }
1286 1307
1287 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1308 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1288 Handle<JSObject> obj, 1309 Handle<JSObject> obj,
1289 Handle<Object> length, 1310 Handle<Object> length,
1290 Handle<FixedArrayBase> backing_store) { 1311 Handle<FixedArrayBase> backing_store) {
1291 // External arrays do not support changing their length. 1312 // External arrays do not support changing their length.
1292 UNREACHABLE(); 1313 UNREACHABLE();
1293 return obj; 1314 return obj;
1294 } 1315 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 Handle<SeededNumberDictionary> backing_store = 1467 Handle<SeededNumberDictionary> backing_store =
1447 Handle<SeededNumberDictionary>::cast(store); 1468 Handle<SeededNumberDictionary>::cast(store);
1448 Isolate* isolate = backing_store->GetIsolate(); 1469 Isolate* isolate = backing_store->GetIsolate();
1449 int entry = backing_store->FindEntry(key); 1470 int entry = backing_store->FindEntry(key);
1450 if (entry != SeededNumberDictionary::kNotFound) { 1471 if (entry != SeededNumberDictionary::kNotFound) {
1451 return handle(backing_store->ValueAt(entry), isolate); 1472 return handle(backing_store->ValueAt(entry), isolate);
1452 } 1473 }
1453 return isolate->factory()->the_hole_value(); 1474 return isolate->factory()->the_hole_value();
1454 } 1475 }
1455 1476
1477 static Handle<Object> SetImpl(Handle<JSObject> obj, uint32_t key,
1478 Handle<FixedArrayBase> store,
1479 Handle<Object> value) {
1480 Handle<SeededNumberDictionary> backing_store =
1481 Handle<SeededNumberDictionary>::cast(store);
1482 int entry = backing_store->FindEntry(key);
1483 DCHECK_NE(SeededNumberDictionary::kNotFound, entry);
1484 backing_store->ValueAtPut(entry, *value);
1485 return value;
1486 }
1487
1456 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key, 1488 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key,
1457 FixedArrayBase* backing_store) { 1489 FixedArrayBase* backing_store) {
1458 SeededNumberDictionary* dictionary = 1490 SeededNumberDictionary* dictionary =
1459 SeededNumberDictionary::cast(backing_store); 1491 SeededNumberDictionary::cast(backing_store);
1460 int entry = dictionary->FindEntry(key); 1492 int entry = dictionary->FindEntry(key);
1461 if (entry != SeededNumberDictionary::kNotFound) { 1493 if (entry != SeededNumberDictionary::kNotFound) {
1462 return dictionary->DetailsAt(entry).attributes(); 1494 return dictionary->DetailsAt(entry).attributes();
1463 } 1495 }
1464 return ABSENT; 1496 return ABSENT;
1465 } 1497 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 Context* context = Context::cast(parameter_map->get(0)); 1584 Context* context = Context::cast(parameter_map->get(0));
1553 int context_index = entry->aliased_context_slot(); 1585 int context_index = entry->aliased_context_slot();
1554 DCHECK(!context->get(context_index)->IsTheHole()); 1586 DCHECK(!context->get(context_index)->IsTheHole());
1555 return handle(context->get(context_index), isolate); 1587 return handle(context->get(context_index), isolate);
1556 } else { 1588 } else {
1557 return result; 1589 return result;
1558 } 1590 }
1559 } 1591 }
1560 } 1592 }
1561 1593
1594 static Handle<Object> SetImpl(Handle<JSObject> obj, uint32_t key,
1595 Handle<FixedArrayBase> store,
1596 Handle<Object> value) {
1597 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(store);
1598 Object* probe = GetParameterMapArg(*parameter_map, key);
1599 if (!probe->IsTheHole()) {
1600 Context* context = Context::cast(parameter_map->get(0));
1601 int context_index = Smi::cast(probe)->value();
1602 DCHECK(!context->get(context_index)->IsTheHole());
1603 context->set(context_index, *value);
1604 return value;
1605 }
1606 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1607 return ElementsAccessor::ForArray(arguments)
1608 ->Set(obj, key, arguments, value);
1609 }
1610
1562 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key, 1611 static PropertyAttributes GetAttributesImpl(JSObject* obj, uint32_t key,
1563 FixedArrayBase* backing_store) { 1612 FixedArrayBase* backing_store) {
1564 FixedArray* parameter_map = FixedArray::cast(backing_store); 1613 FixedArray* parameter_map = FixedArray::cast(backing_store);
1565 Object* probe = GetParameterMapArg(parameter_map, key); 1614 Object* probe = GetParameterMapArg(parameter_map, key);
1566 if (!probe->IsTheHole()) { 1615 if (!probe->IsTheHole()) {
1567 return NONE; 1616 return NONE;
1568 } else { 1617 } else {
1569 // If not aliased, check the arguments. 1618 // If not aliased, check the arguments.
1570 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); 1619 FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
1571 return ElementsAccessor::ForArray(arguments) 1620 return ElementsAccessor::ForArray(arguments)
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 break; 1929 break;
1881 } 1930 }
1882 1931
1883 array->set_elements(*elms); 1932 array->set_elements(*elms);
1884 array->set_length(Smi::FromInt(number_of_elements)); 1933 array->set_length(Smi::FromInt(number_of_elements));
1885 return array; 1934 return array;
1886 } 1935 }
1887 1936
1888 } // namespace internal 1937 } // namespace internal
1889 } // namespace v8 1938 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/harmony-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698