LibWeb: Extend set_text of HTMLScriptElement to accommodate TrustedTypes

This commit is contained in:
Tete17 2025-08-05 21:58:13 +02:00 committed by Jelle Raaijmakers
parent b4df857a57
commit 664a3b536a
Notes: github-actions[bot] 2025-09-16 08:59:04 +00:00
7 changed files with 46 additions and 3 deletions

View file

@ -24,6 +24,8 @@
#include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/MimeSniff/MimeType.h>
#include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h>
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
namespace Web::HTML {
@ -639,6 +641,26 @@ void HTMLScriptElement::unmark_as_parser_inserted(Badge<DOM::Range>)
m_parser_document = nullptr;
}
// https://www.w3.org/TR/trusted-types/#the-text-idl-attribute
WebIDL::ExceptionOr<void> HTMLScriptElement::set_text(TrustedTypes::TrustedScriptOrString text)
{
// 1. Let value be the result of calling Get Trusted Type compliant string with
// TrustedScript, thiss relevant global object, the given value, HTMLScriptElement text, and script.
auto const value = TRY(get_trusted_type_compliant_string(
TrustedTypes::TrustedTypeName::TrustedScript,
HTML::relevant_global_object(*this),
text,
TrustedTypes::InjectionSink::HTMLScriptElementtext,
TrustedTypes::Script.to_string()));
// 2. Set thiss script text value to the given value.
m_script_text = value;
// 3. String replace all with the given value within this.
string_replace_all(value);
return {};
}
// https://html.spec.whatwg.org/multipage/scripting.html#dom-script-async
bool HTMLScriptElement::async() const
{