Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions core/src/avm2/globals/flash/display/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ pub fn bitmap_allocator<'gc>(
&activation.caller_movie_or_root(),
)
.into();
return Ok(initialize_for_allocator(
activation.context,
display_object,
orig_class,
));
return Ok(
initialize_for_allocator(activation.context, display_object, orig_class).into(),
);
}

if let Some((movie, symbol)) = activation
Expand Down Expand Up @@ -66,11 +64,9 @@ pub fn bitmap_allocator<'gc>(
&activation.caller_movie_or_root(),
);

return Ok(initialize_for_allocator(
activation.context,
child.into(),
orig_class,
));
return Ok(
initialize_for_allocator(activation.context, child.into(), orig_class).into(),
);
}
}
class_def = class.super_class();
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm2/globals/flash/display/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn initialize_for_allocator<'gc>(
context: &mut UpdateContext<'gc>,
dobj: DisplayObject<'gc>,
class: ClassObject<'gc>,
) -> Object<'gc> {
) -> StageObject<'gc> {
let obj = StageObject::for_display_object(context.gc(), dobj, class);
dobj.set_placed_by_avm2_script(true);
dobj.set_object2(context, obj);
Expand All @@ -50,7 +50,7 @@ pub fn initialize_for_allocator<'gc>(
dobj.base().set_skip_next_enter_frame(true);
dobj.on_construction_complete(context);

obj.into()
obj
}

/// Implements `alpha`'s getter.
Expand Down
10 changes: 6 additions & 4 deletions core/src/avm2/globals/flash/display/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ pub fn loader_allocator<'gc>(
None,
false,
)?;

loader.set_slot(
loader_slots::_CONTENT_LOADER_INFO,
loader_info.into(),
activation,
)?;
Ok(loader)

Ok(loader.into())
}

pub fn load<'gc>(
Expand Down Expand Up @@ -86,7 +88,7 @@ pub fn load<'gc>(
}

// Unload the loader, in case something was already loaded.
loader_info.unload(activation);
loader_info.unload(activation.context);

// This is a dummy MovieClip, which will get overwritten in `Loader`
let movie = &activation.context.root_swf;
Expand Down Expand Up @@ -257,7 +259,7 @@ pub fn load_bytes<'gc>(
}

// Unload the loader, in case something was already loaded.
loader_info.unload(activation);
loader_info.unload(activation.context);

// This is a dummy MovieClip, which will get overwritten in `Loader`
let movie = &activation.context.root_swf;
Expand Down Expand Up @@ -305,7 +307,7 @@ pub fn unload<'gc>(

let loader_info = loader_info.as_loader_info_object().unwrap();

loader_info.unload(activation);
loader_info.unload(activation.context);

Ok(Value::Undefined)
}
4 changes: 2 additions & 2 deletions core/src/avm2/globals/flash/display/loader_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub fn get_child_allows_parent<'gc>(
avm2_stub_getter!(activation, "flash.display.LoaderInfo", "childAllowsParent");

