mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-11 21:52:53 +00:00
This patch adds FunctionEnvironmentRecord as a subclass of the existing DeclarativeEnvironmentRecord. Things that are specific to function environment records move into there, simplifying the base. Most of the abstract operations related to function environment records are rewritten to match the spec exactly. I also had to implement GetThisEnvironment() and GetSuperConstructor() to keep tests working after the changes, so that's nice as well. :^)
42 lines
1 KiB
C++
42 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/AST.h>
|
|
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
|
|
|
|
namespace JS {
|
|
|
|
ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& object, EnvironmentRecord* parent_scope)
|
|
: EnvironmentRecord(parent_scope)
|
|
, m_object(object)
|
|
{
|
|
}
|
|
|
|
void ObjectEnvironmentRecord::visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(&m_object);
|
|
}
|
|
|
|
Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyString const& name) const
|
|
{
|
|
auto value = m_object.get(name);
|
|
if (value.is_empty())
|
|
return {};
|
|
return Variable { value, DeclarationKind::Var };
|
|
}
|
|
|
|
void ObjectEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
|
|
{
|
|
m_object.put(name, variable.value);
|
|
}
|
|
|
|
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name)
|
|
{
|
|
return m_object.delete_property(name);
|
|
}
|
|
|
|
}
|