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

Reland of [runtime] further dismantle AccessorInfoHandling, reducing it to the single API usecase.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#33737}
parent 8208dd6a
......@@ -3561,7 +3561,8 @@ static i::MaybeHandle<i::Object> DefineObjectProperty(
isolate, js_object, key, &success, i::LookupIterator::OWN);
if (!success) return i::MaybeHandle<i::Object>();
return i::JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attrs);
return i::JSObject::DefineOwnPropertyIgnoreAttributes(
&it, value, attrs, i::JSObject::FORCE_FIELD);
}
......
......@@ -292,6 +292,7 @@ void LookupIterator::Delete() {
JSObject::ReoptimizeIfPrototype(Handle<JSObject>::cast(holder));
}
}
state_ = NOT_FOUND;
}
......
......@@ -5339,32 +5339,29 @@ Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
CERTAINLY_NOT_STORE_FROM_KEYED);
}
MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes(
Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
PropertyAttributes attributes, AccessorInfoHandling handling) {
PropertyAttributes attributes) {
DCHECK(!value->IsTheHole());
LookupIterator it(object, name, LookupIterator::OWN);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes);
}
MaybeHandle<Object> JSObject::SetOwnElementIgnoreAttributes(
Handle<JSObject> object, uint32_t index, Handle<Object> value,
PropertyAttributes attributes, AccessorInfoHandling handling) {
PropertyAttributes attributes) {
Isolate* isolate = object->GetIsolate();
LookupIterator it(isolate, object, index, LookupIterator::OWN);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes);
}
MaybeHandle<Object> JSObject::DefinePropertyOrElementIgnoreAttributes(
Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
PropertyAttributes attributes, AccessorInfoHandling handling) {
PropertyAttributes attributes) {
Isolate* isolate = object->GetIsolate();
LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name,
LookupIterator::OWN);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling);
return DefineOwnPropertyIgnoreAttributes(&it, value, attributes);
}
......@@ -6602,8 +6599,8 @@ Maybe<bool> JSReceiver::ValidateAndApplyPropertyDescriptor(
? desc->value()
: Handle<Object>::cast(isolate->factory()->undefined_value()));
MaybeHandle<Object> result =
JSObject::DefineOwnPropertyIgnoreAttributes(
it, value, desc->ToAttributes(), JSObject::DONT_FORCE_FIELD);
JSObject::DefineOwnPropertyIgnoreAttributes(it, value,
desc->ToAttributes());
if (result.is_null()) return Nothing<bool>();
}
} else {
......@@ -6795,8 +6792,8 @@ Maybe<bool> JSReceiver::ValidateAndApplyPropertyDescriptor(
? current->value()
: Handle<Object>::cast(
isolate->factory()->undefined_value()));
MaybeHandle<Object> result = JSObject::DefineOwnPropertyIgnoreAttributes(
it, value, attrs, JSObject::DONT_FORCE_FIELD);
MaybeHandle<Object> result =
JSObject::DefineOwnPropertyIgnoreAttributes(it, value, attrs);
if (result.is_null()) return Nothing<bool>();
} else {
DCHECK(desc_is_accessor_descriptor ||
......@@ -6860,10 +6857,9 @@ Maybe<bool> JSObject::CreateDataProperty(LookupIterator* it,
return Just(false);
}
RETURN_ON_EXCEPTION_VALUE(
it->isolate(),
DefineOwnPropertyIgnoreAttributes(it, value, NONE, DONT_FORCE_FIELD),
Nothing<bool>());
RETURN_ON_EXCEPTION_VALUE(it->isolate(),
DefineOwnPropertyIgnoreAttributes(it, value, NONE),
Nothing<bool>());
return Just(true);
}
......
......@@ -2066,36 +2066,35 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor(
LookupIterator* it, ShouldThrow should_throw, Handle<Object> value);
// SetLocalPropertyIgnoreAttributes converts callbacks to fields. We need to
// grant an exemption to AccessorInfo callbacks in some cases.
enum AccessorInfoHandling { DEFAULT_HANDLING, DONT_FORCE_FIELD };
// The API currently still wants DefineOwnPropertyIgnoreAttributes to convert
// AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception
// to the default behavior that calls the setter.
enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD };
MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes(
LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
AccessorInfoHandling handling = DEFAULT_HANDLING);
AccessorInfoHandling handling = DONT_FORCE_FIELD);
MUST_USE_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes(
LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
ShouldThrow should_throw,
AccessorInfoHandling handling = DEFAULT_HANDLING);
AccessorInfoHandling handling = DONT_FORCE_FIELD);
MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes(
Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
PropertyAttributes attributes,
AccessorInfoHandling handling = DEFAULT_HANDLING);
PropertyAttributes attributes);
MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes(
Handle<JSObject> object, uint32_t index, Handle<Object> value,
PropertyAttributes attributes,
AccessorInfoHandling handling = DEFAULT_HANDLING);
PropertyAttributes attributes);
// Equivalent to one of the above depending on whether |name| can be converted
// to an array index.
MUST_USE_RESULT static MaybeHandle<Object>
DefinePropertyOrElementIgnoreAttributes(
Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
PropertyAttributes attributes = NONE,
AccessorInfoHandling handling = DEFAULT_HANDLING);
DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object,
Handle<Name> name,
Handle<Object> value,
PropertyAttributes attributes = NONE);
// Adds or reconfigures a property to attributes NONE. It will fail when it
// cannot.
......
......@@ -65,21 +65,27 @@ static Object* DeclareGlobals(Isolate* isolate, Handle<JSGlobalObject> global,
// Check whether we can reconfigure the existing property into a
// function.
PropertyDetails old_details = it.property_details();
// TODO(verwaest): ACCESSOR_CONSTANT invalidly includes
// ExecutableAccessInfo,
// which are actually data properties, not accessor properties.
if (old_details.IsReadOnly() || old_details.IsDontEnum() ||
old_details.type() == ACCESSOR_CONSTANT) {
(it.state() == LookupIterator::ACCESSOR &&
it.GetAccessors()->IsAccessorPair())) {
return ThrowRedeclarationError(isolate, name);
}
// If the existing property is not configurable, keep its attributes. Do
attr = old_attributes;
}
// If the current state is ACCESSOR, this could mean it's an AccessorInfo
// type property. We are not allowed to call into such setters during global
// function declaration since this would break e.g., onload. Meaning
// 'function onload() {}' would invalidly register that function as the
// onload callback. To avoid this situation, we first delete the property
// before readding it as a regular data property below.
if (it.state() == LookupIterator::ACCESSOR) it.Delete();
}
// Define or redefine own property.
RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
global, name, value, attr));
RETURN_FAILURE_ON_EXCEPTION(
isolate, JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attr));
return isolate->heap()->undefined_value();
}
......@@ -196,8 +202,8 @@ RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) {
}
}
RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
global, name, value, attr));
RETURN_FAILURE_ON_EXCEPTION(
isolate, JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attr));
return *value;
}
......
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