mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:38:10 +00:00

This patch adds the concept of variable bindings to the various environment record classes. The bindings are not yet hooked up to anything, this is just fleshing out all the operations. Most of this is following the spec exactly, but in a few cases we are missing the requisite abstract operations to do the exact right thing. I've added FIXME's in those cases where I noticed it.
50 lines
1.9 KiB
C++
50 lines
1.9 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 {}; }
|
|
|
|
virtual bool has_binding([[maybe_unused]] FlyString const& name) const { return false; }
|
|
virtual void create_mutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool can_be_deleted) { }
|
|
virtual void create_immutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { }
|
|
virtual void initialize_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, Value) { }
|
|
virtual void set_mutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, Value, [[maybe_unused]] bool strict) { }
|
|
virtual Value get_binding_value(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return {}; }
|
|
virtual bool delete_binding(GlobalObject&, [[maybe_unused]] FlyString const& name) { return false; }
|
|
|
|
// [[OuterEnv]]
|
|
EnvironmentRecord* outer_environment() { return m_outer_environment; }
|
|
EnvironmentRecord const* outer_environment() const { return m_outer_environment; }
|
|
|
|
protected:
|
|
explicit EnvironmentRecord(EnvironmentRecord* parent);
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
private:
|
|
EnvironmentRecord* m_outer_environment { nullptr };
|
|
};
|
|
|
|
}
|