script: Pass &mut JSContext to TrustedScriptURL::get_trusted_type_compliant_string (#43245)

Also rename the method and consolidate the sink to be consistent with
both `TrustedHTML` and `TrustedScript`

Part of #42638

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe
2026-03-13 14:56:46 +01:00
committed by GitHub
parent 048612fe84
commit b6ba612a54
5 changed files with 27 additions and 26 deletions

View File

@@ -1289,20 +1289,19 @@ impl HTMLScriptElementMethods<crate::DomTypeHolder> for HTMLScriptElement {
}
/// <https://w3c.github.io/trusted-types/dist/spec/#the-src-idl-attribute>
fn SetSrc(&self, value: TrustedScriptURLOrUSVString, can_gc: CanGc) -> Fallible<()> {
fn SetSrc(&self, cx: &mut JSContext, value: TrustedScriptURLOrUSVString) -> Fallible<()> {
let element = self.upcast::<Element>();
let local_name = &local_name!("src");
let value = TrustedScriptURL::get_trusted_script_url_compliant_string(
let value = TrustedScriptURL::get_trusted_type_compliant_string(
cx,
&element.owner_global(),
value,
"HTMLScriptElement",
local_name,
can_gc,
&format!("HTMLScriptElement {}", local_name),
)?;
element.set_attribute(
local_name,
AttrValue::String(value.str().to_owned()),
can_gc,
CanGc::from_cx(cx),
);
Ok(())
}