mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
LibWeb: Add PlatformObject::implements_interface(String)
This can be used to ask a PlatformObject if it implements a given IDL interface. It's implemented by a chain of virtual overrides that get inserted for each subclass by the WEB_PLATFORM_OBJECT macro.
This commit is contained in:
parent
00a98c24a2
commit
12ddeeb9ce
Notes:
sideshowbarker
2024-07-17 03:50:57 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/12ddeeb9ce Pull-request: https://github.com/SerenityOS/serenity/pull/16249 Reviewed-by: https://github.com/AnthonyIacono Reviewed-by: https://github.com/AtkinsSJ ✅
@ -13,8 +13,14 @@
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
#define WEB_PLATFORM_OBJECT(class_, base_class) \
|
||||
JS_OBJECT(class_, base_class)
|
||||
#define WEB_PLATFORM_OBJECT(class_, base_class) \
|
||||
JS_OBJECT(class_, base_class) \
|
||||
virtual bool implements_interface(String const& interface) const override \
|
||||
{ \
|
||||
if (interface == #class_) \
|
||||
return true; \
|
||||
return Base::implements_interface(interface); \
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#dfn-platform-object
|
||||
class PlatformObject
|
||||
@ -30,6 +36,10 @@ public:
|
||||
// FIXME: This should return a type that works in both window and worker contexts.
|
||||
HTML::Window& global_object() const;
|
||||
|
||||
// https://webidl.spec.whatwg.org/#implements
|
||||
// This is implemented by overrides that get generated by the WEB_PLATFORM_OBJECT macro.
|
||||
[[nodiscard]] virtual bool implements_interface(String const&) const { return false; }
|
||||
|
||||
protected:
|
||||
explicit PlatformObject(JS::Realm&);
|
||||
explicit PlatformObject(JS::Object& prototype);
|
||||
|
Loading…
Reference in New Issue
Block a user