core: Refactor `LoadManager::load_form_into_load_vars`
Make it call `navigator.fetch()` directly rather than receiving an existing `Future`.
This commit is contained in:
parent
f3c22d930b
commit
1c576816b6
|
@ -254,12 +254,13 @@ fn spawn_load_var_fetch<'gc>(
|
|||
(url.to_utf8_lossy(), RequestOptions::get())
|
||||
};
|
||||
|
||||
let fetch = activation.context.navigator.fetch(&url, request_options);
|
||||
let process = activation.context.load_manager.load_form_into_load_vars(
|
||||
let future = activation.context.load_manager.load_form_into_load_vars(
|
||||
activation.context.player.clone().unwrap(),
|
||||
loader_object,
|
||||
fetch,
|
||||
&url,
|
||||
request_options,
|
||||
);
|
||||
activation.context.navigator.spawn_future(future);
|
||||
|
||||
// Create hidden properties on object.
|
||||
if !loader_object.has_property(activation, "_bytesLoaded".into()) {
|
||||
|
@ -284,7 +285,5 @@ fn spawn_load_var_fetch<'gc>(
|
|||
loader_object.set("loaded", false.into(), activation)?;
|
||||
}
|
||||
|
||||
activation.context.navigator.spawn_future(process);
|
||||
|
||||
Ok(true.into())
|
||||
}
|
||||
|
|
|
@ -262,17 +262,13 @@ fn spawn_xml_fetch<'gc>(
|
|||
|
||||
this.set("loaded", false.into(), activation)?;
|
||||
|
||||
let fetch = activation
|
||||
.context
|
||||
.navigator
|
||||
.fetch(&url.to_utf8_lossy(), request_options);
|
||||
let process = activation.context.load_manager.load_form_into_load_vars(
|
||||
let future = activation.context.load_manager.load_form_into_load_vars(
|
||||
activation.context.player.clone().unwrap(),
|
||||
loader_object,
|
||||
fetch,
|
||||
&url.to_utf8_lossy(),
|
||||
request_options,
|
||||
);
|
||||
|
||||
activation.context.navigator.spawn_future(process);
|
||||
activation.context.navigator.spawn_future(future);
|
||||
|
||||
Ok(true.into())
|
||||
}
|
||||
|
|
|
@ -183,7 +183,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::LoadVars {
|
||||
self_handle: None,
|
||||
|
@ -191,8 +192,7 @@ impl<'gc> LoadManager<'gc> {
|
|||
};
|
||||
let handle = self.add_loader(loader);
|
||||
let loader = self.get_loader_mut(handle).unwrap();
|
||||
|
||||
loader.load_vars_loader(player, fetch)
|
||||
loader.load_vars_loader(player, url.to_owned(), options)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,10 +570,11 @@ impl<'gc> Loader<'gc> {
|
|||
}
|
||||
|
||||
/// Creates a future for a LoadVars load call.
|
||||
pub fn load_vars_loader(
|
||||
fn load_vars_loader(
|
||||
&mut self,
|
||||
player: Weak<Mutex<Player>>,
|
||||
fetch: OwnedFuture<Vec<u8>, Error>,
|
||||
url: String,
|
||||
options: RequestOptions,
|
||||
) -> OwnedFuture<(), Error> {
|
||||
let handle = match self {
|
||||
Loader::LoadVars { self_handle, .. } => {
|
||||
|
@ -587,6 +588,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.
|
||||
|
|
Loading…
Reference in New Issue