1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00
serenity/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.h
Andreas Kling aabd82d508 LibJS: Bring function environment records closer to the spec
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. :^)
2021-06-22 18:44:53 +02:00

43 lines
1.1 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Object.h>
namespace JS {
struct Variable {
Value value;
DeclarationKind declaration_kind;
};
class EnvironmentRecord : public Object {
JS_OBJECT(EnvironmentRecord, Object);
public:
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 { return false; }
virtual Value get_this_binding(GlobalObject&) const { return {}; }
// [[OuterEnv]]
EnvironmentRecord* outer_environment() { return m_outer_environment; }
EnvironmentRecord const* outer_environment() const { return m_outer_environment; }
protected:
explicit EnvironmentRecord(EnvironmentRecord* parent);
explicit EnvironmentRecord(GlobalObjectTag);
virtual void visit_edges(Visitor&) override;
private:
EnvironmentRecord* m_outer_environment { nullptr };
};
}