Skip to content

Commit 7e50183

Browse files
Bale001Aaron1011
authored andcommitted
core: Add new context parameter to loader
1 parent 6f430bb commit 7e50183

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

core/src/avm1/activation.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
11421142
Request::get(url),
11431143
None,
11441144
None,
1145+
None,
11451146
);
11461147
self.context.navigator.spawn_future(future);
11471148
}
@@ -1262,6 +1263,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
12621263
request,
12631264
None,
12641265
None,
1266+
None,
12651267
);
12661268
self.context.navigator.spawn_future(future);
12671269
}
@@ -1282,6 +1284,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
12821284
Request::get(url.to_utf8_lossy().into_owned()),
12831285
None,
12841286
None,
1287+
None,
12851288
);
12861289
self.context.navigator.spawn_future(future);
12871290
}

core/src/avm1/globals/movie_clip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ fn load_movie<'gc>(
13411341
request,
13421342
None,
13431343
None,
1344+
None,
13441345
);
13451346
activation.context.navigator.spawn_future(future);
13461347

core/src/avm1/globals/movie_clip_loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn load_clip<'gc>(
6565
Request::get(url.to_utf8_lossy().into_owned()),
6666
None,
6767
Some(MovieLoaderEventHandler::Avm1Broadcast(this)),
68+
None,
6869
);
6970
activation.context.navigator.spawn_future(future);
7071

core/src/avm2/globals/flash/display/loader.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,10 @@ pub fn load<'gc>(
5252
) -> Result<Value<'gc>, Error<'gc>> {
5353
if let Some(this) = this {
5454
let url_request = args[0].as_object().unwrap();
55+
let context = args
56+
.get(1)
57+
.and_then(|v| v.coerce_to_object(activation).ok());
5558

56-
if let Some(context) = args.get(1) {
57-
if !matches!(context, Value::Null) {
58-
log::warn!(
59-
"Loader.load: 'context' argument is not yet implemented: {:?}",
60-
context
61-
);
62-
}
63-
}
6459
let url = url_request
6560
.get_property(&Multiname::public("url"), activation)?
6661
.coerce_to_string(activation)?;
@@ -86,6 +81,7 @@ pub fn load<'gc>(
8681
Request::get(url.to_string()),
8782
Some(url.to_string()),
8883
Some(MovieLoaderEventHandler::Avm2LoaderInfo(loader_info)),
84+
context,
8985
);
9086
activation.context.navigator.spawn_future(future);
9187
}
@@ -100,15 +96,9 @@ pub fn load_bytes<'gc>(
10096
if let Some(this) = this {
10197
let arg0 = args[0].as_object().unwrap();
10298
let bytearray = arg0.as_bytearray().unwrap();
103-
104-
if let Some(context) = args.get(1) {
105-
if !matches!(context, Value::Null) {
106-
log::warn!(
107-
"Loader.load: 'context' argument is not yet implemented: {:?}",
108-
context
109-
);
110-
}
111-
}
99+
let context = args
100+
.get(1)
101+
.and_then(|v| v.coerce_to_object(activation).ok());
112102

113103
// This is a dummy MovieClip, which will get overwritten in `Loader`
114104
let content = MovieClip::new(
@@ -129,6 +119,7 @@ pub fn load_bytes<'gc>(
129119
content.into(),
130120
bytearray.bytes().to_vec(),
131121
Some(MovieLoaderEventHandler::Avm2LoaderInfo(loader_info)),
122+
context,
132123
);
133124
activation.context.navigator.spawn_future(future);
134125
}

core/src/loader.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ impl<'gc> LoadManager<'gc> {
271271
request: Request,
272272
loader_url: Option<String>,
273273
event_handler: Option<MovieLoaderEventHandler<'gc>>,
274+
context: Option<Avm2Object<'gc>>,
274275
) -> OwnedFuture<(), Error> {
275276
let loader = Loader::Movie {
276277
self_handle: None,
277278
target_clip,
278279
event_handler,
279280
loader_status: LoaderStatus::Pending,
280281
movie: None,
282+
context,
281283
};
282284
let handle = self.add_loader(loader);
283285
let loader = self.get_loader_mut(handle).unwrap();
@@ -293,13 +295,15 @@ impl<'gc> LoadManager<'gc> {
293295
target_clip: DisplayObject<'gc>,
294296
bytes: Vec<u8>,
295297
event_handler: Option<MovieLoaderEventHandler<'gc>>,
298+
context: Option<Avm2Object<'gc>>,
296299
) -> OwnedFuture<(), Error> {
297300
let loader = Loader::Movie {
298301
self_handle: None,
299302
target_clip,
300303
event_handler,
301304
loader_status: LoaderStatus::Pending,
302305
movie: None,
306+
context,
303307
};
304308
let handle = self.add_loader(loader);
305309
let loader = self.get_loader_mut(handle).unwrap();
@@ -511,6 +515,9 @@ pub enum Loader<'gc> {
511515
/// completed and we expect the Player to periodically tick preload
512516
/// until loading completes.
513517
movie: Option<Arc<SwfMovie>>,
518+
519+
/// The context of the SWF being loaded. (AVM2 only)
520+
context: Option<Avm2Object<'gc>>,
514521
},
515522

516523
/// Loader that is loading form data into an AVM1 object scope.

0 commit comments

Comments
 (0)