script: Propagate &mut JSContext inside global_scope_script_execution.rs (#43473)

Pass `&mut JSContext` to `HTMLScriptElement::execute`, propagate it
inside `global_scope_script_execution.rs` and then switch to wrappers2
bindings.

Testing: 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-20 11:51:33 +01:00
committed by GitHub
parent 2ca02dfa4c
commit e0fc0174fa
9 changed files with 90 additions and 106 deletions

View File

@@ -281,15 +281,15 @@ fn finish_fetching_a_classic_script(
match script_kind {
ExternalScriptKind::Asap => {
document = elem.preparation_time_document.get().unwrap();
document.asap_script_loaded(elem, load, CanGc::from_cx(cx))
document.asap_script_loaded(cx, elem, load)
},
ExternalScriptKind::AsapInOrder => {
document = elem.preparation_time_document.get().unwrap();
document.asap_in_order_script_loaded(elem, load, CanGc::from_cx(cx))
document.asap_in_order_script_loaded(cx, elem, load)
},
ExternalScriptKind::Deferred => {
document = elem.parser_document.as_rooted();
document.deferred_script_loaded(elem, load, CanGc::from_cx(cx));
document.deferred_script_loaded(cx, elem, load);
},
ExternalScriptKind::ParsingBlocking => {
document = elem.parser_document.as_rooted();
@@ -437,6 +437,7 @@ impl FetchResponseListener for ClassicContext {
// Step 5.7. Let script be the result of creating a classic script given
// sourceText, settingsObject, response's URL, options, mutedErrors, and url.
let script = global.create_a_classic_script(
cx,
source_text,
final_url,
self.fetch_options.clone(),
@@ -920,6 +921,7 @@ impl HTMLScriptElement {
// Step 32.2.1 Let script be the result of creating a classic script
// using source text, settings object, base URL, and options.
let script = self.global().create_a_classic_script(
cx,
std::borrow::Cow::Borrowed(&text.str()),
base_url,
options,
@@ -939,7 +941,7 @@ impl HTMLScriptElement {
doc.set_pending_parsing_blocking_script(self, Some(result));
} else {
// Step 34.3: otherwise.
self.execute(result, CanGc::from_cx(cx));
self.execute(cx, result);
}
},
ScriptType::Module => {
@@ -981,14 +983,14 @@ impl HTMLScriptElement {
));
// Step 34.3
self.execute(Ok(script), CanGc::from_cx(cx));
self.execute(cx, Ok(script));
},
}
}
}
/// <https://html.spec.whatwg.org/multipage/#execute-the-script-element>
pub(crate) fn execute(&self, result: ScriptResult, can_gc: CanGc) {
pub(crate) fn execute(&self, cx: &mut JSContext, result: ScriptResult) {
// Step 1. Let document be el's node document.
let doc = self.owner_document();
@@ -1005,12 +1007,7 @@ impl HTMLScriptElement {
let script = match result {
// Step 4. If el's result is null, then fire an event named error at el, and return.
Err(_) => {
self.dispatch_event(
atom!("error"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
can_gc,
);
self.dispatch_event(cx, atom!("error"));
return;
},
@@ -1046,9 +1043,9 @@ impl HTMLScriptElement {
// Step 6."classic".3. Run the classic script given by el's result.
_ = self.owner_window().as_global_scope().run_a_classic_script(
cx,
script,
RethrowErrors::No,
can_gc,
);
// Step 6."classic".4. Set document's currentScript attribute to oldCurrentScript.
@@ -1059,15 +1056,13 @@ impl HTMLScriptElement {
document.set_current_script(None);
// Step 6."module".2. Run the module script given by el's result.
self.owner_window().as_global_scope().run_a_module_script(
module_tree,
false,
can_gc,
);
self.owner_window()
.as_global_scope()
.run_a_module_script(cx, module_tree, false);
},
Script::ImportMap(script) => {
// Step 6."importmap".1. Register an import map given el's relevant global object and el's result.
register_import_map(&self.owner_global(), script.import_map, can_gc);
register_import_map(&self.owner_global(), script.import_map, CanGc::from_cx(cx));
},
}
@@ -1079,12 +1074,7 @@ impl HTMLScriptElement {
// Step 8. If el's from an external file is true, then fire an event named load at el.
if self.from_an_external_file.get() {
self.dispatch_event(
atom!("load"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
can_gc,
);
self.dispatch_event(cx, atom!("load"));
}
}
@@ -1166,16 +1156,16 @@ impl HTMLScriptElement {
self.non_blocking.get()
}
fn dispatch_event(
&self,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
can_gc: CanGc,
) -> bool {
fn dispatch_event(&self, cx: &mut JSContext, type_: Atom) -> bool {
let window = self.owner_window();
let event = Event::new(window.upcast(), type_, bubbles, cancelable, can_gc);
event.fire(self.upcast(), can_gc)
let event = Event::new(
window.upcast(),
type_,
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
CanGc::from_cx(cx),
);
event.fire(self.upcast(), CanGc::from_cx(cx))
}
fn text(&self) -> DOMString {