LibWeb: Implement is_html method for TrustedTypePolicyFactory

This is used to check the legitimacy of a TrustedHTML object.
This commit is contained in:
Tete17 2025-07-31 00:55:34 +02:00 committed by Luke Wilde
commit a73c082f36
Notes: github-actions[bot] 2025-08-11 11:23:45 +00:00
3 changed files with 11 additions and 1 deletions

View file

@ -15,6 +15,7 @@
#include <LibWeb/HTML/WindowEventHandlers.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/TrustedTypes/TrustedHTML.h>
namespace Web::TrustedTypes {
@ -132,6 +133,13 @@ void TrustedTypePolicyFactory::initialize(JS::Realm& realm)
Base::initialize(realm);
}
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-ishtml
bool TrustedTypePolicyFactory::is_html(JS::Value value)
{
// 1. Returns true if value is an instance of TrustedHTML and has an associated data value set, false otherwise.
return value.is_object() && is<TrustedHTML>(value.as_object());
}
// https://w3c.github.io/trusted-types/dist/spec/#abstract-opdef-get-trusted-type-data-for-attribute
Optional<TrustedTypeData> get_trusted_type_data_for_attribute(String const& element, String const& attribute, Optional<String> const& attribute_ns)
{

View file

@ -21,6 +21,8 @@ public:
virtual ~TrustedTypePolicyFactory() override { }
bool is_html(JS::Value);
Optional<String> get_attribute_type(String const& tag_name, String& attribute, Optional<String> element_ns, Optional<String> attr_ns);
Optional<String> get_property_type(String const& tag_name, String const& property, Optional<String> element_ns);

View file

@ -3,7 +3,7 @@
interface TrustedTypePolicyFactory {
[FIXME] TrustedTypePolicy createPolicy(
DOMString policyName, optional TrustedTypePolicyOptions policyOptions = {});
[FIXME] boolean isHTML(any value);
boolean isHTML(any value);
[FIXME] boolean isScript(any value);
[FIXME] boolean isScriptURL(any value);
[FIXME] readonly attribute TrustedHTML emptyHTML;