1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:07:45 +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

@ -22,14 +22,30 @@ public:
virtual bool has_this_binding() const final { return true; }
virtual Value get_this_binding(GlobalObject&) const final;
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;
Value global_this_value() const;
// [[ObjectRecord]]
ObjectEnvironmentRecord& object_record() { return *m_object_record; }
// [[DeclarativeReco rd]]
// [[DeclarativeRecord]]
DeclarativeEnvironmentRecord& declarative_record() { return *m_declarative_record; }
bool has_var_declaration(FlyString const& name) const;
bool has_lexical_declaration(FlyString const& name) const;
bool has_restricted_global_property(FlyString const& name) const;
bool can_declare_global_var(FlyString const& name) const;
bool can_declare_global_function(FlyString const& name) const;
void create_global_var_binding(FlyString const& name, bool can_be_deleted);
void create_global_function_binding(FlyString const& name, Value, bool can_be_deleted);
private:
virtual bool is_global_environment_record() const override { return true; }
virtual void visit_edges(Visitor&) override;
@ -38,6 +54,8 @@ private:
ObjectEnvironmentRecord* m_object_record { nullptr };
DeclarativeEnvironmentRecord* m_declarative_record { nullptr };
Vector<FlyString> m_var_names;
};
template<>