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

Side by Side Diff: src/elements.cc

Issue 894683003: Introduce LanguageMode, drop StrictMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased (w/ conflicts) Created 5 years, 10 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/execution.cc » ('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/objects.h" 10 #include "src/objects.h"
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 684 }
685 685
686 static void SetFastElementsCapacityAndLength( 686 static void SetFastElementsCapacityAndLength(
687 Handle<JSObject> obj, 687 Handle<JSObject> obj,
688 int capacity, 688 int capacity,
689 int length) { 689 int length) {
690 UNIMPLEMENTED(); 690 UNIMPLEMENTED();
691 } 691 }
692 692
693 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 693 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
694 Handle<JSObject> obj, uint32_t key, StrictMode strict_mode) OVERRIDE = 0; 694 Handle<JSObject> obj, uint32_t key,
695 LanguageMode language_mode) OVERRIDE = 0;
695 696
696 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 697 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
697 FixedArrayBase* to, ElementsKind from_kind, 698 FixedArrayBase* to, ElementsKind from_kind,
698 uint32_t to_start, int packed_size, 699 uint32_t to_start, int packed_size,
699 int copy_size) { 700 int copy_size) {
700 UNREACHABLE(); 701 UNREACHABLE();
701 } 702 }
702 703
703 virtual void CopyElements(Handle<FixedArrayBase> from, uint32_t from_start, 704 virtual void CopyElements(Handle<FixedArrayBase> from, uint32_t from_start,
704 ElementsKind from_kind, Handle<FixedArrayBase> to, 705 ElementsKind from_kind, Handle<FixedArrayBase> to,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // Check whether the backing store should be expanded. 908 // Check whether the backing store should be expanded.
908 uint32_t min = JSObject::NewElementsCapacity(old_capacity); 909 uint32_t min = JSObject::NewElementsCapacity(old_capacity);
909 uint32_t new_capacity = length > min ? length : min; 910 uint32_t new_capacity = length > min ? length : min;
910 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength( 911 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength(
911 array, new_capacity, length); 912 array, new_capacity, length);
912 JSObject::ValidateElements(array); 913 JSObject::ValidateElements(array);
913 return length_object; 914 return length_object;
914 } 915 }
915 916
916 static Handle<Object> DeleteCommon(Handle<JSObject> obj, uint32_t key, 917 static Handle<Object> DeleteCommon(Handle<JSObject> obj, uint32_t key,
917 StrictMode strict_mode) { 918 LanguageMode language_mode) {
918 DCHECK(obj->HasFastSmiOrObjectElements() || 919 DCHECK(obj->HasFastSmiOrObjectElements() ||
919 obj->HasFastDoubleElements() || 920 obj->HasFastDoubleElements() ||
920 obj->HasFastArgumentsElements()); 921 obj->HasFastArgumentsElements());
921 Isolate* isolate = obj->GetIsolate(); 922 Isolate* isolate = obj->GetIsolate();
922 Heap* heap = obj->GetHeap(); 923 Heap* heap = obj->GetHeap();
923 Handle<FixedArrayBase> elements(obj->elements()); 924 Handle<FixedArrayBase> elements(obj->elements());
924 if (*elements == heap->empty_fixed_array()) { 925 if (*elements == heap->empty_fixed_array()) {
925 return isolate->factory()->true_value(); 926 return isolate->factory()->true_value();
926 } 927 }
927 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements); 928 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 } 966 }
966 if (4 * num_used <= backing_store->length()) { 967 if (4 * num_used <= backing_store->length()) {
967 JSObject::NormalizeElements(obj); 968 JSObject::NormalizeElements(obj);
968 } 969 }
969 } 970 }
970 } 971 }
971 return isolate->factory()->true_value(); 972 return isolate->factory()->true_value();
972 } 973 }
973 974
974 virtual MaybeHandle<Object> Delete(Handle<JSObject> obj, uint32_t key, 975 virtual MaybeHandle<Object> Delete(Handle<JSObject> obj, uint32_t key,
975 StrictMode strict_mode) FINAL { 976 LanguageMode language_mode) FINAL {
976 return DeleteCommon(obj, key, strict_mode); 977 return DeleteCommon(obj, key, language_mode);
977 } 978 }
978 979
979 static bool HasElementImpl( 980 static bool HasElementImpl(
980 Handle<Object> receiver, 981 Handle<Object> receiver,
981 Handle<JSObject> holder, 982 Handle<JSObject> holder,
982 uint32_t key, 983 uint32_t key,
983 Handle<FixedArrayBase> backing_store) { 984 Handle<FixedArrayBase> backing_store) {
984 if (key >= static_cast<uint32_t>(backing_store->length())) { 985 if (key >= static_cast<uint32_t>(backing_store->length())) {
985 return false; 986 return false;
986 } 987 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1289 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1289 Handle<JSObject> obj, 1290 Handle<JSObject> obj,
1290 Handle<Object> length, 1291 Handle<Object> length,
1291 Handle<FixedArrayBase> backing_store) { 1292 Handle<FixedArrayBase> backing_store) {
1292 // External arrays do not support changing their length. 1293 // External arrays do not support changing their length.
1293 UNREACHABLE(); 1294 UNREACHABLE();
1294 return obj; 1295 return obj;
1295 } 1296 }
1296 1297
1297 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 1298 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1298 Handle<JSObject> obj, uint32_t key, StrictMode strict_mode) FINAL { 1299 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL {
1299 // External arrays always ignore deletes. 1300 // External arrays always ignore deletes.
1300 return obj->GetIsolate()->factory()->true_value(); 1301 return obj->GetIsolate()->factory()->true_value();
1301 } 1302 }
1302 1303
1303 static bool HasElementImpl(Handle<Object> receiver, 1304 static bool HasElementImpl(Handle<Object> receiver,
1304 Handle<JSObject> holder, 1305 Handle<JSObject> holder,
1305 uint32_t key, 1306 uint32_t key,
1306 Handle<FixedArrayBase> backing_store) { 1307 Handle<FixedArrayBase> backing_store) {
1307 uint32_t capacity = 1308 uint32_t capacity =
1308 AccessorClass::GetCapacityImpl(backing_store); 1309 AccessorClass::GetCapacityImpl(backing_store);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 1388 }
1388 } 1389 }
1389 1390
1390 // Update the number of elements. 1391 // Update the number of elements.
1391 dict->ElementsRemoved(removed_entries); 1392 dict->ElementsRemoved(removed_entries);
1392 } 1393 }
1393 return length_object; 1394 return length_object;
1394 } 1395 }
1395 1396
1396 MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon( 1397 MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon(
1397 Handle<JSObject> obj, uint32_t key, StrictMode strict_mode) { 1398 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) {
1398 Isolate* isolate = obj->GetIsolate(); 1399 Isolate* isolate = obj->GetIsolate();
1399 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()), 1400 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
1400 isolate); 1401 isolate);
1401 bool is_arguments = 1402 bool is_arguments =
1402 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1403 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1403 if (is_arguments) { 1404 if (is_arguments) {
1404 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate); 1405 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
1405 } 1406 }
1406 Handle<SeededNumberDictionary> dictionary = 1407 Handle<SeededNumberDictionary> dictionary =
1407 Handle<SeededNumberDictionary>::cast(backing_store); 1408 Handle<SeededNumberDictionary>::cast(backing_store);
1408 int entry = dictionary->FindEntry(key); 1409 int entry = dictionary->FindEntry(key);
1409 if (entry != SeededNumberDictionary::kNotFound) { 1410 if (entry != SeededNumberDictionary::kNotFound) {
1410 Handle<Object> result = 1411 Handle<Object> result =
1411 SeededNumberDictionary::DeleteProperty(dictionary, entry); 1412 SeededNumberDictionary::DeleteProperty(dictionary, entry);
1412 if (*result == *isolate->factory()->false_value()) { 1413 if (*result == *isolate->factory()->false_value()) {
1413 if (strict_mode == STRICT) { 1414 if (is_strict(language_mode)) {
1414 // Deleting a non-configurable property in strict mode. 1415 // Deleting a non-configurable property in strict mode.
1415 Handle<Object> name = isolate->factory()->NewNumberFromUint(key); 1416 Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
1416 Handle<Object> args[2] = { name, obj }; 1417 Handle<Object> args[2] = { name, obj };
1417 THROW_NEW_ERROR(isolate, NewTypeError("strict_delete_property", 1418 THROW_NEW_ERROR(isolate, NewTypeError("strict_delete_property",
1418 HandleVector(args, 2)), 1419 HandleVector(args, 2)),
1419 Object); 1420 Object);
1420 } 1421 }
1421 return isolate->factory()->false_value(); 1422 return isolate->factory()->false_value();
1422 } 1423 }
1423 Handle<FixedArray> new_elements = 1424 Handle<FixedArray> new_elements =
(...skipping 14 matching lines...) Expand all
1438 int copy_size) { 1439 int copy_size) {
1439 UNREACHABLE(); 1440 UNREACHABLE();
1440 } 1441 }
1441 1442
1442 1443
1443 protected: 1444 protected:
1444 friend class ElementsAccessorBase<DictionaryElementsAccessor, 1445 friend class ElementsAccessorBase<DictionaryElementsAccessor,
1445 ElementsKindTraits<DICTIONARY_ELEMENTS> >; 1446 ElementsKindTraits<DICTIONARY_ELEMENTS> >;
1446 1447
1447 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 1448 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1448 Handle<JSObject> obj, uint32_t key, StrictMode strict_mode) FINAL { 1449 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL {
1449 return DeleteCommon(obj, key, strict_mode); 1450 return DeleteCommon(obj, key, language_mode);
1450 } 1451 }
1451 1452
1452 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( 1453 MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
1453 Handle<Object> receiver, 1454 Handle<Object> receiver,
1454 Handle<JSObject> obj, 1455 Handle<JSObject> obj,
1455 uint32_t key, 1456 uint32_t key,
1456 Handle<FixedArrayBase> store) { 1457 Handle<FixedArrayBase> store) {
1457 Handle<SeededNumberDictionary> backing_store = 1458 Handle<SeededNumberDictionary> backing_store =
1458 Handle<SeededNumberDictionary>::cast(store); 1459 Handle<SeededNumberDictionary>::cast(store);
1459 Isolate* isolate = backing_store->GetIsolate(); 1460 Isolate* isolate = backing_store->GetIsolate();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 Handle<JSObject> obj, 1611 Handle<JSObject> obj,
1611 Handle<Object> length, 1612 Handle<Object> length,
1612 Handle<FixedArrayBase> parameter_map) { 1613 Handle<FixedArrayBase> parameter_map) {
1613 // TODO(mstarzinger): This was never implemented but will be used once we 1614 // TODO(mstarzinger): This was never implemented but will be used once we
1614 // correctly implement [[DefineOwnProperty]] on arrays. 1615 // correctly implement [[DefineOwnProperty]] on arrays.
1615 UNIMPLEMENTED(); 1616 UNIMPLEMENTED();
1616 return obj; 1617 return obj;
1617 } 1618 }
1618 1619
1619 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 1620 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1620 Handle<JSObject> obj, uint32_t key, StrictMode strict_mode) FINAL { 1621 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL {
1621 Isolate* isolate = obj->GetIsolate(); 1622 Isolate* isolate = obj->GetIsolate();
1622 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements())); 1623 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
1623 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key); 1624 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1624 if (!probe->IsTheHole()) { 1625 if (!probe->IsTheHole()) {
1625 // TODO(kmillikin): We could check if this was the last aliased 1626 // TODO(kmillikin): We could check if this was the last aliased
1626 // parameter, and revert to normal elements in that case. That 1627 // parameter, and revert to normal elements in that case. That
1627 // would enable GC of the context. 1628 // would enable GC of the context.
1628 parameter_map->set_the_hole(key + 2); 1629 parameter_map->set_the_hole(key + 2);
1629 } else { 1630 } else {
1630 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 1631 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1631 if (arguments->IsDictionary()) { 1632 if (arguments->IsDictionary()) {
1632 return DictionaryElementsAccessor::DeleteCommon(obj, key, strict_mode); 1633 return DictionaryElementsAccessor::DeleteCommon(obj, key,
1634 language_mode);
1633 } else { 1635 } else {
1634 // It's difficult to access the version of DeleteCommon that is declared 1636 // It's difficult to access the version of DeleteCommon that is declared
1635 // in the templatized super class, call the concrete implementation in 1637 // in the templatized super class, call the concrete implementation in
1636 // the class for the most generalized ElementsKind subclass. 1638 // the class for the most generalized ElementsKind subclass.
1637 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, 1639 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key,
1638 strict_mode); 1640 language_mode);
1639 } 1641 }
1640 } 1642 }
1641 return isolate->factory()->true_value(); 1643 return isolate->factory()->true_value();
1642 } 1644 }
1643 1645
1644 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 1646 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
1645 FixedArrayBase* to, ElementsKind from_kind, 1647 FixedArrayBase* to, ElementsKind from_kind,
1646 uint32_t to_start, int packed_size, 1648 uint32_t to_start, int packed_size,
1647 int copy_size) { 1649 int copy_size) {
1648 UNREACHABLE(); 1650 UNREACHABLE();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 UNREACHABLE(); 1883 UNREACHABLE();
1882 break; 1884 break;
1883 } 1885 }
1884 1886
1885 array->set_elements(*elms); 1887 array->set_elements(*elms);
1886 array->set_length(Smi::FromInt(number_of_elements)); 1888 array->set_length(Smi::FromInt(number_of_elements));
1887 return array; 1889 return array;
1888 } 1890 }
1889 1891
1890 } } // namespace v8::internal 1892 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698