LibWeb: Extend src attribute of HTMLScriptElement with TrustedTypes

The field does no longer have the Reflect and URL attributes so we
remove it from our internal unit test.
This commit is contained in:
Tete17 2025-08-06 02:28:52 +02:00 committed by Jelle Raaijmakers
parent 664a3b536a
commit f65dca1b53
Notes: github-actions[bot] 2025-09-16 08:58:57 +00:00
6 changed files with 24 additions and 3 deletions

View file

@ -661,6 +661,23 @@ WebIDL::ExceptionOr<void> HTMLScriptElement::set_text(TrustedTypes::TrustedScrip
return {};
}
// https://www.w3.org/TR/trusted-types/#the-src-idl-attribute
WebIDL::ExceptionOr<void> HTMLScriptElement::set_src(TrustedTypes::TrustedScriptURLOrString text)
{
// 1. Let value be the result of calling Get Trusted Type compliant string with
// TrustedScriptURL, thiss relevant global object, the given value, HTMLScriptElement src, and script.
auto const value = TRY(TrustedTypes::get_trusted_type_compliant_string(
TrustedTypes::TrustedTypeName::TrustedScriptURL,
HTML::relevant_global_object(*this),
text,
TrustedTypes::InjectionSink::HTMLScriptElementsrc,
TrustedTypes::Script.to_string()));
// 2. Set thiss src content attribute to value.
TRY(set_attribute(AttributeNames::src, value));
return {};
}
// https://html.spec.whatwg.org/multipage/scripting.html#dom-script-async
bool HTMLScriptElement::async() const
{

View file

@ -14,6 +14,7 @@
#include <LibWeb/HTML/Scripting/Script.h>
#include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
#include <LibWeb/TrustedTypes/TrustedScript.h>
#include <LibWeb/TrustedTypes/TrustedScriptURL.h>
namespace Web::HTML {
@ -61,6 +62,9 @@ public:
TrustedTypes::TrustedScriptOrString text() const { return child_text_content(); }
WebIDL::ExceptionOr<void> set_text(TrustedTypes::TrustedScriptOrString);
TrustedTypes::TrustedScriptURLOrString src() const { return Utf16String::from_utf8(get_attribute_value(AttributeNames::src)); }
WebIDL::ExceptionOr<void> set_src(TrustedTypes::TrustedScriptURLOrString);
[[nodiscard]] bool async() const;
void set_async(bool);

View file

@ -8,7 +8,6 @@ interface HTMLScriptElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions, Reflect] attribute DOMString type;
[CEReactions, Reflect, URL] attribute USVString src;
[CEReactions, Reflect=nomodule] attribute boolean noModule;
[CEReactions] attribute boolean async;
[CEReactions, Reflect] attribute boolean defer;
@ -20,6 +19,7 @@ interface HTMLScriptElement : HTMLElement {
// https://www.w3.org/TR/trusted-types/#enforcement-in-scripts
[CEReactions] attribute (TrustedScript or Utf16DOMString) text;
[CEReactions] attribute (TrustedScriptURL or Utf16USVString) src;
static boolean supports(DOMString type);