LibJS: Align ObjectEnvironmentRecord member names with the spec

In the spec, object environments have a [[BindingObject]], so let's
call it the same thing in our implementation.
This commit is contained in:
Andreas Kling 2021-06-26 10:38:36 +02:00
parent 0f9038b732
commit ee4fc97038
3 changed files with 32 additions and 30 deletions

View file

@ -117,7 +117,7 @@ bool GlobalEnvironmentRecord::delete_binding(GlobalObject& global_object, FlyStr
if (m_declarative_record->has_binding(name))
return m_declarative_record->delete_binding(global_object, name);
bool existing_prop = m_object_record->object().has_own_property(name);
bool existing_prop = m_object_record->binding_object().has_own_property(name);
if (existing_prop) {
bool status = m_object_record->delete_binding(global_object, name);
if (status) {
@ -143,7 +143,7 @@ bool GlobalEnvironmentRecord::has_lexical_declaration(FlyString const& name) con
// 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty
bool GlobalEnvironmentRecord::has_restricted_global_property(FlyString const& name) const
{
auto existing_prop = m_object_record->object().get_own_property_descriptor(name);
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
if (!existing_prop.has_value() || existing_prop.value().value.is_undefined())
return false;
if (existing_prop.value().attributes.is_configurable())
@ -154,18 +154,18 @@ bool GlobalEnvironmentRecord::has_restricted_global_property(FlyString const& na
// 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar
bool GlobalEnvironmentRecord::can_declare_global_var(FlyString const& name) const
{
bool has_property = m_object_record->object().has_own_property(name);
bool has_property = m_object_record->binding_object().has_own_property(name);
if (has_property)
return true;
return m_object_record->object().is_extensible();
return m_object_record->binding_object().is_extensible();
}
// 9.1.1.4.16 CanDeclareGlobalFunction ( N ), https://tc39.es/ecma262/#sec-candeclareglobalfunction
bool GlobalEnvironmentRecord::can_declare_global_function(FlyString const& name) const
{
auto existing_prop = m_object_record->object().get_own_property_descriptor(name);
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
if (!existing_prop.has_value() || existing_prop.value().value.is_undefined())
return m_object_record->object().is_extensible();
return m_object_record->binding_object().is_extensible();
if (existing_prop.value().attributes.is_configurable())
return true;
if (existing_prop.value().is_data_descriptor() && existing_prop.value().attributes.is_writable() && existing_prop.value().attributes.is_enumerable())
@ -176,10 +176,10 @@ bool GlobalEnvironmentRecord::can_declare_global_function(FlyString const& name)
// 9.1.1.4.17 CreateGlobalVarBinding ( N, D ), https://tc39.es/ecma262/#sec-createglobalvarbinding
void GlobalEnvironmentRecord::create_global_var_binding(FlyString const& name, bool can_be_deleted)
{
bool has_property = m_object_record->object().has_own_property(name);
bool extensible = m_object_record->object().is_extensible();
bool has_property = m_object_record->binding_object().has_own_property(name);
bool extensible = m_object_record->binding_object().is_extensible();
if (!has_property && extensible) {
m_object_record->create_mutable_binding(static_cast<GlobalObject&>(m_object_record->object()), name, can_be_deleted);
m_object_record->create_mutable_binding(static_cast<GlobalObject&>(m_object_record->binding_object()), name, can_be_deleted);
m_object_record->initialize_binding(m_object_record->global_object(), name, js_undefined());
}
if (!m_var_names.contains_slow(name))
@ -189,7 +189,7 @@ void GlobalEnvironmentRecord::create_global_var_binding(FlyString const& name, b
// 9.1.1.4.18 CreateGlobalFunctionBinding ( N, V, D ), https://tc39.es/ecma262/#sec-createglobalfunctionbinding
void GlobalEnvironmentRecord::create_global_function_binding(FlyString const& name, Value value, bool can_be_deleted)
{
auto existing_prop = m_object_record->object().get_own_property_descriptor(name);
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
PropertyDescriptor desc;
if (!existing_prop.has_value() || existing_prop.value().value.is_undefined() || existing_prop.value().attributes.is_configurable()) {
desc.value = value;
@ -204,7 +204,7 @@ void GlobalEnvironmentRecord::create_global_function_binding(FlyString const& na
desc.value = value;
}
// FIXME: This should be DefinePropertyOrThrow, followed by Set
m_object_record->object().define_property(name, value, desc.attributes);
m_object_record->binding_object().define_property(name, value, desc.attributes);
if (vm().exception())
return;
if (!m_var_names.contains_slow(name))

View file

@ -10,9 +10,9 @@
namespace JS {
ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& object, IsWithEnvironment is_with_environment, EnvironmentRecord* parent_scope)
: EnvironmentRecord(parent_scope)
, m_object(object)
ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& binding_object, IsWithEnvironment is_with_environment, EnvironmentRecord* outer_environment)
: EnvironmentRecord(outer_environment)
, m_binding_object(binding_object)
, m_with_environment(is_with_environment == IsWithEnvironment::Yes)
{
}
@ -20,12 +20,12 @@ ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& object, IsWithEnvironme
void ObjectEnvironmentRecord::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(&m_object);
visitor.visit(&m_binding_object);
}
Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyString const& name) const
{
auto value = m_object.get(name);
auto value = m_binding_object.get(name);
if (value.is_empty())
return {};
return Variable { value, DeclarationKind::Var };
@ -33,18 +33,18 @@ Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyStrin
void ObjectEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
{
m_object.put(name, variable.value);
m_binding_object.put(name, variable.value);
}
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name)
{
return m_object.delete_property(name);
return m_binding_object.delete_property(name);
}
// 9.1.1.2.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-hasbinding-n
bool ObjectEnvironmentRecord::has_binding(FlyString const& name) const
{
bool found_binding = m_object.has_property(name);
bool found_binding = m_binding_object.has_property(name);
if (!found_binding)
return false;
@ -64,7 +64,7 @@ void ObjectEnvironmentRecord::create_mutable_binding(GlobalObject&, FlyString co
attributes.set_has_configurable();
if (can_be_deleted)
attributes.set_configurable();
m_object.define_property(name, js_undefined(), attributes, true);
m_binding_object.define_property(name, js_undefined(), attributes, true);
}
// 9.1.1.2.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-createimmutablebinding-n-s
@ -83,20 +83,20 @@ void ObjectEnvironmentRecord::initialize_binding(GlobalObject& global_object, Fl
// 9.1.1.2.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-object-environment-records-setmutablebinding-n-v-s
void ObjectEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
{
bool still_exists = m_object.has_property(name);
bool still_exists = m_binding_object.has_property(name);
if (!still_exists && strict) {
global_object.vm().throw_exception<ReferenceError>(global_object, ErrorType::UnknownIdentifier, name);
return;
}
// FIXME: This should use the Set abstract operation.
// FIXME: Set returns a bool, so this may need to return a bool as well.
m_object.put(name, value);
m_binding_object.put(name, value);
}
// 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s
Value ObjectEnvironmentRecord::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
{
if (!m_object.has_property(name)) {
if (!m_binding_object.has_property(name)) {
if (!strict)
return js_undefined();
@ -104,13 +104,13 @@ Value ObjectEnvironmentRecord::get_binding_value(GlobalObject& global_object, Fl
return {};
}
// FIXME: This should use the Get abstract operation.
return m_object.get(name);
return m_binding_object.get(name);
}
// 9.1.1.2.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-deletebinding-n
bool ObjectEnvironmentRecord::delete_binding(GlobalObject&, FlyString const& name)
{
return m_object.delete_property(name);
return m_binding_object.delete_property(name);
}
}

View file

@ -18,7 +18,7 @@ public:
No,
Yes,
};
ObjectEnvironmentRecord(Object&, IsWithEnvironment, EnvironmentRecord* parent_scope);
ObjectEnvironmentRecord(Object& binding_object, IsWithEnvironment, EnvironmentRecord* outer_environment);
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
@ -36,18 +36,20 @@ public:
virtual Object* with_base_object() const override
{
if (is_with_environment())
return &m_object;
return &m_binding_object;
return nullptr;
}
bool is_with_environment() const { return m_with_environment; }
// [[BindingObject]], The binding object of this Environment Record.
Object& binding_object() { return m_binding_object; }
Object& object() { return m_object; }
// [[IsWithEnvironment]], Indicates whether this Environment Record is created for a with statement.
bool is_with_environment() const { return m_with_environment; }
private:
virtual void visit_edges(Visitor&) override;
Object& m_object;
Object& m_binding_object;
bool m_with_environment { false };
};