if let Some(loader) = loader_info.loader() {
let loader = loader.as_display_object().expect("Loader is a DO");
let loader = loader.display_object();
let parent_movie = loader.movie();

if let Ok(child_url) = Url::parse(root.url()) {
Expand Down Expand Up @@ -306,7 +306,7 @@ pub fn get_parent_allows_child<'gc>(
avm2_stub_getter!(activation, "flash.display.LoaderInfo", "parentAllowsChild");

if let Some(loader) = loader_info.loader() {
let loader = loader.as_display_object().expect("Loader is a DO");
let loader = loader.display_object();
let parent_movie = loader.movie();

if let Ok(child_url) = Url::parse(root.url()) {
Expand Down
6 changes: 1 addition & 5 deletions core/src/avm2/globals/flash/display/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ pub fn shape_allocator<'gc>(
) -> Result<Object<'gc>, Error<'gc>> {
let display_object = Graphic::empty(activation.context).into();

Ok(initialize_for_allocator(
activation.context,
display_object,
class,
))
Ok(initialize_for_allocator(activation.context, display_object, class).into())
}

/// Implements `graphics`.
Expand Down
6 changes: 1 addition & 5 deletions core/src/avm2/globals/flash/display/simple_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ pub fn simple_button_allocator<'gc>(
.instantiate_by_id(symbol, activation.context.gc_context);

if let Some(child) = child {
return Ok(initialize_for_allocator(
activation.context,
child,
orig_class,
));
return Ok(initialize_for_allocator(activation.context, child, orig_class).into());
} else {
return Err(make_error_2136(activation));
}
Expand Down
14 changes: 4 additions & 10 deletions core/src/avm2/globals/flash/display/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ pub fn sprite_allocator<'gc>(
if class == sprite_cls {
let movie = activation.caller_movie_or_root();
let display_object = MovieClip::new(movie, activation.gc()).into();
return Ok(initialize_for_allocator(
activation.context,
display_object,
orig_class,
));
return Ok(
initialize_for_allocator(activation.context, display_object, orig_class).into(),
);
}

if let Some((movie, symbol)) = activation
Expand All @@ -44,11 +42,7 @@ pub fn sprite_allocator<'gc>(
.instantiate_by_id(symbol, activation.context.gc_context);

if let Some(child) = child {
return Ok(initialize_for_allocator(
activation.context,
child,
orig_class,
));
return Ok(initialize_for_allocator(activation.context, child, orig_class).into());
} else {
return Err(make_error_2136(activation));
}
Expand Down
8 changes: 2 additions & 6 deletions core/src/avm2/globals/flash/media/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ pub fn video_allocator<'gc>(
if target == video_class {
let movie = activation.caller_movie_or_root();
let new_do = Video::new(activation.gc(), movie, 0, 0, None);
return Ok(initialize_for_allocator(
activation.context,
new_do.into(),
class,
));
return Ok(initialize_for_allocator(activation.context, new_do.into(), class).into());
}

if let Some((movie, symbol)) = activation
Expand All @@ -36,7 +32,7 @@ pub fn video_allocator<'gc>(
.instantiate_by_id(symbol, activation.context.gc_context);

if let Some(child) = child {
return Ok(initialize_for_allocator(activation.context, child, class));
return Ok(initialize_for_allocator(activation.context, child, class).into());
} else {
return Err(make_error_2136(activation));
}
Expand Down
6 changes: 1 addition & 5 deletions core/src/avm2/globals/flash/text/text_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ pub fn text_field_allocator<'gc>(
let movie = activation.caller_movie_or_root();
let display_object = EditText::new(activation.context, movie, 0.0, 0.0, 100.0, 100.0).into();

Ok(initialize_for_allocator(
activation.context,
display_object,
class,
))
Ok(initialize_for_allocator(activation.context, display_object, class).into())
}

pub fn get_always_show_selection<'gc>(
Expand Down
46 changes: 20 additions & 26 deletions core/src/avm2/object/loaderinfo_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

use crate::avm2::activation::Activation;
use crate::avm2::object::script_object::ScriptObjectData;
use crate::avm2::object::{EventObject, Object, TObject};
use crate::avm2::{Avm2, Error, Value};
use crate::avm2::object::{EventObject, Object, StageObject, TObject};
use crate::avm2::{Avm2, Error};
use crate::context::UpdateContext;
use crate::display_object::DisplayObject;
use crate::display_object::{DisplayObject, TDisplayObject, TDisplayObjectContainer};
use crate::loader::ContentType;
use crate::tag_utils::SwfMovie;
use core::fmt;
use gc_arena::barrier::unlock;
use gc_arena::{
lock::{Lock, RefLock},
Collect, Gc, GcWeak, Mutation,
};
use gc_arena::{lock::RefLock, Collect, Gc, GcWeak, Mutation};
use ruffle_common::utils::HasPrefixField;
use std::cell::{Cell, Ref};
use std::sync::Arc;
Expand Down Expand Up @@ -81,7 +78,7 @@ pub struct LoaderInfoObjectData<'gc> {
/// The loaded stream that this gets its info from.
loaded_stream: RefLock<LoaderStream<'gc>>,

loader: Option<Object<'gc>>,
loader: Option<StageObject<'gc>>,

/// Whether or not we've fired our 'init' event
init_event_fired: Cell<bool>,
Expand All @@ -96,8 +93,6 @@ pub struct LoaderInfoObjectData<'gc> {

uncaught_error_events: Object<'gc>,

cached_avm1movie: Lock<Option<Object<'gc>>>,

content_type: Cell<ContentType>,

expose_content: Cell<bool>,
Expand All @@ -113,7 +108,7 @@ impl<'gc> LoaderInfoObject<'gc> {
pub fn not_yet_loaded(
activation: &mut Activation<'_, 'gc>,
movie: Arc<SwfMovie>,
loader: Option<Object<'gc>>,
loader: Option<StageObject<'gc>>,
root_clip: Option<DisplayObject<'gc>>,
is_stage: bool,
) -> Result<Self, Error<'gc>> {
Expand Down Expand Up @@ -144,7 +139,6 @@ impl<'gc> LoaderInfoObject<'gc> {
.construct(activation, &[])?
.as_object()
.unwrap(),
cached_avm1movie: Lock::new(None),
content_type: Cell::new(ContentType::Unknown),
expose_content: Cell::new(false),
errored: Cell::new(false),
Expand All @@ -154,7 +148,7 @@ impl<'gc> LoaderInfoObject<'gc> {
Ok(object)
}

pub fn loader(self) -> Option<Object<'gc>> {
pub fn loader(self) -> Option<StageObject<'gc>> {
self.0.loader
}

Expand Down Expand Up @@ -269,27 +263,27 @@ impl<'gc> LoaderInfoObject<'gc> {
self.0.content_type.set(content_type);
}

pub fn unload(self, activation: &mut Activation<'_, 'gc>) {
pub fn unload(self, context: &mut UpdateContext<'gc>) {
// Reset properties
let movie = &activation.context.root_swf;
let movie = &context.root_swf;
let empty_swf = Arc::new(SwfMovie::empty(movie.version(), Some(movie.url().into())));
let loader_stream = LoaderStream::NotYetLoaded(empty_swf, None, false);
self.set_loader_stream(loader_stream, activation.gc());
self.set_loader_stream(loader_stream, context.gc());
self.set_errored(false);
self.reset_init_and_complete_events();

let loader = self
let mut loader = self
.0
.loader
.expect("LoaderInfo must have been created by Loader");

// Remove the Loader's content element, and ignore the resulting
// error if the loader hadn't loaded it.
let _ = crate::avm2::globals::flash::display::display_object_container::remove_child_at(
activation,
Value::Object(loader),
&[0.into()],
);
.expect("LoaderInfo must have been created by Loader")
.display_object()
.as_container()
.unwrap();

// Remove the Loader's content element if it exists.
if let Some(child) = loader.child_by_index(0) {
loader.remove_child(context, child);
}
}
}

Expand Down
Loading
Loading