2020-04-15 21:58:22 +02:00
|
|
|
/*
|
2021-06-21 23:17:24 +02:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-04-15 21:58:22 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-15 21:58:22 +02:00
|
|
|
*/
|
|
|
|
|
2020-06-08 13:31:21 -05:00
|
|
|
#include <LibJS/Interpreter.h>
|
2021-06-21 23:17:24 +02:00
|
|
|
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
|
2020-06-08 13:31:21 -05:00
|
|
|
#include <LibJS/Runtime/Error.h>
|
|
|
|
#include <LibJS/Runtime/Function.h>
|
2020-09-27 15:18:55 +02:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-06-08 13:31:21 -05:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2020-04-15 21:58:22 +02:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord()
|
|
|
|
: EnvironmentRecord(nullptr)
|
2020-04-15 21:58:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecordType environment_record_type)
|
|
|
|
: EnvironmentRecord(nullptr)
|
2020-11-28 16:02:27 +01:00
|
|
|
, m_environment_record_type(environment_record_type)
|
2020-06-08 13:31:21 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-22 00:56:14 +02:00
|
|
|
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope)
|
|
|
|
: EnvironmentRecord(parent_scope)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope)
|
|
|
|
: EnvironmentRecord(parent_scope)
|
2020-04-15 21:58:22 +02:00
|
|
|
, m_variables(move(variables))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope, EnvironmentRecordType environment_record_type)
|
|
|
|
: EnvironmentRecord(parent_scope)
|
2020-11-28 16:02:27 +01:00
|
|
|
, m_environment_record_type(environment_record_type)
|
2020-06-08 13:31:21 -05:00
|
|
|
, m_variables(move(variables))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
DeclarativeEnvironmentRecord::~DeclarativeEnvironmentRecord()
|
2020-04-15 21:58:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor)
|
2020-04-15 21:58:22 +02:00
|
|
|
{
|
2021-01-28 10:13:47 +01:00
|
|
|
Base::visit_edges(visitor);
|
2020-04-15 21:58:22 +02:00
|
|
|
for (auto& it : m_variables)
|
|
|
|
visitor.visit(it.value.value);
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
Optional<Variable> DeclarativeEnvironmentRecord::get_from_environment_record(FlyString const& name) const
|
2020-04-15 21:58:22 +02:00
|
|
|
{
|
|
|
|
return m_variables.get(name);
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
void DeclarativeEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
|
2020-04-15 21:58:22 +02:00
|
|
|
{
|
2020-11-28 16:02:27 +01:00
|
|
|
m_variables.set(name, variable);
|
2020-04-15 21:58:22 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 23:41:38 +02:00
|
|
|
bool DeclarativeEnvironmentRecord::delete_from_environment_record(FlyString const& name)
|
2021-06-08 04:00:53 +03:00
|
|
|
{
|
|
|
|
return m_variables.remove(name);
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:58:22 +02:00
|
|
|
}
|