core: Refactor `LoadManager::load_form_into_object`

Make it call `navigator.fetch()` directly rather than receiving an
existing `Future`.
This commit is contained in:
relrelb 2022-03-25 18:09:51 +03:00 committed by Mike Welsh
parent 83353e17c5
commit f3c22d930b
3 changed files with 24 additions and 15 deletions

View File

@ -1217,14 +1217,13 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
&url,
NavigationMethod::from_send_vars_method(action.send_vars_method()),
);
let fetch = self.context.navigator.fetch(&url, opts);
let process = self.context.load_manager.load_form_into_object(
let future = self.context.load_manager.load_form_into_object(
self.context.player.clone().unwrap(),
target_obj,
fetch,
&url,
opts,
);
self.context.navigator.spawn_future(process);
self.context.navigator.spawn_future(future);
}
return Ok(FrameControl::Continue);

View File

@ -1345,15 +1345,14 @@ fn load_variables<'gc>(
let method = args.get(1).cloned().unwrap_or(Value::Undefined);
let method = NavigationMethod::from_method_str(&method.coerce_to_string(activation)?);
let (url, opts) = activation.locals_into_request_options(&url, method);
let fetch = activation.context.navigator.fetch(&url, opts);
let target = target.object().coerce_to_object(activation);
let process = activation.context.load_manager.load_form_into_object(
let future = activation.context.load_manager.load_form_into_object(
activation.context.player.clone().unwrap(),
target,
fetch,
&url,
opts,
);
activation.context.navigator.spawn_future(process);
activation.context.navigator.spawn_future(future);
Ok(Value::Undefined)
}

View File

@ -164,7 +164,8 @@ impl<'gc> LoadManager<'gc> {
&mut self,
player: Weak<Mutex<Player>>,
target_object: Object<'gc>,
fetch: OwnedFuture<Vec<u8>, Error>,
url: &str,
options: RequestOptions,
) -> OwnedFuture<(), Error> {
let loader = Loader::Form {
self_handle: None,
@ -172,8 +173,7 @@ impl<'gc> LoadManager<'gc> {
};
let handle = self.add_loader(loader);
let loader = self.get_loader_mut(handle).unwrap();
loader.form_loader(player, fetch)
loader.form_loader(player, url.to_owned(), options)
}
/// Kick off a form data load into an AVM1 object.
@ -516,10 +516,11 @@ impl<'gc> Loader<'gc> {
})
}
pub fn form_loader(
fn form_loader(
&mut self,
player: Weak<Mutex<Player>>,
fetch: OwnedFuture<Vec<u8>, Error>,
url: String,
options: RequestOptions,
) -> OwnedFuture<(), Error> {
let handle = match self {
Loader::Form { self_handle, .. } => self_handle.expect("Loader not self-introduced"),
@ -531,6 +532,16 @@ impl<'gc> Loader<'gc> {
.expect("Could not upgrade weak reference to player");
Box::pin(async move {
// clippy reports a false positive for explicitly dropped guards:
// https://github.com/rust-lang/rust-clippy/issues/6446
// A workaround for this is to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
let fetch;
{
let player_lock = player.lock().unwrap();
let url = player_lock.navigator().resolve_relative_url(&url);
fetch = player_lock.navigator().fetch(&url, options);
}
let data = fetch.await?;
// Fire the load handler.