mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
LibJS: Add ObjectEnvironmentRecord.[[IsWithEnvironment]] field
This is true for environments created by `with` statements, and false for other (global) object environments. Also add the WithBaseObject abstract operation while we're here.
This commit is contained in:
parent
3f8857cd21
commit
0cd65b55bd
5 changed files with 22 additions and 7 deletions
|
@ -14,7 +14,11 @@ class ObjectEnvironmentRecord : public EnvironmentRecord {
|
|||
JS_ENVIRONMENT_RECORD(ObjectEnvironmentRecord, EnvironmentRecord);
|
||||
|
||||
public:
|
||||
ObjectEnvironmentRecord(Object&, EnvironmentRecord* parent_scope);
|
||||
enum class IsWithEnvironment {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
ObjectEnvironmentRecord(Object&, IsWithEnvironment, EnvironmentRecord* parent_scope);
|
||||
|
||||
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
|
||||
virtual void put_into_environment_record(FlyString const&, Variable) override;
|
||||
|
@ -28,12 +32,23 @@ public:
|
|||
virtual Value get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
|
||||
virtual bool delete_binding(GlobalObject&, FlyString const& name) override;
|
||||
|
||||
// 9.1.1.2.10 WithBaseObject ( ), https://tc39.es/ecma262/#sec-object-environment-records-withbaseobject
|
||||
virtual Object* with_base_object() const override
|
||||
{
|
||||
if (is_with_environment())
|
||||
return &m_object;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool is_with_environment() const { return m_with_environment; }
|
||||
|
||||
Object& object() { return m_object; }
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
Object& m_object;
|
||||
bool m_with_environment { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue