mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
LibJS+LibWeb: Add JS::Object::inherits(class_name)
To allow implementing the DOM class hierarchy in JS bindings, this patch adds an inherits() function that can be used to ask an Object if it inherits from a specific C++ class (by name). The necessary overrides are baked into each Object subclass by the new JS_OBJECT macro, which works similarly to C_OBJECT in LibCore. Thanks to @Dexesttp for suggesting this approach. :^)
This commit is contained in:
parent
1914f52371
commit
af51dc105a
57 changed files with 122 additions and 106 deletions
|
@ -39,6 +39,12 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
#define JS_OBJECT(class_, base_class) \
|
||||
public: \
|
||||
using Base = base_class; \
|
||||
virtual const char* class_name() const override { return #class_; } \
|
||||
virtual bool inherits(const StringView& class_name) const override { return class_name == #class_ || Base::inherits(class_name); }
|
||||
|
||||
struct PropertyDescriptor {
|
||||
PropertyAttributes attributes;
|
||||
Value value;
|
||||
|
@ -60,6 +66,8 @@ public:
|
|||
virtual void initialize(Interpreter&, GlobalObject&) override;
|
||||
virtual ~Object();
|
||||
|
||||
virtual bool inherits(const StringView& class_name) const { return class_name == this->class_name(); }
|
||||
|
||||
enum class GetOwnPropertyMode {
|
||||
Key,
|
||||
Value,
|
||||
|
@ -111,8 +119,6 @@ public:
|
|||
virtual bool is_symbol_object() const { return false; }
|
||||
virtual bool is_bigint_object() const { return false; }
|
||||
|
||||
virtual bool is_web_wrapper() const { return false; }
|
||||
|
||||
virtual const char* class_name() const override { return "Object"; }
|
||||
virtual void visit_children(Cell::Visitor&) override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue