mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00: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
1 changed files with 12 additions and 2 deletions
|
@ -13,8 +13,14 @@
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
#define WEB_PLATFORM_OBJECT(class_, base_class) \
|
#define WEB_PLATFORM_OBJECT(class_, base_class) \
|
||||||
JS_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
|
// https://webidl.spec.whatwg.org/#dfn-platform-object
|
||||||
class PlatformObject
|
class PlatformObject
|
||||||
|
@ -30,6 +36,10 @@ public:
|
||||||
// FIXME: This should return a type that works in both window and worker contexts.
|
// FIXME: This should return a type that works in both window and worker contexts.
|
||||||
HTML::Window& global_object() const;
|
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:
|
protected:
|
||||||
explicit PlatformObject(JS::Realm&);
|
explicit PlatformObject(JS::Realm&);
|
||||||
explicit PlatformObject(JS::Object& prototype);
|
explicit PlatformObject(JS::Object& prototype);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue