mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02: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:
Notes:
sideshowbarker
2024-07-19 05:29:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/af51dc105a1
@@ -31,6 +31,8 @@
|
||||
namespace JS {
|
||||
|
||||
class StringConstructor final : public NativeFunction {
|
||||
JS_OBJECT(StringConstructor, NativeFunction);
|
||||
|
||||
public:
|
||||
explicit StringConstructor(GlobalObject&);
|
||||
virtual void initialize(Interpreter&, GlobalObject&) override;
|
||||
@@ -41,7 +43,6 @@ public:
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
virtual const char* class_name() const override { return "StringConstructor"; }
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(raw);
|
||||
JS_DECLARE_NATIVE_FUNCTION(from_char_code);
|
||||
|
||||
Reference in New Issue
Block a user