ladybird/Userland/Libraries/LibJS/Runtime/GlobalEnvironmentRecord.cpp
Andreas Kling 1f8b6ac3c3 LibJS: Begin implementing GlobalEnvironmentRecord
These represent the outermost scope in the environment record
hierarchy. The spec says they should be a "composite" of two things:

- An ObjectEnvironmentRecord wrapping the global object
- A DeclarativeEnvironmentRecord for other declarations

It's not yet clear to me how this should work, so this patch only
implements the first part, an object record wrapping the global object.
2021-06-22 18:44:53 +02:00

58 lines
1.8 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/AST.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
namespace JS {
GlobalEnvironmentRecord::GlobalEnvironmentRecord(GlobalObject& global_object)
: EnvironmentRecord(nullptr)
, m_global_object(global_object)
{
m_object_record = global_object.heap().allocate<ObjectEnvironmentRecord>(global_object, global_object, nullptr);
m_declarative_record = global_object.heap().allocate<DeclarativeEnvironmentRecord>(global_object);
}
void GlobalEnvironmentRecord::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_object_record);
visitor.visit(m_declarative_record);
}
Optional<Variable> GlobalEnvironmentRecord::get_from_environment_record(FlyString const& name) const
{
// FIXME: This should be a "composite" of the object record and the declarative record.
return m_object_record->get_from_environment_record(name);
}
void GlobalEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable)
{
// FIXME: This should be a "composite" of the object record and the declarative record.
m_object_record->put_into_environment_record(name, variable);
}
bool GlobalEnvironmentRecord::delete_from_environment_record(FlyString const& name)
{
// FIXME: This should be a "composite" of the object record and the declarative record.
return object_record().delete_property(name);
}
Value GlobalEnvironmentRecord::get_this_binding(GlobalObject&) const
{
return &m_global_object;
}
Value GlobalEnvironmentRecord::global_this_value() const
{
return &m_global_object;
}
}