1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibJS: Rename virtuals in EnvironmentRecord

This patch makes the following renames:

- get_from_scope() => get_from_environment_record()
- put_to_scope() => put_into_environment_record()
- delete_from_scope() => delete_from_environment_record()
This commit is contained in:
Andreas Kling 2021-06-21 23:41:38 +02:00
parent 5edd259b0a
commit d407f247b7
10 changed files with 32 additions and 31 deletions

View file

@ -853,7 +853,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
if (interpreter.exception())
return {};
interpreter.current_scope()->put_to_scope(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
interpreter.current_scope()->put_into_environment_record(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
return {};
}

View file

@ -91,7 +91,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
if (scope_type == ScopeType::Function) {
push_scope({ scope_type, scope_node, false });
for (auto& declaration : scope_node.functions())
current_scope()->put_to_scope(declaration.name(), { js_undefined(), DeclarationKind::Var });
current_scope()->put_into_environment_record(declaration.name(), { js_undefined(), DeclarationKind::Var });
return;
}

View file

@ -52,17 +52,17 @@ void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor)
visitor.visit(it.value.value);
}
Optional<Variable> DeclarativeEnvironmentRecord::get_from_scope(FlyString const& name) const
Optional<Variable> DeclarativeEnvironmentRecord::get_from_environment_record(FlyString const& name) const
{
return m_variables.get(name);
}
void DeclarativeEnvironmentRecord::put_to_scope(FlyString const& name, Variable variable)
void DeclarativeEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
{
m_variables.set(name, variable);
}
bool DeclarativeEnvironmentRecord::delete_from_scope(FlyString const& name)
bool DeclarativeEnvironmentRecord::delete_from_environment_record(FlyString const& name)
{
return m_variables.remove(name);
}

View file

@ -37,9 +37,9 @@ public:
virtual ~DeclarativeEnvironmentRecord() override;
// ^EnvironmentRecord
virtual Optional<Variable> get_from_scope(FlyString const&) const override;
virtual void put_to_scope(FlyString const&, Variable) override;
virtual bool delete_from_scope(FlyString const&) override;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
virtual bool has_this_binding() const override;
virtual Value get_this_binding(GlobalObject&) const override;

View file

@ -19,9 +19,10 @@ class EnvironmentRecord : public Object {
JS_OBJECT(EnvironmentRecord, Object);
public:
virtual Optional<Variable> get_from_scope(FlyString const&) const = 0;
virtual void put_to_scope(FlyString const&, Variable) = 0;
virtual bool delete_from_scope(FlyString const&) = 0;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const = 0;
virtual void put_into_environment_record(FlyString const&, Variable) = 0;
virtual bool delete_from_environment_record(FlyString const&) = 0;
virtual bool has_this_binding() const = 0;
virtual Value get_this_binding(GlobalObject&) const = 0;

View file

@ -328,7 +328,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
return Value(sign * number);
}
Optional<Variable> GlobalObject::get_from_scope(const FlyString& name) const
Optional<Variable> GlobalObject::get_from_environment_record(FlyString const& name) const
{
auto value = get(name);
if (value.is_empty())
@ -336,12 +336,12 @@ Optional<Variable> GlobalObject::get_from_scope(const FlyString& name) const
return Variable { value, DeclarationKind::Var };
}
void GlobalObject::put_to_scope(const FlyString& name, Variable variable)
void GlobalObject::put_into_environment_record(FlyString const& name, Variable variable)
{
put(name, variable.value);
}
bool GlobalObject::delete_from_scope(FlyString const& name)
bool GlobalObject::delete_from_environment_record(FlyString const& name)
{
return delete_property(name);
}

View file

@ -21,9 +21,9 @@ public:
virtual ~GlobalObject() override;
virtual Optional<Variable> get_from_scope(FlyString const&) const override;
virtual void put_to_scope(FlyString const&, Variable) override;
virtual bool delete_from_scope(FlyString const&) override;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
virtual bool has_this_binding() const override;
virtual Value get_this_binding(GlobalObject&) const override;

