2021-06-21 23:17:24 +02:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyString const& name) const
|
2021-06-21 23:17:24 +02:00
|
|
|
{
|
|
|
|
auto value = m_object.get(name);
|
|
|
|
if (value.is_empty())
|
|
|
|
return {};
|
|
|
|
return Variable { value, DeclarationKind::Var };
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
void ObjectEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
|
2021-06-21 23:17:24 +02:00
|
|
|
{
|
|
|
|
m_object.put(name, variable.value);
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name)
|
2021-06-21 23:17:24 +02:00
|
|
|
{
|
|
|
|
return m_object.delete_property(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|