script: Pass &mut JSContext to DOM apis that call Element::create (#43108)

Testing: No behaviour change, a successful build is enough.
Part of #40600

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24
2026-03-09 11:07:13 +01:00
committed by GitHub
parent c32d9f51af
commit fa86bbedbe
13 changed files with 154 additions and 99 deletions

View File

@@ -4,6 +4,7 @@
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix, QualName, local_name, ns};
use js::context::JSContext;
use js::rust::HandleObject;
use style::attr::AttrValue;
@@ -56,9 +57,9 @@ impl HTMLAudioElement {
impl HTMLAudioElementMethods<crate::DomTypeHolder> for HTMLAudioElement {
/// <https://html.spec.whatwg.org/multipage/#dom-audio>
fn Audio(
cx: &mut JSContext,
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
src: Option<DOMString>,
) -> Fallible<DomRoot<HTMLAudioElement>> {
// Step 1. Let document be the current global object's associated Document.
@@ -73,21 +74,25 @@ impl HTMLAudioElementMethods<crate::DomTypeHolder> for HTMLAudioElement {
ElementCreator::ScriptCreated,
CustomElementCreationMode::Synchronous,
proto,
can_gc,
CanGc::from_cx(cx),
);
// Step 3. Set an attribute value for audio using "preload" and "auto".
audio.set_attribute(
&local_name!("preload"),
AttrValue::String("auto".to_owned()),
can_gc,
CanGc::from_cx(cx),
);
// Step 4. If src is given, then set an attribute value for audio using "src" and src. (This
// will cause the user agent to invoke the object's resource selection algorithm before
// returning).
if let Some(s) = src {
audio.set_attribute(&local_name!("src"), AttrValue::String(s.into()), can_gc);
audio.set_attribute(
&local_name!("src"),
AttrValue::String(s.into()),
CanGc::from_cx(cx),
);
}
// Step 5. Return audio.