View file

@ -21,7 +21,7 @@ void ObjectEnvironmentRecord::visit_edges(Cell::Visitor& visitor)
visitor.visit(&m_object);
}
Optional<Variable> ObjectEnvironmentRecord::get_from_scope(FlyString const& name) const
Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyString const& name) const
{
auto value = m_object.get(name);
if (value.is_empty())
@ -29,12 +29,12 @@ Optional<Variable> ObjectEnvironmentRecord::get_from_scope(FlyString const& name
return Variable { value, DeclarationKind::Var };
}
void ObjectEnvironmentRecord::put_to_scope(FlyString const& name, Variable variable)
void ObjectEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
{
m_object.put(name, variable.value);
}
bool ObjectEnvironmentRecord::delete_from_scope(FlyString const& name)
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name)
{
return m_object.delete_property(name);
}

View file

@ -16,9 +16,9 @@ class ObjectEnvironmentRecord : public EnvironmentRecord {
public:
ObjectEnvironmentRecord(Object&, EnvironmentRecord* parent_scope);
virtual Optional<Variable> get_from_scope(FlyString const&) const override;
virtual void put_to_scope(FlyString const&, Variable) override;
virtual bool delete_from_scope(FlyString const&) override;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
virtual bool has_this_binding() const override;
virtual Value get_this_binding(GlobalObject&) const override;

View file

@ -136,7 +136,7 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
Optional<Variable> possible_match;
if (!specific_scope && m_call_stack.size()) {
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
possible_match = environment_record->get_from_scope(name);
possible_match = environment_record->get_from_environment_record(name);
if (possible_match.has_value()) {
specific_scope = environment_record;
break;
@ -150,12 +150,12 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
return;
}
specific_scope->put_to_scope(name, { value, possible_match.value().declaration_kind });
specific_scope->put_into_environment_record(name, { value, possible_match.value().declaration_kind });
return;
}
if (specific_scope) {
specific_scope->put_to_scope(name, { value, DeclarationKind::Var });
specific_scope->put_into_environment_record(name, { value, DeclarationKind::Var });
return;
}
@ -168,7 +168,7 @@ bool VM::delete_variable(FlyString const& name)
Optional<Variable> possible_match;
if (!m_call_stack.is_empty()) {
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
possible_match = environment_record->get_from_scope(name);
possible_match = environment_record->get_from_environment_record(name);
if (possible_match.has_value()) {
specific_scope = environment_record;
break;
@ -182,7 +182,7 @@ bool VM::delete_variable(FlyString const& name)
return false;
VERIFY(specific_scope);
return specific_scope->delete_from_scope(name);
return specific_scope->delete_from_environment_record(name);
}
void VM::assign(const FlyString& target, Value value, GlobalObject& global_object, bool first_assignment, EnvironmentRecord* specific_scope)
@ -363,7 +363,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
// a function parameter, or by a local var declaration, we use that.
// Otherwise, we return a lazily constructed Array with all the argument values.
// FIXME: Do something much more spec-compliant.
auto possible_match = current_scope()->get_from_scope(name);
auto possible_match = current_scope()->get_from_environment_record(name);
if (possible_match.has_value())
return possible_match.value().value;
if (!call_frame().arguments_object) {
@ -377,7 +377,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
}
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
auto possible_match = environment_record->get_from_scope(name);
auto possible_match = environment_record->get_from_environment_record(name);
if (exception())
return {};
if (possible_match.has_value())
@ -396,7 +396,7 @@ Reference VM::get_reference(const FlyString& name)
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
if (is<GlobalObject>(environment_record))
break;
auto possible_match = environment_record->get_from_scope(name);
auto possible_match = environment_record->get_from_environment_record(name);
if (possible_match.has_value())
return { Reference::LocalVariable, name };
}