LibWeb: Make HostDefined and Intrinsics free functions [[nodiscard]]

Hopefully no one else will forget to call set_prototype with the cached
prototype they just retrieved from a realm and spend a long time
wondering why their object has no properties...
This commit is contained in:
Andrew Kaster 2022-10-08 21:27:21 -06:00 committed by Andreas Kling
parent 2d5bee256e
commit 07b950d8a6
Notes: sideshowbarker 2024-07-17 06:54:15 +09:00
2 changed files with 5 additions and 5 deletions

View file

@ -27,7 +27,7 @@ struct HostDefined : public JS::Realm::HostDefined {
JS::NonnullGCPtr<Intrinsics> intrinsics;
};
inline HTML::EnvironmentSettingsObject& host_defined_environment_settings_object(JS::Realm& realm)
[[nodiscard]] inline HTML::EnvironmentSettingsObject& host_defined_environment_settings_object(JS::Realm& realm)
{
return *verify_cast<HostDefined>(realm.host_defined())->environment_settings_object;
}

View file

@ -60,24 +60,24 @@ private:
JS::NonnullGCPtr<JS::Realm> m_realm;
};
inline Intrinsics& host_defined_intrinsics(JS::Realm& realm)
[[nodiscard]] inline Intrinsics& host_defined_intrinsics(JS::Realm& realm)
{
return *verify_cast<HostDefined>(realm.host_defined())->intrinsics;
}
template<typename T>
JS::Object& ensure_web_prototype(JS::Realm& realm, String const& class_name)
[[nodiscard]] JS::Object& ensure_web_prototype(JS::Realm& realm, String const& class_name)
{
return host_defined_intrinsics(realm).ensure_web_prototype<T>(class_name);
}
template<typename T>
JS::NativeFunction& ensure_web_constructor(JS::Realm& realm, String const& class_name)
[[nodiscard]] JS::NativeFunction& ensure_web_constructor(JS::Realm& realm, String const& class_name)
{
return host_defined_intrinsics(realm).ensure_web_constructor<T>(class_name);
}
inline JS::Object& cached_web_prototype(JS::Realm& realm, String const& class_name)
[[nodiscard]] inline JS::Object& cached_web_prototype(JS::Realm& realm, String const& class_name)
{
return host_defined_intrinsics(realm).cached_web_prototype(class_name);
}