Truly independent web browser
LibWeb: Implement the Trusted Types value interfaces in Rust
Shannon Boothf0891af4cb36
diff --git a/Libraries/LibWeb/Bindings/Rust/src/lib.rs b/Libraries/LibWeb/Bindings/Rust/src/lib.rsindex 9806b94b697..a4b1b88c36a 100644--- a/Libraries/LibWeb/Bindings/Rust/src/lib.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/lib.rs@@ -255,6 +255,16 @@ pub(crate) mod storage_api;)]pub(crate) mod streams;#[cfg(not(test))]+#[cfg_attr(+ not(web_idl_bindings),+ allow(dead_code, reason = "only the generated bindings use the interfaces")+)]+#[allow(+ clippy::unnecessary_wraps,+ reason = "the bindings call every attribute and operation as one that can throw"+)]+pub(crate) mod trusted_types;+#[cfg(not(test))]pub(crate) mod ui_events;#[cfg_attr(not(web_idl_bindings),diff --git a/Libraries/LibWeb/Bindings/Rust/src/trusted_types/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/mod.rsnew file mode 100644index 00000000000..a71ef4c2bff--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/mod.rs@@ -0,0 +1,11 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! Trusted Types, https://w3c.github.io/trusted-types/dist/spec/++pub(crate) mod trusted_html;+pub(crate) mod trusted_script;+pub(crate) mod trusted_script_url;diff --git a/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_html.rs b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_html.rsnew file mode 100644index 00000000000..30d47793ee4--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_html.rs@@ -0,0 +1,70 @@+/*+ * Copyright (c) 2025, Miguel Sacristán Izcue <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! TrustedHTML, https://w3c.github.io/trusted-types/dist/spec/#trusted-html++use core::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::{Trace, Vm};++use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};+use crate::bindings::{CallContext, WebIdlResult};++/// https://w3c.github.io/trusted-types/dist/spec/#trusted-html+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct TrustedHTML {+ data: Utf16String,+}++impl Wrappable for TrustedHTML {}++impl TrustedHTML {+ pub(crate) fn create(vm: &Vm, data: Utf16String) -> Ref<Self> {+ allocate(vm, |_| Self { data })+ }++ pub(crate) fn data(&self) -> &Utf16String {+ &self.data+ }++ // https://w3c.github.io/trusted-types/dist/spec/#trustedhtml-stringification-behavior+ pub(crate) fn to_string(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ // 1. return the associated data value.+ Ok(self.data.clone())+ }++ // https://w3c.github.io/trusted-types/dist/spec/#dom-trustedhtml-tojson+ pub(crate) fn to_json(&self, cx: &mut CallContext) -> WebIdlResult<Utf16String> {+ // 1. return the associated data value.+ self.to_string(cx)+ }+}++/// A new TrustedHTML with the data, a raw AK::Utf16String that C++ hands over.+///+/// # Safety+///+/// `vm` must be the live VM, and `data` a raw string that C++ hands over.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_create_trusted_html(vm: *mut c_void, data: usize) -> *mut c_void {+ // SAFETY: The caller passes the live VM and hands over the string.+ let (vm, data) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(data)) };+ cell_into_abi(TrustedHTML::create(vm, data))+}++/// The associated data of the TrustedHTML, a raw AK::Utf16String that the call lends for as long as the object lives.+///+/// # Safety+///+/// `cell` must be the live cell of a TrustedHTML.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_trusted_html_data(cell: *mut c_void) -> usize {+ // SAFETY: The caller passes a live cell.+ unsafe { cell_from_abi::<TrustedHTML>(cell) }.data().raw_identity()+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script.rs b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script.rsnew file mode 100644index 00000000000..b83b125e980--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script.rs@@ -0,0 +1,70 @@+/*+ * Copyright (c) 2025, Miguel Sacristán Izcue <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! TrustedScript, https://w3c.github.io/trusted-types/dist/spec/#trusted-script++use core::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::{Trace, Vm};++use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};+use crate::bindings::{CallContext, WebIdlResult};++/// https://w3c.github.io/trusted-types/dist/spec/#trusted-script+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct TrustedScript {+ data: Utf16String,+}++impl Wrappable for TrustedScript {}++impl TrustedScript {+ pub(crate) fn create(vm: &Vm, data: Utf16String) -> Ref<Self> {+ allocate(vm, |_| Self { data })+ }++ pub(crate) fn data(&self) -> &Utf16String {+ &self.data+ }++ // https://w3c.github.io/trusted-types/dist/spec/#trustedscript-stringification-behavior+ pub(crate) fn to_string(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ // 1. return the associated data value.+ Ok(self.data.clone())+ }++ // https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscript-tojson+ pub(crate) fn to_json(&self, cx: &mut CallContext) -> WebIdlResult<Utf16String> {+ // 1. return the associated data value.+ self.to_string(cx)+ }+}++/// A new TrustedScript with the data, a raw AK::Utf16String that C++ hands over.+///+/// # Safety+///+/// `vm` must be the live VM, and `data` a raw string that C++ hands over.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_create_trusted_script(vm: *mut c_void, data: usize) -> *mut c_void {+ // SAFETY: The caller passes the live VM and hands over the string.+ let (vm, data) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(data)) };+ cell_into_abi(TrustedScript::create(vm, data))+}++/// The associated data of the TrustedScript, a raw AK::Utf16String that the call lends for as long as the object lives.+///+/// # Safety+///+/// `cell` must be the live cell of a TrustedScript.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_trusted_script_data(cell: *mut c_void) -> usize {+ // SAFETY: The caller passes a live cell.+ unsafe { cell_from_abi::<TrustedScript>(cell) }.data().raw_identity()+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script_url.rs b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script_url.rsnew file mode 100644index 00000000000..1b7565db594--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/trusted_types/trusted_script_url.rs@@ -0,0 +1,71 @@+/*+ * Copyright (c) 2025, Miguel Sacristán Izcue <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! TrustedScriptURL, https://w3c.github.io/trusted-types/dist/spec/#trused-script-url++use core::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::{Trace, Vm};++use crate::bindings::conversions::UsvString;+use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};+use crate::bindings::{CallContext, WebIdlResult};++/// https://w3c.github.io/trusted-types/dist/spec/#trused-script-url+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct TrustedScriptURL {+ data: Utf16String,+}++impl Wrappable for TrustedScriptURL {}++impl TrustedScriptURL {+ pub(crate) fn create(vm: &Vm, data: Utf16String) -> Ref<Self> {+ allocate(vm, |_| Self { data })+ }++ pub(crate) fn data(&self) -> &Utf16String {+ &self.data+ }++ // https://w3c.github.io/trusted-types/dist/spec/#trustedscripturl-stringification-behavior+ pub(crate) fn to_string(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ // 1. return the associated data value.+ Ok(self.data.clone())+ }++ // https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscripturl-tojson+ pub(crate) fn to_json(&self, cx: &mut CallContext) -> WebIdlResult<UsvString> {+ // 1. return the associated data value.+ Ok(UsvString::from_utf16_string(&self.to_string(cx)?))+ }+}++/// A new TrustedScriptURL with the data, a raw AK::Utf16String that C++ hands over.+///+/// # Safety+///+/// `vm` must be the live VM, and `data` a raw string that C++ hands over.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_create_trusted_script_url(vm: *mut c_void, data: usize) -> *mut c_void {+ // SAFETY: The caller passes the live VM and hands over the string.+ let (vm, data) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(data)) };+ cell_into_abi(TrustedScriptURL::create(vm, data))+}++/// The associated data of the TrustedScriptURL, a raw AK::Utf16String that the call lends for as long as the object lives.+///+/// # Safety+///+/// `cell` must be the live cell of a TrustedScriptURL.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_trusted_types_trusted_script_url_data(cell: *mut c_void) -> usize {+ // SAFETY: The caller passes a live cell.+ unsafe { cell_from_abi::<TrustedScriptURL>(cell) }.data().raw_identity()+}diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 7dd61d4d183..6848a06b5b5 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -13305,9 +13305,9 @@ static WebIDL::ExceptionOr<Utf16String> document_write_compliant_string(DOM::Docfor (auto const& value : text) {string.append(value.visit(// 1. If value is a TrustedHTML object, then append value's associated data to string.- [](GC::Root<TrustedTypes::TrustedHTML> const& value) -> Utf16String const& { return value->to_string(); },+ [](GC::Root<TrustedTypes::TrustedHTML> const& value) { return value->to_string(); },// 2. Otherwise, append value to string.- [](Utf16String const& value) -> Utf16String const& { return value; }));+ [](Utf16String const& value) { return value; }));}// 4. If isTrusted is false, set string to the result of invoking the Get Trusted Type compliant string algorithmdiff --git a/Libraries/LibWeb/TrustedTypes/TrustedHTML.cpp b/Libraries/LibWeb/TrustedTypes/TrustedHTML.cppindex 3393a45d202..e6efcf86877 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedHTML.cpp+++ b/Libraries/LibWeb/TrustedTypes/TrustedHTML.cpp@@ -4,31 +4,26 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/TrustedTypes/TrustedHTML.h>-#include <LibGC/Ptr.h>-namespace Web::TrustedTypes {-GC_DEFINE_ALLOCATOR(TrustedHTML);--TrustedHTML::TrustedHTML(Utf16String data)- : m_data(move(data))-{+extern "C" {+// Defined in Bindings/Rust/src/trusted_types/trusted_html.rs.+TrustedHTML* web_rust_trusted_types_create_trusted_html(JSVM*, FlatPtr data);+FlatPtr web_rust_trusted_types_trusted_html_data(TrustedHTML*);}-// https://w3c.github.io/trusted-types/dist/spec/#trustedhtml-stringification-behavior-Utf16String const& TrustedHTML::to_string() const+GC::Ref<TrustedHTML> TrustedHTML::create(Utf16String data){- // 1. return the associated data value.- return m_data;+ return *web_rust_trusted_types_create_trusted_html(JS::HostABI::vm_to_abi(JS::VM::the()), move(data).into_raw());}-// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedhtml-tojson-Utf16String const& TrustedHTML::to_json() const+Utf16String TrustedHTML::to_string() const{- // 1. return the associated data value.- return to_string();+ return Utf16String::from_raw(web_rust_trusted_types_trusted_html_data(const_cast<TrustedHTML*>(this)));}}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedHTML.h b/Libraries/LibWeb/TrustedTypes/TrustedHTML.hindex 502492ce5d5..dd4544f67b1 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedHTML.h+++ b/Libraries/LibWeb/TrustedTypes/TrustedHTML.h@@ -8,26 +8,20 @@#include <AK/Utf16String.h>#include <AK/Variant.h>-#include <LibWeb/Bindings/Wrappable.h>+#include <LibWeb/Bindings/RustInterface.h>+#include <LibWeb/Bindings/TrustedHTML.h>namespace Web::TrustedTypes {using TrustedHTMLOrString = Variant<GC::Ref<TrustedHTML>, Utf16String>;-class TrustedHTML final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(TrustedHTML, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(TrustedHTML);+class TrustedHTML final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(TrustedHTML, trusted_html)public:- virtual ~TrustedHTML() override = default;+ [[nodiscard]] static GC::Ref<TrustedHTML> create(Utf16String data);- Utf16String const& to_string() const;- Utf16String const& to_json() const;--private:- explicit TrustedHTML(Utf16String);-- Utf16String const m_data;+ Utf16String to_string() const;};}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedHTML.idl b/Libraries/LibWeb/TrustedTypes/TrustedHTML.idlindex a404347d00d..03d23744bee 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedHTML.idl+++ b/Libraries/LibWeb/TrustedTypes/TrustedHTML.idl@@ -1,5 +1,5 @@// https://w3c.github.io/trusted-types/dist/spec/#trusted-html-[Exposed=(Window,Worker)]+[Exposed=(Window,Worker), ImplementedIn=Rust]interface TrustedHTML {stringifier;DOMString toJSON();diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScript.cpp b/Libraries/LibWeb/TrustedTypes/TrustedScript.cppindex b8ccda930bb..d7cee17a852 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScript.cpp+++ b/Libraries/LibWeb/TrustedTypes/TrustedScript.cpp@@ -4,31 +4,26 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/TrustedTypes/TrustedScript.h>-#include <LibGC/Ptr.h>-namespace Web::TrustedTypes {-GC_DEFINE_ALLOCATOR(TrustedScript);--TrustedScript::TrustedScript(Utf16String data)- : m_data(move(data))-{+extern "C" {+// Defined in Bindings/Rust/src/trusted_types/trusted_script.rs.+TrustedScript* web_rust_trusted_types_create_trusted_script(JSVM*, FlatPtr data);+FlatPtr web_rust_trusted_types_trusted_script_data(TrustedScript*);}-// https://w3c.github.io/trusted-types/dist/spec/#trustedscript-stringification-behavior-Utf16String const& TrustedScript::to_string() const+GC::Ref<TrustedScript> TrustedScript::create(Utf16String data){- // 1. return the associated data value.- return m_data;+ return *web_rust_trusted_types_create_trusted_script(JS::HostABI::vm_to_abi(JS::VM::the()), move(data).into_raw());}-// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscript-tojson-Utf16String const& TrustedScript::to_json() const+Utf16String TrustedScript::to_string() const{- // 1. return the associated data value.- return to_string();+ return Utf16String::from_raw(web_rust_trusted_types_trusted_script_data(const_cast<TrustedScript*>(this)));}}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScript.h b/Libraries/LibWeb/TrustedTypes/TrustedScript.hindex 50bea9b98f3..286314f1a44 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScript.h+++ b/Libraries/LibWeb/TrustedTypes/TrustedScript.h@@ -8,27 +8,21 @@#include <AK/Utf16String.h>#include <AK/Variant.h>-#include <LibWeb/Bindings/Wrappable.h>+#include <LibWeb/Bindings/RustInterface.h>+#include <LibWeb/Bindings/TrustedScript.h>namespace Web::TrustedTypes {using TrustedScriptOrString = Variant<GC::Ref<TrustedScript>, Utf16String>;using NullableTrustedScriptOrString = Variant<GC::Ref<TrustedScript>, Utf16String, Empty>;-class TrustedScript final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(TrustedScript, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(TrustedScript);+class TrustedScript final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(TrustedScript, trusted_script)public:- virtual ~TrustedScript() override = default;+ [[nodiscard]] static GC::Ref<TrustedScript> create(Utf16String data);- Utf16String const& to_string() const;- Utf16String const& to_json() const;--private:- explicit TrustedScript(Utf16String);-- Utf16String const m_data;+ Utf16String to_string() const;};}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScript.idl b/Libraries/LibWeb/TrustedTypes/TrustedScript.idlindex c49e852c92d..0d77bccb0ab 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScript.idl+++ b/Libraries/LibWeb/TrustedTypes/TrustedScript.idl@@ -1,5 +1,5 @@// https://w3c.github.io/trusted-types/dist/spec/#trusted-script-[Exposed=(Window,Worker)]+[Exposed=(Window,Worker), ImplementedIn=Rust]interface TrustedScript {stringifier;DOMString toJSON();diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cpp b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cppindex 21075f50332..eda13540f79 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cpp+++ b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cpp@@ -4,31 +4,26 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/TrustedTypes/TrustedScriptURL.h>-#include <LibGC/Ptr.h>-namespace Web::TrustedTypes {-GC_DEFINE_ALLOCATOR(TrustedScriptURL);--TrustedScriptURL::TrustedScriptURL(Utf16String data)- : m_data(move(data))-{+extern "C" {+// Defined in Bindings/Rust/src/trusted_types/trusted_script_url.rs.+TrustedScriptURL* web_rust_trusted_types_create_trusted_script_url(JSVM*, FlatPtr data);+FlatPtr web_rust_trusted_types_trusted_script_url_data(TrustedScriptURL*);}-// https://w3c.github.io/trusted-types/dist/spec/#trustedscripturl-stringification-behavior-Utf16String const& TrustedScriptURL::to_string() const+GC::Ref<TrustedScriptURL> TrustedScriptURL::create(Utf16String data){- // 1. return the associated data value.- return m_data;+ return *web_rust_trusted_types_create_trusted_script_url(JS::HostABI::vm_to_abi(JS::VM::the()), move(data).into_raw());}-// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscripturl-tojson-Utf16String const& TrustedScriptURL::to_json() const+Utf16String TrustedScriptURL::to_string() const{- // 1. return the associated data value.- return to_string();+ return Utf16String::from_raw(web_rust_trusted_types_trusted_script_url_data(const_cast<TrustedScriptURL*>(this)));}}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.h b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.hindex b4e8552f576..7bf289e69ac 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.h+++ b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.h@@ -8,26 +8,20 @@#include <AK/Utf16String.h>#include <AK/Variant.h>-#include <LibWeb/Bindings/Wrappable.h>+#include <LibWeb/Bindings/RustInterface.h>+#include <LibWeb/Bindings/TrustedScriptURL.h>namespace Web::TrustedTypes {using TrustedScriptURLOrString = Variant<GC::Ref<TrustedScriptURL>, Utf16String>;-class TrustedScriptURL final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(TrustedScriptURL, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(TrustedScriptURL);+class TrustedScriptURL final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(TrustedScriptURL, trusted_script_url)public:- virtual ~TrustedScriptURL() override = default;+ [[nodiscard]] static GC::Ref<TrustedScriptURL> create(Utf16String data);- Utf16String const& to_string() const;- Utf16String const& to_json() const;--private:- explicit TrustedScriptURL(Utf16String);-- Utf16String const m_data;+ Utf16String to_string() const;};}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idl b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idlindex 9d6db2e100e..e56d96d2539 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idl+++ b/Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idl@@ -1,5 +1,5 @@// https://w3c.github.io/trusted-types/dist/spec/#trused-script-url-[Exposed=(Window,Worker)]+[Exposed=(Window,Worker), ImplementedIn=Rust]interface TrustedScriptURL {stringifier;USVString toJSON();diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cppindex 2253120a66b..cac93632853 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp+++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp@@ -475,11 +475,11 @@ TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(JS::VM& vm, Truste// 5. Return a new instance of an interface with a type name trustedTypeName, with its associated data value set to dataString.switch (trusted_type_name) {case TrustedTypeName::TrustedHTML:- return TrustedType { GC::Heap::the().allocate<TrustedHTML>(move(data_string)) };+ return TrustedType { TrustedHTML::create(move(data_string)) };case TrustedTypeName::TrustedScript:- return TrustedType { GC::Heap::the().allocate<TrustedScript>(move(data_string)) };+ return TrustedType { TrustedScript::create(move(data_string)) };case TrustedTypeName::TrustedScriptURL:- return TrustedType { GC::Heap::the().allocate<TrustedScriptURL>(move(data_string)) };+ return TrustedType { TrustedScriptURL::create(move(data_string)) };default:VERIFY_NOT_REACHED();}@@ -589,11 +589,11 @@ WebIDL::ExceptionOr<Optional<TrustedType>> process_value_with_a_default_policy(T// 6. Return a new instance of an interface with a type name trustedTypeName, with its associated data value set to dataString.switch (trusted_type_name) {case TrustedTypeName::TrustedHTML:- return TrustedType { GC::Heap::the().allocate<TrustedHTML>(move(data_string)) };+ return TrustedType { TrustedHTML::create(move(data_string)) };case TrustedTypeName::TrustedScript:- return TrustedType { GC::Heap::the().allocate<TrustedScript>(move(data_string)) };+ return TrustedType { TrustedScript::create(move(data_string)) };case TrustedTypeName::TrustedScriptURL:- return TrustedType { GC::Heap::the().allocate<TrustedScriptURL>(move(data_string)) };+ return TrustedType { TrustedScriptURL::create(move(data_string)) };}VERIFY_NOT_REACHED();}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cppindex 8c0415b0d79..64e3df33a69 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp+++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp@@ -189,18 +189,18 @@ bool TrustedTypePolicyFactory::is_script_url(JS::Value value) constreturn is_trusted_script_url_value(value);}-GC::Ref<TrustedHTML const> TrustedTypePolicyFactory::empty_html()+GC::Ref<TrustedHTML> TrustedTypePolicyFactory::empty_html(){if (!m_empty_html)- m_empty_html = GC::Heap::the().allocate<TrustedHTML>(""_utf16);+ m_empty_html = TrustedHTML::create(""_utf16);return GC::Ref { *m_empty_html };}-GC::Ref<TrustedScript const> TrustedTypePolicyFactory::empty_script()+GC::Ref<TrustedScript> TrustedTypePolicyFactory::empty_script(){if (!m_empty_script)- m_empty_script = GC::Heap::the().allocate<TrustedScript>(""_utf16);+ m_empty_script = TrustedScript::create(""_utf16);return GC::Ref { *m_empty_script };}diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.hindex 0ec98a4a275..b6e0bc42dcf 100644--- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h+++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h@@ -32,8 +32,8 @@ public:bool is_script(JS::Value) const;bool is_script_url(JS::Value) const;- GC::Ref<TrustedHTML const> empty_html();- GC::Ref<TrustedScript const> empty_script();+ GC::Ref<TrustedHTML> empty_html();+ GC::Ref<TrustedScript> empty_script();Optional<Utf16String> get_attribute_type(Utf16FlyString const& tag_name, Utf16FlyString const& attribute, Optional<Utf16FlyString> element_ns, Optional<Utf16FlyString> attr_ns);Optional<Utf16String> get_property_type(Utf16FlyString const& tag_name, Utf16FlyString const& property, Optional<Utf16FlyString> element_ns);@@ -62,10 +62,10 @@ private:GC::Ptr<TrustedTypePolicy> m_default_policy;// https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-emptyhtml- GC::Ptr<TrustedHTML const> m_empty_html;+ GC::Ptr<TrustedHTML> m_empty_html;// https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-emptyscript- GC::Ptr<TrustedScript const> m_empty_script;+ GC::Ptr<TrustedScript> m_empty_script;};struct TrustedTypeData {