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

Side by Side Diff: src/elements.cc

Issue 1156573002: [strong] Implement per-object restrictions behaviour of delete operator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback 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 | « no previous file | src/messages.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 // 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 918
919 // Check whether the backing store should be expanded. 919 // Check whether the backing store should be expanded.
920 uint32_t min = JSObject::NewElementsCapacity(old_capacity); 920 uint32_t min = JSObject::NewElementsCapacity(old_capacity);
921 uint32_t new_capacity = length > min ? length : min; 921 uint32_t new_capacity = length > min ? length : min;
922 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength( 922 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength(
923 array, new_capacity, length); 923 array, new_capacity, length);
924 JSObject::ValidateElements(array); 924 JSObject::ValidateElements(array);
925 return length_object; 925 return length_object;
926 } 926 }
927 927
928 static Handle<Object> DeleteCommon(Handle<JSObject> obj, uint32_t key, 928 static MaybeHandle<Object> DeleteCommon(Handle<JSObject> obj, uint32_t key,
929 LanguageMode language_mode) { 929 LanguageMode language_mode) {
930 DCHECK(obj->HasFastSmiOrObjectElements() || 930 DCHECK(obj->HasFastSmiOrObjectElements() ||
931 obj->HasFastDoubleElements() || 931 obj->HasFastDoubleElements() ||
932 obj->HasFastArgumentsElements()); 932 obj->HasFastArgumentsElements());
933 Isolate* isolate = obj->GetIsolate(); 933 Isolate* isolate = obj->GetIsolate();
934 Heap* heap = obj->GetHeap(); 934 Heap* heap = obj->GetHeap();
935 Handle<FixedArrayBase> elements(obj->elements()); 935 Handle<FixedArrayBase> elements(obj->elements());
936 if (*elements == heap->empty_fixed_array()) { 936 if (*elements == heap->empty_fixed_array()) {
937 return isolate->factory()->true_value(); 937 return isolate->factory()->true_value();
938 } 938 }
939 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements); 939 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
940 bool is_sloppy_arguments_elements_map = 940 bool is_sloppy_arguments_elements_map =
941 backing_store->map() == heap->sloppy_arguments_elements_map(); 941 backing_store->map() == heap->sloppy_arguments_elements_map();
942 if (is_sloppy_arguments_elements_map) { 942 if (is_sloppy_arguments_elements_map) {
943 backing_store = handle( 943 backing_store = handle(
944 BackingStore::cast(Handle<FixedArray>::cast(backing_store)->get(1)), 944 BackingStore::cast(Handle<FixedArray>::cast(backing_store)->get(1)),
945 isolate); 945 isolate);
946 } 946 }
947 uint32_t length = static_cast<uint32_t>( 947 uint32_t length = static_cast<uint32_t>(
948 obj->IsJSArray() 948 obj->IsJSArray()
949 ? Smi::cast(Handle<JSArray>::cast(obj)->length())->value() 949 ? Smi::cast(Handle<JSArray>::cast(obj)->length())->value()
950 : backing_store->length()); 950 : backing_store->length());
951 if (key < length) { 951 if (key < length) {
952 if (obj->map()->is_strong() && !backing_store->is_the_hole(key)) {
953 if (is_strict(language_mode)) {
954 Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
955 THROW_NEW_ERROR(
956 isolate,
957 NewTypeError(MessageTemplate::kStrongDeleteProperty, obj, name),
958 Object);
959 }
960 return isolate->factory()->false_value();
961 }
952 if (!is_sloppy_arguments_elements_map) { 962 if (!is_sloppy_arguments_elements_map) {
953 ElementsKind kind = KindTraits::Kind; 963 ElementsKind kind = KindTraits::Kind;
954 if (IsFastPackedElementsKind(kind)) { 964 if (IsFastPackedElementsKind(kind)) {
955 JSObject::TransitionElementsKind(obj, GetHoleyElementsKind(kind)); 965 JSObject::TransitionElementsKind(obj, GetHoleyElementsKind(kind));
956 } 966 }
957 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { 967 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) {
958 Handle<Object> writable = JSObject::EnsureWritableFastElements(obj); 968 Handle<Object> writable = JSObject::EnsureWritableFastElements(obj);
959 backing_store = Handle<BackingStore>::cast(writable); 969 backing_store = Handle<BackingStore>::cast(writable);
960 } 970 }
961 } 971 }
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 isolate); 1423 isolate);
1414 bool is_arguments = 1424 bool is_arguments =
1415 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1425 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1416 if (is_arguments) { 1426 if (is_arguments) {
1417 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate); 1427 backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
1418 } 1428 }
1419 Handle<SeededNumberDictionary> dictionary = 1429 Handle<SeededNumberDictionary> dictionary =
1420 Handle<SeededNumberDictionary>::cast(backing_store); 1430 Handle<SeededNumberDictionary>::cast(backing_store);
1421 int entry = dictionary->FindEntry(key); 1431 int entry = dictionary->FindEntry(key);
1422 if (entry != SeededNumberDictionary::kNotFound) { 1432 if (entry != SeededNumberDictionary::kNotFound) {
1423 Handle<Object> result = 1433 Handle<Object> result;
1424 SeededNumberDictionary::DeleteProperty(dictionary, entry); 1434 bool strong = obj->map()->is_strong();
1425 if (*result == *isolate->factory()->false_value()) { 1435 if (!strong) {
1436 result = SeededNumberDictionary::DeleteProperty(dictionary, entry);
1437 }
1438 if (strong || *result == *isolate->factory()->false_value()) {
1439 // Fail if the property is not configurable, or on a strong object.
1426 if (is_strict(language_mode)) { 1440 if (is_strict(language_mode)) {
1427 // Deleting a non-configurable property in strict mode.
1428 Handle<Object> name = isolate->factory()->NewNumberFromUint(key); 1441 Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
1442 if (strong) {
1443 THROW_NEW_ERROR(
1444 isolate,
1445 NewTypeError(MessageTemplate::kStrongDeleteProperty, obj, name),
1446 Object);
1447 }
1429 THROW_NEW_ERROR( 1448 THROW_NEW_ERROR(
1430 isolate, 1449 isolate,
1431 NewTypeError(MessageTemplate::kStrictDeleteProperty, name, obj), 1450 NewTypeError(MessageTemplate::kStrictDeleteProperty, name, obj),
1432 Object); 1451 Object);
1433 } 1452 }
1434 return isolate->factory()->false_value(); 1453 return isolate->factory()->false_value();
1435 } 1454 }
1436 Handle<FixedArray> new_elements = 1455 Handle<FixedArray> new_elements =
1437 SeededNumberDictionary::Shrink(dictionary, key); 1456 SeededNumberDictionary::Shrink(dictionary, key);
1438 1457
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 UNREACHABLE(); 1913 UNREACHABLE();
1895 break; 1914 break;
1896 } 1915 }
1897 1916
1898 array->set_elements(*elms); 1917 array->set_elements(*elms);
1899 array->set_length(Smi::FromInt(number_of_elements)); 1918 array->set_length(Smi::FromInt(number_of_elements));
1900 return array; 1919 return array;
1901 } 1920 }
1902 1921
1903 } } // namespace v8::internal 1922 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698