Commit dba715ec authored by verwaest's avatar verwaest Committed by Commit bot

Cleanup Delete backend implementation.

BUG=v8:4137
LOG=n

Review URL: https://codereview.chromium.org/1218813012

Cr-Commit-Position: refs/heads/master@{#29477}
parent b0a852e8
This diff is collapsed.
......@@ -62,8 +62,7 @@ class ElementsAccessor {
virtual void SetLength(Handle<JSArray> holder, uint32_t new_length) = 0;
// Deletes an element in an object.
virtual void Delete(Handle<JSObject> holder, uint32_t key,
LanguageMode language_mode) = 0;
virtual void Delete(Handle<JSObject> holder, uint32_t index) = 0;
// If kCopyToEnd is specified as the copy_size to CopyElements, it copies all
// of elements from source after source_start to the destination array.
......
......@@ -223,6 +223,28 @@ void LookupIterator::ApplyTransitionToDataProperty() {
}
void LookupIterator::Delete() {
Handle<JSObject> holder = Handle<JSObject>::cast(holder_);
if (IsElement()) {
ElementsAccessor* accessor = holder->GetElementsAccessor();
accessor->Delete(holder, number_);
} else {
PropertyNormalizationMode mode = holder->map()->is_prototype_map()
? KEEP_INOBJECT_PROPERTIES
: CLEAR_INOBJECT_PROPERTIES;
if (holder->HasFastProperties()) {
JSObject::NormalizeProperties(holder, mode, 0, "DeletingProperty");
holder_map_ = handle(holder->map(), isolate_);
ReloadPropertyInformation();
}
// TODO(verwaest): Get rid of the name_ argument.
JSObject::DeleteNormalizedProperty(holder, name_, number_);
JSObject::ReoptimizeIfPrototype(holder);
}
}
void LookupIterator::TransitionToAccessorProperty(
AccessorComponent component, Handle<Object> accessor,
PropertyAttributes attributes) {
......
......@@ -216,6 +216,7 @@ class LookupIterator final BASE_EMBEDDED {
void ApplyTransitionToDataProperty();
void ReconfigureDataProperty(Handle<Object> value,
PropertyAttributes attributes);
void Delete();
void TransitionToAccessorProperty(AccessorComponent component,
Handle<Object> accessor,
PropertyAttributes attributes);
......
......@@ -229,7 +229,7 @@ class CallSite {
T(StrongArity, \
"In strong mode, calling a function with too few arguments is deprecated") \
T(StrongDeleteProperty, \
"On strong object %, deletion of property % is deprecated") \
"Deleting property '%' of strong object '%' is deprecated") \
T(StrongImplicitConversion, \
"In strong mode, implicit conversions are deprecated") \
T(StrongRedefineDisallowed, \
......
......@@ -5145,14 +5145,13 @@ MaybeHandle<Object> JSObject::DeletePropertyWithInterceptor(
void JSObject::DeleteNormalizedProperty(Handle<JSObject> object,
Handle<Name> name) {
Handle<Name> name, int entry) {
DCHECK(!object->HasFastProperties());
Isolate* isolate = object->GetIsolate();
if (object->IsGlobalObject()) {
// If we have a global object, invalidate the cell and swap in a new one.
Handle<GlobalDictionary> dictionary(object->global_dictionary());
int entry = dictionary->FindEntry(name);
DCHECK_NE(GlobalDictionary::kNotFound, entry);
auto cell = PropertyCell::InvalidateEntry(dictionary, entry);
......@@ -5162,7 +5161,6 @@ void JSObject::DeleteNormalizedProperty(Handle<JSObject> object,
cell->property_details().set_cell_type(PropertyCellType::kInvalidated));
} else {
Handle<NameDictionary> dictionary(object->property_dictionary());
int entry = dictionary->FindEntry(name);
DCHECK_NE(NameDictionary::kNotFound, entry);
NameDictionary::DeleteProperty(dictionary, entry);
......@@ -5221,16 +5219,12 @@ MaybeHandle<Object> JSReceiver::DeleteProperty(LookupIterator* it,
if (!it->IsConfigurable() || receiver->map()->is_strong()) {
// Fail if the property is not configurable, or on a strong object.
if (is_strict(language_mode)) {
if (receiver->map()->is_strong()) {
THROW_NEW_ERROR(
isolate, NewTypeError(MessageTemplate::kStrongDeleteProperty,
receiver, it->GetName()),
Object);
}
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kStrictDeleteProperty,
it->GetName(), receiver),
Object);
MessageTemplate::Template templ =
receiver->map()->is_strong()
? MessageTemplate::kStrongDeleteProperty
: MessageTemplate::kStrictDeleteProperty;
THROW_NEW_ERROR(
isolate, NewTypeError(templ, it->GetName(), receiver), Object);
}
return it->factory()->false_value();
}
......@@ -5243,18 +5237,7 @@ MaybeHandle<Object> JSReceiver::DeleteProperty(LookupIterator* it,
return it->factory()->true_value();
}
if (it->IsElement()) {
ElementsAccessor* accessor = holder->GetElementsAccessor();
accessor->Delete(holder, it->index(), language_mode);
} else {
PropertyNormalizationMode mode = holder->map()->is_prototype_map()
? KEEP_INOBJECT_PROPERTIES
: CLEAR_INOBJECT_PROPERTIES;
JSObject::NormalizeProperties(holder, mode, 0, "DeletingProperty");
JSObject::DeleteNormalizedProperty(holder, it->name());
JSObject::ReoptimizeIfPrototype(holder);
}
it->Delete();
if (is_observed) {
RETURN_ON_EXCEPTION(isolate,
......
......@@ -2292,6 +2292,10 @@ class JSObject: public JSReceiver {
// Gets the current elements capacity and the number of used elements.
void GetElementsCapacityAndUsage(int* capacity, int* used);
// Deletes an existing named property in a normalized object.
static void DeleteNormalizedProperty(Handle<JSObject> object,
Handle<Name> name, int entry);
private:
friend class DictionaryElementsAccessor;
friend class JSReceiver;
......@@ -2318,10 +2322,6 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithInterceptor(
LookupIterator* it);
// Deletes an existing named property in a normalized object.
static void DeleteNormalizedProperty(Handle<JSObject> object,
Handle<Name> name);
bool ReferencesObjectFromElements(FixedArray* elements,
ElementsKind kind,
Object* object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment