Skip to content

Commit

Permalink
core: remove UpdateContext's unused lifetime and reborrow method
Browse files Browse the repository at this point in the history
  • Loading branch information
moulins authored and Dinnerbone committed Aug 10, 2024
1 parent 13cffa4 commit 47030b4
Show file tree
Hide file tree
Showing 70 changed files with 658 additions and 775 deletions.
28 changes: 11 additions & 17 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub struct Activation<'a, 'gc: 'a> {
/// Whether the base clip was removed when we started this frame.
base_clip_unloaded: bool,

pub context: &'a mut UpdateContext<'a, 'gc>,
pub context: &'a mut UpdateContext<'gc>,

/// An identifier to refer to this activation by, when debugging.
/// This is often the name of a function (if known), or some static name to indicate where
Expand All @@ -245,7 +245,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

#[allow(clippy::too_many_arguments)]
pub fn from_action(
context: &'a mut UpdateContext<'a, 'gc>,
context: &'a mut UpdateContext<'gc>,
id: ActivationIdentifier<'a>,
swf_version: u8,
scope: Gc<'gc, Scope<'gc>>,
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
avm_debug!(self.context.avm1, "START {id}");
Activation {
id,
context: self.context.reborrow(),
context: self.context,
swf_version: self.swf_version,
scope,
constant_pool: self.constant_pool,
Expand All @@ -301,7 +301,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
/// Note: using the returned `Activation` directly to execute arbitrary bytecode and/or
/// to define new local variables is a logic error, and will corrupt the global scope.
pub fn from_nothing(
context: &'a mut UpdateContext<'a, 'gc>,
context: &'a mut UpdateContext<'gc>,
id: ActivationIdentifier<'a>,
base_clip: DisplayObject<'gc>,
) -> Self {
Expand All @@ -324,10 +324,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

/// Construct an empty stack frame with no code running on the root movie in
/// layer 0.
pub fn from_stub(
context: &'a mut UpdateContext<'a, 'gc>,
id: ActivationIdentifier<'a>,
) -> Self {
pub fn from_stub(context: &'a mut UpdateContext<'gc>, id: ActivationIdentifier<'a>) -> Self {
// [NA]: we have 3 options here:
// 1 - Don't execute anything (return None and handle that at the caller)
// 2 - Execute something with a temporary orphaned movie
Expand All @@ -345,7 +342,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
/// Construct an empty stack frame with no code running on the root move in
/// layer 0.
pub fn try_from_stub(
context: &'a mut UpdateContext<'a, 'gc>,
context: &'a mut UpdateContext<'gc>,
id: ActivationIdentifier<'a>,
) -> Option<Self> {
if let Some(level0) = context.stage.root_clip() {
Expand All @@ -362,11 +359,8 @@ impl<'a, 'gc> Activation<'a, 'gc> {
active_clip: DisplayObject<'gc>,
code: SwfSlice,
) -> Result<ReturnType<'gc>, Error<'gc>> {
let mut parent_activation = Activation::from_nothing(
self.context.reborrow(),
self.id.child("[Actions Parent]"),
active_clip,
);
let mut parent_activation =
Activation::from_nothing(self.context, self.id.child("[Actions Parent]"), active_clip);
let clip_obj = active_clip
.object()
.coerce_to_object(&mut parent_activation);
Expand All @@ -381,7 +375,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let constant_pool = parent_activation.context.avm1.constant_pool();
let child_name = parent_activation.id.child(name);
let mut child_activation = Activation::from_action(
parent_activation.context.reborrow(),
parent_activation.context,
child_name,
active_clip.swf_version(),
child_scope,
Expand Down Expand Up @@ -418,7 +412,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
);
let constant_pool = self.context.avm1.constant_pool();
let mut activation = Activation::from_action(
self.context.reborrow(),
self.context,
self.id.child(name),
swf_version,
child_scope,
Expand Down Expand Up @@ -2267,7 +2261,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
if let Some((catch_vars, actions)) = &action.catch_body {
if let Err(Error::ThrownValue(value)) = &result {
let mut activation = Activation::from_action(
self.context.reborrow(),
self.context,
self.id.child("[Catch]"),
self.swf_version,
self.scope,
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl<'gc> Executable<'gc> {

let max_recursion_depth = activation.context.avm1.max_recursion_depth();
let mut frame = Activation::from_action(
activation.context.reborrow(),
activation.context,
activation.id.function(name, reason, max_recursion_depth)?,
swf_version,
child_scope,
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/bitmap_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn clone<'gc>(

pub fn avm1_to_filter<'gc>(
object: Object<'gc>,
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
) -> Option<Filter> {
let native = object.native();
match native {
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/convolution_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<'gc> ConvolutionFilter<'gc> {
Ok(())
}

fn matrix(&self, context: &mut UpdateContext<'_, 'gc>) -> ArrayObject<'gc> {
fn matrix(&self, context: &mut UpdateContext<'gc>) -> ArrayObject<'gc> {
ArrayObject::new(
context.gc_context,
context.avm1.prototypes().array,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/displacement_map_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'gc> DisplacementMapFilter<'gc> {
Self(GcCell::new(gc_context, self.0.read().clone()))
}

fn map_bitmap(&self, context: &mut UpdateContext<'_, 'gc>) -> Option<Object<'gc>> {
fn map_bitmap(&self, context: &mut UpdateContext<'gc>) -> Option<Object<'gc>> {
if let Some(map_bitmap) = self.0.read().map_bitmap {
let proto = context.avm1.prototypes().bitmap_data;
let result = ScriptObject::new(context.gc_context, Some(proto));
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'gc> DisplacementMapFilter<'gc> {

pub fn filter(
&self,
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
) -> ruffle_render::filters::DisplacementMapFilter {
let filter = self.0.read();
ruffle_render::filters::DisplacementMapFilter {
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm1/globals/gradient_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'gc> GradientFilter<'gc> {
Ok(())
}

fn colors(&self, context: &mut UpdateContext<'_, 'gc>) -> ArrayObject<'gc> {
fn colors(&self, context: &mut UpdateContext<'gc>) -> ArrayObject<'gc> {
let read = self.0.read();
ArrayObject::new(
context.gc_context,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<'gc> GradientFilter<'gc> {
Ok(())
}

fn alphas(&self, context: &mut UpdateContext<'_, 'gc>) -> ArrayObject<'gc> {
fn alphas(&self, context: &mut UpdateContext<'gc>) -> ArrayObject<'gc> {
let read = self.0.read();
ArrayObject::new(
context.gc_context,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<'gc> GradientFilter<'gc> {
Ok(())
}

fn ratios(&self, context: &mut UpdateContext<'_, 'gc>) -> ArrayObject<'gc> {
fn ratios(&self, context: &mut UpdateContext<'gc>) -> ArrayObject<'gc> {
let read = self.0.read();
ArrayObject::new(
context.gc_context,
Expand Down
8 changes: 4 additions & 4 deletions core/src/avm1/globals/local_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'gc> LocalConnection<'gc> {
}

pub fn send_status(
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
this: Object<'gc>,
status: &'static str,
) -> Result<(), Error<'gc>> {
Expand All @@ -76,7 +76,7 @@ impl<'gc> LocalConnection<'gc> {
return Ok(());
};
let mut activation = Activation::from_nothing(
context.reborrow(),
context,
ActivationIdentifier::root("[LocalConnection onStatus]"),
root_clip,
);
Expand All @@ -95,7 +95,7 @@ impl<'gc> LocalConnection<'gc> {
}

pub fn run_method(
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
this: Object<'gc>,
method_name: AvmString<'gc>,
amf_arguments: Vec<AmfValue>,
Expand All @@ -105,7 +105,7 @@ impl<'gc> LocalConnection<'gc> {
return Ok(());
};
let mut activation = Activation::from_nothing(
context.reborrow(),
context,
ActivationIdentifier::root("[LocalConnection call]"),
root_clip,
);
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ fn duplicate_movie_clip<'gc>(

pub fn clone_sprite<'gc>(
movie_clip: MovieClip<'gc>,
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
target: AvmString<'gc>,
depth: Depth,
init_object: Option<Object<'gc>>,
Expand Down
12 changes: 6 additions & 6 deletions core/src/avm1/globals/netconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'gc> NetConnection<'gc> {
}

pub fn on_status_event(
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
this: Object<'gc>,
code: &'static str,
) -> Result<(), Error<'gc>> {
Expand All @@ -56,7 +56,7 @@ impl<'gc> NetConnection<'gc> {
return Ok(());
};
let mut activation = Activation::from_nothing(
context.reborrow(),
context,
ActivationIdentifier::root("[NetConnection connect]"),
root_clip,
);
Expand All @@ -77,15 +77,15 @@ impl<'gc> NetConnection<'gc> {

// [NA] I have no idea why this is a thing. It's similar in AVM2 too.
pub fn on_empty_status_event(
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
this: Object<'gc>,
) -> Result<(), Error<'gc>> {
let Some(root_clip) = context.stage.root_clip() else {
tracing::warn!("Ignored NetConnection callback as there's no root movie");
return Ok(());
};
let mut activation = Activation::from_nothing(
context.reborrow(),
context,
ActivationIdentifier::root("[NetConnection connect]"),
root_clip,
);
Expand All @@ -99,7 +99,7 @@ impl<'gc> NetConnection<'gc> {
}

pub fn send_callback(
context: &mut UpdateContext<'_, 'gc>,
context: &mut UpdateContext<'gc>,
responder: Object<'gc>,
callback: ResponderCallback,
message: &flash_lso::types::Value,
Expand All @@ -109,7 +109,7 @@ impl<'gc> NetConnection<'gc> {
return Ok(());
};
let mut activation = Activation::from_nothing(
context.reborrow(),
context,
ActivationIdentifier::root("[NetConnection response]"),
root_clip,
);
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/object/stage_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'gc> StageObject<'gc> {

/// Clears all text field bindings from this stage object, and places the textfields on the unbound list.
/// This is called when the object is removed from the stage.
pub fn unregister_text_field_bindings(self, context: &mut UpdateContext<'_, 'gc>) {
pub fn unregister_text_field_bindings(self, context: &mut UpdateContext<'gc>) {
for binding in self
.0
.write(context.gc_context)
Expand Down
Loading

0 comments on commit 47030b4

Please sign in to comment.