mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17: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
|
@ -32,6 +32,8 @@
|
|||
namespace JS {
|
||||
|
||||
class NativeProperty final : public Object {
|
||||
JS_OBJECT(NativeProperty, Object);
|
||||
|
||||
public:
|
||||
NativeProperty(AK::Function<Value(Interpreter&, GlobalObject&)> getter, AK::Function<void(Interpreter&, GlobalObject&, Value)> setter);
|
||||
virtual ~NativeProperty() override;
|
||||
|
@ -41,7 +43,6 @@ public:
|
|||
|
||||
private:
|
||||
virtual bool is_native_property() const override { return true; }
|
||||
virtual const char* class_name() const override { return "NativeProperty"; }
|
||||
|
||||
AK::Function<Value(Interpreter&, GlobalObject&)> m_getter;
|
||||
AK::Function<void(Interpreter&, GlobalObject&, Value)> m_setter;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue