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

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: Rebasing on r20629 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') | 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 // 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 } 1469 }
1470 } 1470 }
1471 } 1471 }
1472 1472
1473 // Update the number of elements. 1473 // Update the number of elements.
1474 dict->ElementsRemoved(removed_entries); 1474 dict->ElementsRemoved(removed_entries);
1475 } 1475 }
1476 return length_object; 1476 return length_object;
1477 } 1477 }
1478 1478
1479 MUST_USE_RESULT static MaybeObject* DeleteCommon( 1479 MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon(
1480 JSObject* obj, 1480 Handle<JSObject> obj,
1481 uint32_t key, 1481 uint32_t key,
1482 JSReceiver::DeleteMode mode) { 1482 JSReceiver::DeleteMode mode) {
1483 Isolate* isolate = obj->GetIsolate(); 1483 Isolate* isolate = obj->GetIsolate();
1484 Heap* heap = isolate->heap(); 1484 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
1485 FixedArray* backing_store = FixedArray::cast(obj->elements()); 1485 isolate);
1486 bool is_arguments = 1486 bool is_arguments =
1487 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1487 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1488 if (is_arguments) { 1488 if (is_arguments) {
1489 backing_store = FixedArray::cast(backing_store->get(1)); 1489 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
1490 } 1490 }
1491 SeededNumberDictionary* dictionary = 1491 Handle<SeededNumberDictionary> dictionary =
1492 SeededNumberDictionary::cast(backing_store); 1492 Handle<SeededNumberDictionary>::cast(backing_store);
1493 int entry = dictionary->FindEntry(key); 1493 int entry = dictionary->FindEntry(key);
1494 if (entry != SeededNumberDictionary::kNotFound) { 1494 if (entry != SeededNumberDictionary::kNotFound) {
1495 Object* result = dictionary->DeleteProperty(entry, mode); 1495 Handle<Object> result =
1496 if (result == heap->false_value()) { 1496 SeededNumberDictionary::DeleteProperty(dictionary, entry, mode);
1497 if (*result == *isolate->factory()->false_value()) {
1497 if (mode == JSObject::STRICT_DELETION) { 1498 if (mode == JSObject::STRICT_DELETION) {
1498 // Deleting a non-configurable property in strict mode. 1499 // Deleting a non-configurable property in strict mode.
1499 HandleScope scope(isolate);
1500 Handle<Object> holder(obj, isolate);
1501 Handle<Object> name = isolate->factory()->NewNumberFromUint(key); 1500 Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
1502 Handle<Object> args[2] = { name, holder }; 1501 Handle<Object> args[2] = { name, obj };
1503 Handle<Object> error = 1502 Handle<Object> error =
1504 isolate->factory()->NewTypeError("strict_delete_property", 1503 isolate->factory()->NewTypeError("strict_delete_property",
1505 HandleVector(args, 2)); 1504 HandleVector(args, 2));
1506 return isolate->Throw(*error); 1505 return isolate->Throw<Object>(error);
1507 } 1506 }
1508 return heap->false_value(); 1507 return isolate->factory()->false_value();
1509 } 1508 }
1510 MaybeObject* maybe_elements = dictionary->Shrink(key); 1509 Handle<FixedArray> new_elements =
1511 FixedArray* new_elements = NULL; 1510 SeededNumberDictionary::Shrink(dictionary, key);
1512 if (!maybe_elements->To(&new_elements)) { 1511
1513 return maybe_elements;
1514 }
1515 if (is_arguments) { 1512 if (is_arguments) {
1516 FixedArray::cast(obj->elements())->set(1, new_elements); 1513 FixedArray::cast(obj->elements())->set(1, *new_elements);
1517 } else { 1514 } else {
1518 obj->set_elements(new_elements); 1515 obj->set_elements(*new_elements);
1519 } 1516 }
1520 } 1517 }
1521 return heap->true_value(); 1518 return isolate->factory()->true_value();
1522 }
1523
1524 // TODO(ishell): Temporary wrapper until handlified.
1525 MUST_USE_RESULT static Handle<Object> DeleteCommon(
1526 Handle<JSObject> obj,
1527 uint32_t key,
1528 JSReceiver::DeleteMode mode) {
1529 CALL_HEAP_FUNCTION(obj->GetIsolate(),
1530 DeleteCommon(*obj, key, mode),
1531 Object);
1532 } 1519 }
1533 1520
1534 static void CopyElementsImpl(Handle<FixedArrayBase> from, 1521 static void CopyElementsImpl(Handle<FixedArrayBase> from,
1535 uint32_t from_start, 1522 uint32_t from_start,
1536 Handle<FixedArrayBase> to, 1523 Handle<FixedArrayBase> to,
1537 ElementsKind from_kind, 1524 ElementsKind from_kind,
1538 uint32_t to_start, 1525 uint32_t to_start,
1539 int packed_size, 1526 int packed_size,
1540 int copy_size) { 1527 int copy_size) {
1541 UNREACHABLE(); 1528 UNREACHABLE();
1542 } 1529 }
1543 1530
1544 1531
1545 protected: 1532 protected:
1546 friend class ElementsAccessorBase<DictionaryElementsAccessor, 1533 friend class ElementsAccessorBase<DictionaryElementsAccessor,
1547 ElementsKindTraits<DICTIONARY_ELEMENTS> >; 1534 ElementsKindTraits<DICTIONARY_ELEMENTS> >;
1548 1535
1549 MUST_USE_RESULT virtual Handle<Object> Delete( 1536 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1550 Handle<JSObject> obj, 1537 Handle<JSObject> obj,
1551 uint32_t key, 1538 uint32_t key,
1552 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1539 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1553 return DeleteCommon(obj, key, mode); 1540 return DeleteCommon(obj, key, mode);
1554 } 1541 }
1555 1542
1556 static Handle<Object> GetImpl( 1543 static Handle<Object> GetImpl(
1557 Handle<Object> receiver, 1544 Handle<Object> receiver,
1558 Handle<JSObject> obj, 1545 Handle<JSObject> obj,
1559 uint32_t key, 1546 uint32_t key,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1727 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1741 Handle<JSObject> obj, 1728 Handle<JSObject> obj,
1742 Handle<Object> length, 1729 Handle<Object> length,
1743 Handle<FixedArrayBase> parameter_map) { 1730 Handle<FixedArrayBase> parameter_map) {
1744 // TODO(mstarzinger): This was never implemented but will be used once we 1731 // TODO(mstarzinger): This was never implemented but will be used once we
1745 // correctly implement [[DefineOwnProperty]] on arrays. 1732 // correctly implement [[DefineOwnProperty]] on arrays.
1746 UNIMPLEMENTED(); 1733 UNIMPLEMENTED();
1747 return obj; 1734 return obj;
1748 } 1735 }
1749 1736
1750 MUST_USE_RESULT virtual Handle<Object> Delete( 1737 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1751 Handle<JSObject> obj, 1738 Handle<JSObject> obj,
1752 uint32_t key, 1739 uint32_t key,
1753 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { 1740 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
1754 Isolate* isolate = obj->GetIsolate(); 1741 Isolate* isolate = obj->GetIsolate();
1755 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements())); 1742 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
1756 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key); 1743 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1757 if (!probe->IsTheHole()) { 1744 if (!probe->IsTheHole()) {
1758 // TODO(kmillikin): We could check if this was the last aliased 1745 // TODO(kmillikin): We could check if this was the last aliased
1759 // parameter, and revert to normal elements in that case. That 1746 // parameter, and revert to normal elements in that case. That
1760 // would enable GC of the context. 1747 // would enable GC of the context.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 UNREACHABLE(); 1995 UNREACHABLE();
2009 break; 1996 break;
2010 } 1997 }
2011 1998
2012 array->set_elements(*elms); 1999 array->set_elements(*elms);
2013 array->set_length(Smi::FromInt(number_of_elements)); 2000 array->set_length(Smi::FromInt(number_of_elements));
2014 return array; 2001 return array;
2015 } 2002 }
2016 2003
2017 } } // namespace v8::internal 2004 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698