mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09: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
Notes:
sideshowbarker
2024-07-19 05:29:32 +09:00
Author: https://github.com/awesomekling
Commit: af51dc105a
57 changed files with 122 additions and 106 deletions
|
@ -32,6 +32,8 @@
|
|||
namespace JS {
|
||||
|
||||
class ErrorConstructor final : public NativeFunction {
|
||||
JS_OBJECT(ErrorConstructor, NativeFunction);
|
||||
|
||||
public:
|
||||
explicit ErrorConstructor(GlobalObject&);
|
||||
virtual void initialize(Interpreter&, GlobalObject&) override;
|
||||
|
@ -42,11 +44,12 @@ public:
|
|||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
virtual const char* class_name() const override { return "ErrorConstructor"; }
|
||||
};
|
||||
|
||||
#define DECLARE_ERROR_SUBCLASS_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
class ConstructorName final : public NativeFunction { \
|
||||
JS_OBJECT(ConstructorName, NativeFunction); \
|
||||
\
|
||||
public: \
|
||||
explicit ConstructorName(GlobalObject&); \
|
||||
virtual void initialize(Interpreter&, GlobalObject&) override; \
|
||||
|
@ -56,7 +59,6 @@ private:
|
|||
\
|
||||
private: \
|
||||
virtual bool has_constructor() const override { return true; } \
|
||||
virtual const char* class_name() const override { return #ClassName "Constructor"; } \
|
||||
};
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue