LibWeb: Implement TrustedScriptURL class

This commit is contained in:
Tete17 2025-07-31 17:08:30 +02:00 committed by Luke Wilde
commit adaad653ca
Notes: github-actions[bot] 2025-08-11 11:23:01 +00:00
8 changed files with 86 additions and 0 deletions

View file

@ -899,6 +899,7 @@ set(SOURCES
SVG/ViewBox.cpp
TrustedTypes/TrustedHTML.cpp
TrustedTypes/TrustedScript.cpp
TrustedTypes/TrustedScriptURL.cpp
TrustedTypes/TrustedTypePolicy.cpp
TrustedTypes/TrustedTypePolicyFactory.cpp
UIEvents/CompositionEvent.cpp

View file

@ -1222,6 +1222,7 @@ namespace Web::TrustedTypes {
class TrustedHTML;
class TrustedScript;
class TrustedScriptURL;
class TrustedTypePolicy;
class TrustedTypePolicyFactory;
struct TrustedTypePolicyOptions;

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/TrustedTypes/TrustedScriptURL.h>
#include <LibGC/Ptr.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
namespace Web::TrustedTypes {
GC_DEFINE_ALLOCATOR(TrustedScriptURL);
TrustedScriptURL::TrustedScriptURL(JS::Realm& realm, Utf16String data)
: PlatformObject(realm)
, m_data(move(data))
{
}
void TrustedScriptURL::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(TrustedScriptURL);
Base::initialize(realm);
}
// https://w3c.github.io/trusted-types/dist/spec/#trustedscripturl-stringification-behavior
Utf16String const& TrustedScriptURL::to_string() const
{
// 1. return the associated data value.
return m_data;
}
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscripturl-tojson
Utf16String const& TrustedScriptURL::to_json() const
{
// 1. return the associated data value.
return to_string();
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/TrustedScriptURLPrototype.h>
namespace Web::TrustedTypes {
class TrustedScriptURL final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(TrustedScriptURL, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(TrustedScriptURL);
public:
virtual ~TrustedScriptURL() override = default;
Utf16String const& to_string() const;
Utf16String const& to_json() const;
private:
explicit TrustedScriptURL(JS::Realm&, Utf16String);
virtual void initialize(JS::Realm&) override;
Utf16String const m_data;
};
}

View file

@ -0,0 +1,6 @@
// https://w3c.github.io/trusted-types/dist/spec/#trused-script-url
[Exposed=(Window,Worker)]
interface TrustedScriptURL {
stringifier;
Utf16DOMString toJSON();
};

View file

@ -330,6 +330,7 @@ libweb_js_bindings(Streams/WritableStreamDefaultController)
libweb_js_bindings(Streams/WritableStreamDefaultWriter)
libweb_js_bindings(TrustedTypes/TrustedHTML)
libweb_js_bindings(TrustedTypes/TrustedScript)
libweb_js_bindings(TrustedTypes/TrustedScriptURL)
libweb_js_bindings(TrustedTypes/TrustedTypePolicy)
libweb_js_bindings(TrustedTypes/TrustedTypePolicyFactory)
libweb_js_bindings(SVG/SVGAElement)

View file

@ -118,6 +118,7 @@ static bool is_platform_object(Type const& type)
"TimeRanges"sv,
"TrustedHTML"sv,
"TrustedScript"sv,
"TrustedScriptURL"sv,
"TrustedTypePolicy"sv,
"TrustedTypePolicyFactory"sv,
"URLSearchParams"sv,

View file

@ -434,6 +434,7 @@ TransitionEvent
TreeWalker
TrustedHTML
TrustedScript
TrustedScriptURL
TrustedTypePolicy
TrustedTypePolicyFactory
TypeError