Use DOMString for internal data of Trusted Types (#37472)

This avoids various conversions back and forth between DOMString and
String. By using DOMString consistently, we avoid these
double-conversions. The only caveat are the USVString which are
initially passed into
TrustedScriptURL.

Part of #36258

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe 2025-06-15 16:12:33 +02:00 committed by GitHub
parent dfbd5b7d21
commit 576c7445b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 72 additions and 70 deletions

View file

@ -3272,13 +3272,13 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
// Step 1. Let compliantHTML be the result of invoking the
// Get Trusted Type compliant string algorithm with TrustedHTML,
// this's relevant global object, html, "Element setHTMLUnsafe", and "script".
let html = DOMString::from(TrustedHTML::get_trusted_script_compliant_string(
let html = TrustedHTML::get_trusted_script_compliant_string(
&self.owner_global(),
html,
"Element",
"setHTMLUnsafe",
can_gc,
)?);
)?;
// Step 2. Let target be this's template contents if this is a template element; otherwise this.
let target = if let Some(template) = self.downcast::<HTMLTemplateElement>() {
DomRoot::upcast(template.Content(can_gc))
@ -3329,13 +3329,13 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
// Step 1: Let compliantString be the result of invoking the
// Get Trusted Type compliant string algorithm with TrustedHTML,
// this's relevant global object, the given value, "Element innerHTML", and "script".
let value = DOMString::from(TrustedHTML::get_trusted_script_compliant_string(
let value = TrustedHTML::get_trusted_script_compliant_string(
&self.owner_global(),
value.convert(),
"Element",
"innerHTML",
can_gc,
)?);
)?;
// https://github.com/w3c/DOM-Parsing/issues/1
let target = if let Some(template) = self.downcast::<HTMLTemplateElement>() {
// Step 4: If context is a template element, then set context to
@ -3387,13 +3387,13 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
// Step 1: Let compliantString be the result of invoking the
// Get Trusted Type compliant string algorithm with TrustedHTML,
// this's relevant global object, the given value, "Element outerHTML", and "script".
let value = DOMString::from(TrustedHTML::get_trusted_script_compliant_string(
let value = TrustedHTML::get_trusted_script_compliant_string(
&self.owner_global(),
value.convert(),
"Element",
"outerHTML",
can_gc,
)?);
)?;
let context_document = self.owner_document();
let context_node = self.upcast::<Node>();
// Step 2: Let parent be this's parent.
@ -3603,13 +3603,13 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
// Step 1: Let compliantString be the result of invoking the
// Get Trusted Type compliant string algorithm with TrustedHTML,
// this's relevant global object, string, "Element insertAdjacentHTML", and "script".
let text = DOMString::from(TrustedHTML::get_trusted_script_compliant_string(
let text = TrustedHTML::get_trusted_script_compliant_string(
&self.owner_global(),
text,
"Element",
"insertAdjacentHTML",
can_gc,
)?);
)?;
let position = position.parse::<AdjacentPosition>()?;
// Step 2: Let context be null.