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:
Andreas Kling 2022-11-29 20:45:35 +01:00
parent 00a98c24a2
commit 12ddeeb9ce
Notes: sideshowbarker 2024-07-17 03:50:57 +09:00

View File

@ -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);