1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:57:35 +00:00

LibJS: Start implementing spec-compliant variable bindings

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.
This commit is contained in:
Andreas Kling 2021-06-23 12:26:37 +02:00
parent 2822da8c8f
commit 9d49a5478a
8 changed files with 360 additions and 4 deletions

View file

@ -13,6 +13,14 @@
namespace JS {
struct Binding {
Value value;
bool strict;
bool mutable_ { false };
bool can_be_deleted { false };
bool initialized { false };
};
class DeclarativeEnvironmentRecord : public EnvironmentRecord {
JS_OBJECT(DeclarativeEnvironmentRecord, EnvironmentRecord);
@ -40,6 +48,14 @@ public:
EnvironmentRecordType type() const { return m_environment_record_type; }
virtual bool has_binding(FlyString const& name) const override;
virtual void create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override;
virtual void create_immutable_binding(GlobalObject&, FlyString const& name, bool strict) override;
virtual void initialize_binding(GlobalObject&, FlyString const& name, Value) override;
virtual void set_mutable_binding(GlobalObject&, FlyString const& name, Value, bool strict) override;
virtual Value get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
virtual bool delete_binding(GlobalObject&, FlyString const& name) override;
protected:
virtual void visit_edges(Visitor&) override;
@ -48,6 +64,7 @@ private:
EnvironmentRecordType m_environment_record_type : 8 { EnvironmentRecordType::Declarative };
HashMap<FlyString, Variable> m_variables;
HashMap<FlyString, Binding> m_bindings;
};
template<>