mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibJS+LibWeb: Add fast_is<T> helpers for Realm::HostDefined class family
This commit is contained in:
parent
a9e415b3c4
commit
f35069d63b
Notes:
github-actions[bot]
2025-04-18 12:47:43 +00:00
Author: https://github.com/awesomekling
Commit: f35069d63b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4395
4 changed files with 18 additions and 4 deletions
|
@ -30,6 +30,12 @@ public:
|
||||||
virtual ~HostDefined() = default;
|
virtual ~HostDefined() = default;
|
||||||
|
|
||||||
virtual void visit_edges(Cell::Visitor&) { }
|
virtual void visit_edges(Cell::Visitor&) { }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool fast_is() const = delete;
|
||||||
|
|
||||||
|
virtual bool is_principal_host_defined() const { return false; }
|
||||||
|
virtual bool is_synthetic_host_defined() const { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
|
|
|
@ -31,8 +31,8 @@ bool Intrinsics::is_exposed(StringView name) const
|
||||||
|
|
||||||
Intrinsics& host_defined_intrinsics(JS::Realm& realm)
|
Intrinsics& host_defined_intrinsics(JS::Realm& realm)
|
||||||
{
|
{
|
||||||
VERIFY(realm.host_defined());
|
ASSERT(realm.host_defined());
|
||||||
return as<Bindings::HostDefined>(*realm.host_defined()).intrinsics;
|
return static_cast<Bindings::HostDefined&>(*realm.host_defined()).intrinsics;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
struct PrincipalHostDefined : public HostDefined {
|
struct PrincipalHostDefined final : public HostDefined {
|
||||||
PrincipalHostDefined(GC::Ref<HTML::EnvironmentSettingsObject> eso, GC::Ref<Intrinsics> intrinsics, GC::Ref<Page> page)
|
PrincipalHostDefined(GC::Ref<HTML::EnvironmentSettingsObject> eso, GC::Ref<Intrinsics> intrinsics, GC::Ref<Page> page)
|
||||||
: HostDefined(intrinsics)
|
: HostDefined(intrinsics)
|
||||||
, environment_settings_object(eso)
|
, environment_settings_object(eso)
|
||||||
|
@ -23,6 +23,7 @@ struct PrincipalHostDefined : public HostDefined {
|
||||||
}
|
}
|
||||||
virtual ~PrincipalHostDefined() override = default;
|
virtual ~PrincipalHostDefined() override = default;
|
||||||
virtual void visit_edges(JS::Cell::Visitor& visitor) override;
|
virtual void visit_edges(JS::Cell::Visitor& visitor) override;
|
||||||
|
virtual bool is_principal_host_defined() const override { return true; }
|
||||||
|
|
||||||
GC::Ref<HTML::EnvironmentSettingsObject> environment_settings_object;
|
GC::Ref<HTML::EnvironmentSettingsObject> environment_settings_object;
|
||||||
GC::Ref<Page> page;
|
GC::Ref<Page> page;
|
||||||
|
@ -44,3 +45,6 @@ struct PrincipalHostDefined : public HostDefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool JS::Realm::HostDefined::fast_is<Web::Bindings::PrincipalHostDefined>() const { return is_principal_host_defined(); }
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
struct SyntheticHostDefined : public HostDefined {
|
struct SyntheticHostDefined final : public HostDefined {
|
||||||
SyntheticHostDefined(HTML::SyntheticRealmSettings synthetic_realm_settings, GC::Ref<Intrinsics> intrinsics)
|
SyntheticHostDefined(HTML::SyntheticRealmSettings synthetic_realm_settings, GC::Ref<Intrinsics> intrinsics)
|
||||||
: HostDefined(intrinsics)
|
: HostDefined(intrinsics)
|
||||||
, synthetic_realm_settings(move(synthetic_realm_settings))
|
, synthetic_realm_settings(move(synthetic_realm_settings))
|
||||||
|
@ -22,8 +22,12 @@ struct SyntheticHostDefined : public HostDefined {
|
||||||
|
|
||||||
virtual ~SyntheticHostDefined() override = default;
|
virtual ~SyntheticHostDefined() override = default;
|
||||||
virtual void visit_edges(JS::Cell::Visitor& visitor) override;
|
virtual void visit_edges(JS::Cell::Visitor& visitor) override;
|
||||||
|
virtual bool is_synthetic_host_defined() const override { return true; }
|
||||||
|
|
||||||
HTML::SyntheticRealmSettings synthetic_realm_settings;
|
HTML::SyntheticRealmSettings synthetic_realm_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool JS::Realm::HostDefined::fast_is<Web::Bindings::SyntheticHostDefined>() const { return is_synthetic_host_defined(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue