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

LibJS: Implement basic support for the "delete" operator

It turns out "delete" is actually a unary op :)
This patch implements deletion of object properties, it doesn't yet
work for casually deleting properties from the global object.

When deleting a property from an object, we switch that object to
having a unique shape, no longer sharing shapes with others.
Once an object has a unique shape, it no longer needs to care about
shape transitions.
This commit is contained in:
Andreas Kling 2020-04-26 13:53:40 +02:00
parent 1617be1e6f
commit f897c41092
9 changed files with 190 additions and 8 deletions

View file

@ -78,6 +78,9 @@ public:
Shape* create_configure_transition(const FlyString& name, u8 attributes);
Shape* create_prototype_transition(Object* new_prototype);
bool is_unique() const { return m_unique; }
Shape* create_unique_clone() const;
Object* prototype() { return m_prototype; }
const Object* prototype() const { return m_prototype; }
@ -87,6 +90,10 @@ public:
void set_prototype_without_transition(Object* new_prototype) { m_prototype = new_prototype; }
void remove_property_from_unique_shape(const FlyString&, size_t offset);
void add_property_to_unique_shape(const FlyString&, u8 attributes);
void reconfigure_property_in_unique_shape(const FlyString& property_name, u8 attributes);
private:
virtual const char* class_name() const override { return "Shape"; }
virtual void visit_children(Visitor&) override;
@ -99,6 +106,7 @@ private:
Shape* m_previous { nullptr };
FlyString m_property_name;
u8 m_attributes { 0 };
bool m_unique { false };
Object* m_prototype { nullptr };
TransitionType m_transition_type { TransitionType::Invalid };
};