1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS: Add a mechanism for callback-based object properties

This patch adds NativeProperty, which can be used to implement object
properties that have C++ getters and/or setters.

Use this to move String.prototype.length to its correct place. :^)
This commit is contained in:
Andreas Kling 2020-03-15 18:15:44 +01:00
parent bb57bc1b42
commit 3163929990
7 changed files with 125 additions and 2 deletions

View file

@ -42,10 +42,12 @@ public:
void put(String property_name, Value);
void put_native_function(String property_name, AK::Function<Value(Interpreter&, Vector<Value>)>);
void put_native_property(String property_name, AK::Function<Value(Object*)> getter, AK::Function<void(Object*, Value)> setter);
virtual bool is_function() const { return false; }
virtual bool is_native_function() const { return false; }
virtual bool is_string_object() const { return false; }
virtual bool is_native_property() const { return false; }
virtual const char* class_name() const override { return "Object"; }
virtual void visit_children(Cell::Visitor&) override;