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

Side by Side Diff: src/elements.cc

Issue 230733003: ElementsAccessor::Delete() maybehandlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « src/elements.h ('k') | src/objects.h » ('j') | src/objects.cc » ('J')
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 // 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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 SetFastElementsCapacityAndLength(array, capacity, length); 747 SetFastElementsCapacityAndLength(array, capacity, length);
748 } 748 }
749 749
750 static void SetFastElementsCapacityAndLength( 750 static void SetFastElementsCapacityAndLength(
751 Handle<JSObject> obj, 751 Handle<JSObject> obj,
752 int capacity, 752 int capacity,
753 int length) { 753 int length) {
754 UNIMPLEMENTED(); 754 UNIMPLEMENTED();
755 } 755 }
756 756
757 MUST_USE_RESULT virtual Handle<Object> Delete( 757 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
758 Handle<JSObject> obj, 758 Handle<JSObject> obj,
759 uint32_t key, 759 uint32_t key,
760 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0; 760 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0;
761 761
762 static void CopyElementsImpl(Handle<FixedArrayBase> from, 762 static void CopyElementsImpl(Handle<FixedArrayBase> from,
763 uint32_t from_start, 763 uint32_t from_start,
764 Handle<FixedArrayBase> to, 764 Handle<FixedArrayBase> to,
765 ElementsKind from_kind, 765 ElementsKind from_kind,
766 uint32_t to_start, 766 uint32_t to_start,
767 int packed_size, 767 int packed_size,
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (4 * num_used > backing_store->length()) break; 1031 if (4 * num_used > backing_store->length()) break;
1032 } 1032 }
1033 if (4 * num_used <= backing_store->length()) { 1033 if (4 * num_used <= backing_store->length()) {
1034 JSObject::NormalizeElements(obj); 1034 JSObject::NormalizeElements(obj);
1035 } 1035 }
1036 } 1036 }
1037 } 1037 }
1038 return isolate->factory()->true_value(); 1038 return isolate->factory()->true_value();
1039 } 1039 }
1040 1040
1041 virtual Handle<Object> Delete( 1041 virtual MaybeHandle<Object> Delete(
1042 Handle<JSObject> obj, 1042 Handle<JSObject> obj,
1043 uint32_t key, 1043 uint32_t key,
1044 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1044 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1045 return DeleteCommon(obj, key, mode); 1045 return DeleteCommon(obj, key, mode);
1046 } 1046 }
1047 1047
1048 static bool HasElementImpl( 1048 static bool HasElementImpl(
1049 Handle<Object> receiver, 1049 Handle<Object> receiver,
1050 Handle<JSObject> holder, 1050 Handle<JSObject> holder,
1051 uint32_t key, 1051 uint32_t key,
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 1366
1367 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1367 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1368 Handle<JSObject> obj, 1368 Handle<JSObject> obj,
1369 Handle<Object> length, 1369 Handle<Object> length,
1370 Handle<FixedArrayBase> backing_store) { 1370 Handle<FixedArrayBase> backing_store) {
1371 // External arrays do not support changing their length. 1371 // External arrays do not support changing their length.
1372 UNREACHABLE(); 1372 UNREACHABLE();
1373 return obj; 1373 return obj;
1374 } 1374 }
1375 1375
1376 MUST_USE_RESULT virtual Handle<Object> Delete( 1376 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1377 Handle<JSObject> obj, 1377 Handle<JSObject> obj,
1378 uint32_t key, 1378 uint32_t key,
1379 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1379 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1380 // External arrays always ignore deletes. 1380 // External arrays always ignore deletes.
1381 return obj->GetIsolate()->factory()->true_value(); 1381 return obj->GetIsolate()->factory()->true_value();
1382 } 1382 }
1383 1383
1384 static bool HasElementImpl(Handle<Object> receiver, 1384 static bool HasElementImpl(Handle<Object> receiver,
1385 Handle<JSObject> holder, 1385 Handle<JSObject> holder,
1386 uint32_t key, 1386 uint32_t key,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 Handle<FixedArrayBase> store, 1481 Handle<FixedArrayBase> store,
1482 Handle<JSArray> array, 1482 Handle<JSArray> array,
1483 Handle<Object> length_object, 1483 Handle<Object> length_object,
1484 uint32_t length) { 1484 uint32_t length) {
1485 CALL_HEAP_FUNCTION(array->GetIsolate(), 1485 CALL_HEAP_FUNCTION(array->GetIsolate(),
1486 SetLengthWithoutNormalize( 1486 SetLengthWithoutNormalize(
1487 *store, *array, *length_object, length), 1487 *store, *array, *length_object, length),
1488 Object); 1488 Object);
1489 } 1489 }
1490 1490
1491 MUST_USE_RESULT static MaybeObject* DeleteCommon( 1491 MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon(
1492 JSObject* obj, 1492 Handle<JSObject> obj,
1493 uint32_t key, 1493 uint32_t key,
1494 JSReceiver::DeleteMode mode) { 1494 JSReceiver::DeleteMode mode) {
1495 Isolate* isolate = obj->GetIsolate(); 1495 Isolate* isolate = obj->GetIsolate();
1496 Heap* heap = isolate->heap(); 1496 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
1497 FixedArray* backing_store = FixedArray::cast(obj->elements()); 1497 isolate);
1498 bool is_arguments = 1498 bool is_arguments =
1499 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1499 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1500 if (is_arguments) { 1500 if (is_arguments) {
1501 backing_store = FixedArray::cast(backing_store->get(1)); 1501 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
1502 } 1502 }
1503 SeededNumberDictionary* dictionary = 1503 Handle<SeededNumberDictionary> dictionary =
1504 SeededNumberDictionary::cast(backing_store); 1504 Handle<SeededNumberDictionary>::cast(backing_store);
1505 int entry = dictionary->FindEntry(key); 1505 int entry = dictionary->FindEntry(key);
1506 if (entry != SeededNumberDictionary::kNotFound) { 1506 if (entry != SeededNumberDictionary::kNotFound) {
1507 Object* result = dictionary->DeleteProperty(entry, mode); 1507 Handle<Object> result =
1508 if (result == heap->false_value()) { 1508 SeededNumberDictionary::DeleteProperty(dictionary, entry, mode);
1509 if (*result == *isolate->factory()->false_value()) {
1509 if (mode == JSObject::STRICT_DELETION) { 1510 if (mode == JSObject::STRICT_DELETION) {
1510 // Deleting a non-configurable property in strict mode. 1511 // Deleting a non-configurable property in strict mode.
1511 HandleScope scope(isolate);
1512 Handle<Object> holder(obj, isolate);
1513 Handle<Object> name = isolate->factory()->NewNumberFromUint(key); 1512 Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
1514 Handle<Object> args[2] = { name, holder }; 1513 Handle<Object> args[2] = { name, obj };
1515 Handle<Object> error = 1514 Handle<Object> error =
1516 isolate->factory()->NewTypeError("strict_delete_property", 1515 isolate->factory()->NewTypeError("strict_delete_property",
1517 HandleVector(args, 2)); 1516 HandleVector(args, 2));
1518 return isolate->Throw(*error); 1517 return isolate->Throw<Object>(error);
1519 } 1518 }
1520 return heap->false_value(); 1519 return isolate->factory()->false_value();
1521 } 1520 }
1522 MaybeObject* maybe_elements = dictionary->Shrink(key); 1521 Handle<FixedArray> new_elements =
1523 FixedArray* new_elements = NULL; 1522 SeededNumberDictionary::Shrink(dictionary, key);
1524 if (!maybe_elements->To(&new_elements)) { 1523
1525 return maybe_elements;
1526 }
1527 if (is_arguments) { 1524 if (is_arguments) {
1528 FixedArray::cast(obj->elements())->set(1, new_elements); 1525 FixedArray::cast(obj->elements())->set(1, *new_elements);
1529 } else { 1526 } else {
1530 obj->set_elements(new_elements); 1527 obj->set_elements(*new_elements);
1531 } 1528 }
1532 } 1529 }
1533 return heap->true_value(); 1530 return isolate->factory()->true_value();
1534 }
1535
1536 // TODO(ishell): Temporary wrapper until handlified.
1537 MUST_USE_RESULT static Handle<Object> DeleteCommon(
1538 Handle<JSObject> obj,
1539 uint32_t key,
1540 JSReceiver::DeleteMode mode) {
1541 CALL_HEAP_FUNCTION(obj->GetIsolate(),
1542 DeleteCommon(*obj, key, mode),
1543 Object);
1544 } 1531 }
1545 1532
1546 static void CopyElementsImpl(Handle<FixedArrayBase> from, 1533 static void CopyElementsImpl(Handle<FixedArrayBase> from,
1547 uint32_t from_start, 1534 uint32_t from_start,
1548 Handle<FixedArrayBase> to, 1535 Handle<FixedArrayBase> to,
1549 ElementsKind from_kind, 1536 ElementsKind from_kind,
1550 uint32_t to_start, 1537 uint32_t to_start,
1551 int packed_size, 1538 int packed_size,
1552 int copy_size) { 1539 int copy_size) {
1553 UNREACHABLE(); 1540 UNREACHABLE();
1554 } 1541 }
1555 1542
1556 1543
1557 protected: 1544 protected:
1558 friend class ElementsAccessorBase<DictionaryElementsAccessor, 1545 friend class ElementsAccessorBase<DictionaryElementsAccessor,
1559 ElementsKindTraits<DICTIONARY_ELEMENTS> >; 1546 ElementsKindTraits<DICTIONARY_ELEMENTS> >;
1560 1547
1561 MUST_USE_RESULT virtual Handle<Object> Delete( 1548 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1562 Handle<JSObject> obj, 1549 Handle<JSObject> obj,
1563 uint32_t key, 1550 uint32_t key,
1564 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1551 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1565 return DeleteCommon(obj, key, mode); 1552 return DeleteCommon(obj, key, mode);
1566 } 1553 }
1567 1554
1568 static Handle<Object> GetImpl( 1555 static Handle<Object> GetImpl(
1569 Handle<Object> receiver, 1556 Handle<Object> receiver,
1570 Handle<JSObject> obj, 1557 Handle<JSObject> obj,
1571 uint32_t key, 1558 uint32_t key,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1739 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1753 Handle<JSObject> obj, 1740 Handle<JSObject> obj,
1754 Handle<Object> length, 1741 Handle<Object> length,
1755 Handle<FixedArrayBase> parameter_map) { 1742 Handle<FixedArrayBase> parameter_map) {
1756 // TODO(mstarzinger): This was never implemented but will be used once we 1743 // TODO(mstarzinger): This was never implemented but will be used once we
1757 // correctly implement [[DefineOwnProperty]] on arrays. 1744 // correctly implement [[DefineOwnProperty]] on arrays.
1758 UNIMPLEMENTED(); 1745 UNIMPLEMENTED();
1759 return obj; 1746 return obj;
1760 } 1747 }
1761 1748
1762 MUST_USE_RESULT virtual Handle<Object> Delete( 1749 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1763 Handle<JSObject> obj, 1750 Handle<JSObject> obj,
1764 uint32_t key, 1751 uint32_t key,
1765 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1752 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1766 Isolate* isolate = obj->GetIsolate(); 1753 Isolate* isolate = obj->GetIsolate();
1767 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements())); 1754 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
1768 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key); 1755 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1769 if (!probe->IsTheHole()) { 1756 if (!probe->IsTheHole()) {
1770 // TODO(kmillikin): We could check if this was the last aliased 1757 // TODO(kmillikin): We could check if this was the last aliased
1771 // parameter, and revert to normal elements in that case. That 1758 // parameter, and revert to normal elements in that case. That
1772 // would enable GC of the context. 1759 // would enable GC of the context.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 UNREACHABLE(); 2007 UNREACHABLE();
2021 break; 2008 break;
2022 } 2009 }
2023 2010
2024 array->set_elements(*elms); 2011 array->set_elements(*elms);
2025 array->set_length(Smi::FromInt(number_of_elements)); 2012 array->set_length(Smi::FromInt(number_of_elements));
2026 return array; 2013 return array;
2027 } 2014 }
2028 2015
2029 } } // namespace v8::internal 2016 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698