2020-11-28 16:02:27 +01:00
|
|
|
/*
|
2021-06-21 23:17:24 +02:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-11-28 16:02:27 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-28 16:02:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
|
|
struct Variable {
|
|
|
|
|
Value value;
|
|
|
|
|
DeclarationKind declaration_kind;
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-21 23:17:24 +02:00
|
|
|
class EnvironmentRecord : public Object {
|
|
|
|
|
JS_OBJECT(EnvironmentRecord, Object);
|
2020-11-28 16:02:27 +01:00
|
|
|
|
|
|
|
|
public:
|
2021-06-21 23:26:50 +02:00
|
|
|
virtual Optional<Variable> get_from_scope(FlyString const&) const = 0;
|
|
|
|
|
virtual void put_to_scope(FlyString const&, Variable) = 0;
|
2021-06-08 04:00:53 +03:00
|
|
|
virtual bool delete_from_scope(FlyString const&) = 0;
|
2020-11-28 16:02:27 +01:00
|
|
|
virtual bool has_this_binding() const = 0;
|
|
|
|
|
virtual Value get_this_binding(GlobalObject&) const = 0;
|
|
|
|
|
|
2021-06-21 23:35:30 +02:00
|
|
|
// [[OuterEnv]]
|
|
|
|
|
EnvironmentRecord* outer_environment() { return m_outer_environment; }
|
|
|
|
|
EnvironmentRecord const* outer_environment() const { return m_outer_environment; }
|
2020-11-28 16:02:27 +01:00
|
|
|
|
|
|
|
|
protected:
|
2021-06-21 23:17:24 +02:00
|
|
|
explicit EnvironmentRecord(EnvironmentRecord* parent);
|
|
|
|
|
explicit EnvironmentRecord(GlobalObjectTag);
|
2020-11-28 16:02:27 +01:00
|
|
|
|
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
|
|
|
|
|
private:
|
2021-06-21 23:35:30 +02:00
|
|
|
EnvironmentRecord* m_outer_environment { nullptr };
|
2020-11-28 16:02:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|