Skip to content
Merged
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
37 changes: 23 additions & 14 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ impl<'a, 'gc> Activation<'a, 'gc> {
&mut self.context.strings
}

pub fn prototypes(&self) -> &crate::avm1::globals::SystemPrototypes<'gc> {
self.context.avm1.prototypes(self.swf_version())
}

/// Obtain a reference to the global scope.
pub fn global_scope(&self) -> Gc<'gc, Scope<'gc>> {
self.context.avm1.global_scope(self.swf_version())
}
/// Obtain a reference to `_global`.
pub fn global_object(&self) -> Object<'gc> {
self.global_scope().locals_cell()
}

#[expect(clippy::too_many_arguments)]
pub fn from_action(
context: &'a mut UpdateContext<'gc>,
Expand Down Expand Up @@ -282,15 +295,17 @@ impl<'a, 'gc> Activation<'a, 'gc> {
) -> Self {
avm_debug!(context.avm1, "START {id}");

let swf_version = base_clip.swf_version();
let scope = context.avm1.global_scope(swf_version);
Self {
id,
swf_version: base_clip.swf_version(),
scope: context.avm1.global_scope(),
swf_version,
scope,
constant_pool: context.avm1.constant_pool(),
base_clip,
target_clip: Some(base_clip),
base_clip_unloaded: base_clip.avm1_removed(),
this: context.avm1.global_object().into(),
this: scope.locals_cell().into(),
callee: None,
local_registers: None,
context,
Expand Down Expand Up @@ -380,7 +395,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let child_scope = Gc::new(
self.gc(),
Scope::new(
self.context.avm1.global_scope(),
self.context.avm1.global_scope(swf_version),
scope::ScopeClass::Target,
clip_obj,
),
Expand Down Expand Up @@ -882,14 +897,11 @@ impl<'a, 'gc> Activation<'a, 'gc> {
MovieClipReference::try_from_stage_object(self, bc).unwrap(),
);
let name = func.name();
let prototype = Object::new(
&self.context.strings,
Some(self.context.avm1.prototypes().object),
);
let prototype = Object::new(&self.context.strings, Some(self.prototypes().object));
let func_obj = FunctionObject::function(
&self.context.strings,
Gc::new(self.gc(), func),
self.context.avm1.prototypes().function,
self.prototypes().function,
prototype,
);
if let Some(name) = name {
Expand Down Expand Up @@ -1453,10 +1465,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
// InitArray pops no args and pushes undefined if num_props is out of range.
Value::Undefined
} else {
let object = Object::new(
&self.context.strings,
Some(self.context.avm1.prototypes().object),
);
let object = Object::new(&self.context.strings, Some(self.prototypes().object));
for _ in 0..num_props as usize {
let value = self.context.avm1.pop();
let name_val = self.context.avm1.pop();
Expand Down Expand Up @@ -2932,7 +2941,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

/// Returns whether property keys should be case sensitive based on the current SWF version.
pub fn is_case_sensitive(&self) -> bool {
self.swf_version() > 6
crate::avm1::runtime::Avm1::is_case_sensitive(self.swf_version())
}

/// Resolve a particular named local variable within this activation.
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/flv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn avm1_object_from_flv_variables<'gc>(
activation: &mut Activation<'_, 'gc>,
variables: Vec<FlvVariable>,
) -> Avm1Value<'gc> {
let object_proto = activation.context.avm1.prototypes().object;
let object_proto = activation.prototypes().object;
let info_object = Object::new(activation.strings(), Some(object_proto));

for value in variables {
Expand All @@ -29,7 +29,7 @@ fn avm1_date_from_flv_date<'gc>(
unix_time: f64,
_local_offset: i16,
) -> Avm1Value<'gc> {
let constructor = activation.context.avm1.prototypes().date_constructor;
let constructor = activation.prototypes().date_constructor;
let result = constructor.construct(activation, &[unix_time.into()]);

result.expect("AVM1 date constructed from FLV date")
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'gc> Avm1Function<'gc> {

fn load_global(&self, frame: &mut Activation<'_, 'gc>, preload_r: &mut u8) {
if self.flags.contains(FunctionFlags::PRELOAD_GLOBAL) {
let global = frame.context.avm1.global_object();
let global = frame.global_object();
frame.set_local_register(*preload_r, global.into());
*preload_r += 1;
}
Expand Down Expand Up @@ -394,7 +394,7 @@ impl<'gc> Executable<'gc> {
let scope = Gc::new(
activation.gc(),
Scope::new(
activation.context.avm1.global_scope(),
activation.global_scope(),
super::scope::ScopeClass::Target,
base_clip_obj,
),
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'gc> ArrayBuilder<'gc> {
}

pub fn new(activation: &Activation<'_, 'gc>) -> Self {
let proto = activation.context.avm1.prototypes().array;
let proto = activation.prototypes().array;
Self::new_with_proto(&activation.context.strings, proto)
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/avm1/globals/as_broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ fn initialize<'gc>(
initialize_internal(
&activation.context.strings,
broadcaster,
activation.context.avm1.broadcaster_functions(),
activation.context.avm1.prototypes().array,
activation
.context
.avm1
.broadcaster_functions(activation.swf_version()),
activation.prototypes().array,
);
}
Ok(Value::Undefined)
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/bitmap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn get_rectangle<'gc>(
) -> Result<Value<'gc>, Error<'gc>> {
if let NativeObject::BitmapData(bitmap_data) = this.native() {
if !bitmap_data.disposed() {
let proto = activation.context.avm1.prototypes().rectangle_constructor;
let proto = activation.prototypes().rectangle_constructor;
let rect = proto.construct(
activation,
&[
Expand Down Expand Up @@ -772,7 +772,7 @@ fn get_color_bounds_rect<'gc>(
color,
);

let proto = activation.context.avm1.prototypes().rectangle_constructor;
let proto = activation.prototypes().rectangle_constructor;
let rect =
proto.construct(activation, &[x.into(), y.into(), w.into(), h.into()])?;
return Ok(rect);
Expand Down
18 changes: 9 additions & 9 deletions core/src/avm1/globals/bitmap_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,48 +100,48 @@ pub fn filter_to_avm1<'gc>(activation: &mut Activation<'_, 'gc>, filter: Filter)
let (native, proto) = match filter {
Filter::BevelFilter(filter) => (
NativeObject::BevelFilter(BevelFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().bevel_filter,
activation.prototypes().bevel_filter,
),
Filter::BlurFilter(filter) => (
NativeObject::BlurFilter(BlurFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().blur_filter,
activation.prototypes().blur_filter,
),
Filter::ColorMatrixFilter(filter) => (
NativeObject::ColorMatrixFilter(ColorMatrixFilter::from_filter(
activation.gc(),
filter,
)),
activation.context.avm1.prototypes().color_matrix_filter,
activation.prototypes().color_matrix_filter,
),
Filter::ConvolutionFilter(filter) => (
NativeObject::ConvolutionFilter(ConvolutionFilter::from_filter(
activation.gc(),
filter,
)),
activation.context.avm1.prototypes().convolution_filter,
activation.prototypes().convolution_filter,
),
Filter::GlowFilter(filter) => (
NativeObject::GlowFilter(GlowFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().glow_filter,
activation.prototypes().glow_filter,
),
Filter::DropShadowFilter(filter) => (
NativeObject::DropShadowFilter(DropShadowFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().drop_shadow_filter,
activation.prototypes().drop_shadow_filter,
),
Filter::DisplacementMapFilter(filter) => (
NativeObject::DisplacementMapFilter(DisplacementMapFilter::from_filter(
activation.gc(),
filter,
)),
activation.context.avm1.prototypes().displacement_map_filter,
activation.prototypes().displacement_map_filter,
),
Filter::GradientBevelFilter(filter) => (
NativeObject::GradientBevelFilter(GradientFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().gradient_bevel_filter,
activation.prototypes().gradient_bevel_filter,
),
Filter::GradientGlowFilter(filter) => (
NativeObject::GradientGlowFilter(GradientFilter::from_filter(activation.gc(), filter)),
activation.context.avm1.prototypes().gradient_glow_filter,
activation.prototypes().gradient_glow_filter,
),
Filter::ShaderFilter(_) => {
unreachable!(
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn get_transform<'gc>(
let color_transform = base.color_transform();
let out = Object::new(
&activation.context.strings,
Some(activation.context.avm1.prototypes().object),
Some(activation.prototypes().object),
);
out.set(
istr!("ra"),
Expand Down
6 changes: 1 addition & 5 deletions core/src/avm1/globals/color_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl<'gc> ColorTransformObject {
color_transform.b_add.into(),
color_transform.a_add.into(),
];
let constructor = activation
.context
.avm1
.prototypes()
.color_transform_constructor;
let constructor = activation.prototypes().color_transform_constructor;
constructor.construct(activation, &args)
}

Expand Down
10 changes: 3 additions & 7 deletions core/src/avm1/globals/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn constructor<'gc>(

let built_in_items = Object::new(
&activation.context.strings,
Some(activation.context.avm1.prototypes().object),
Some(activation.prototypes().object),
);

built_in_items.set(istr!("print"), true.into(), activation)?;
Expand All @@ -48,7 +48,7 @@ fn constructor<'gc>(

this.set(istr!("builtInItems"), built_in_items.into(), activation)?;

let constructor = activation.context.avm1.prototypes().array_constructor;
let constructor = activation.prototypes().array_constructor;
let custom_items = constructor.construct(activation, &[])?;

this.set(istr!("customItems"), custom_items, activation)?;
Expand All @@ -65,11 +65,7 @@ pub fn copy<'gc>(
.get(istr!("onSelect"), activation)?
.coerce_to_object(activation);

let constructor = activation
.context
.avm1
.prototypes()
.context_menu_constructor;
let constructor = activation.prototypes().context_menu_constructor;
let copy = constructor
.construct(activation, &[callback.into()])?
.coerce_to_object(activation);
Expand Down
6 changes: 1 addition & 5 deletions core/src/avm1/globals/context_menu_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ pub fn copy<'gc>(
.get(istr!("visible"), activation)?
.as_bool(activation.swf_version());

let constructor = activation
.context
.avm1
.prototypes()
.context_menu_item_constructor;
let constructor = activation.prototypes().context_menu_item_constructor;
let copy = constructor.construct(
activation,
&[
Expand Down
12 changes: 6 additions & 6 deletions core/src/avm1/globals/displacement_map_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ impl<'gc> DisplacementMapFilter<'gc> {
Self(Gc::new(gc_context, self.0.as_ref().clone()))
}

fn map_bitmap(self, context: &mut UpdateContext<'gc>) -> Option<Object<'gc>> {
fn map_bitmap(self, activation: &mut Activation<'_, 'gc>) -> Option<Object<'gc>> {
if let Some(map_bitmap) = self.0.map_bitmap.get() {
let proto = context.avm1.prototypes().bitmap_data;
let result = Object::new(&context.strings, Some(proto));
result.set_native(context.gc(), NativeObject::BitmapData(map_bitmap));
let proto = activation.prototypes().bitmap_data;
let result = Object::new(activation.strings(), Some(proto));
result.set_native(activation.gc(), NativeObject::BitmapData(map_bitmap));
Some(result)
} else {
None
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'gc> DisplacementMapFilter<'gc> {
fn map_point(self, activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, Error<'gc>> {
let map_point = self.0.map_point.get();
let args = &[map_point.x.into(), map_point.y.into()];
let constructor = activation.context.avm1.prototypes().point_constructor;
let constructor = activation.prototypes().point_constructor;
constructor.construct(activation, args)
}

Expand Down Expand Up @@ -353,7 +353,7 @@ fn method<'gc>(

Ok(match index {
GET_MAP_BITMAP => this
.map_bitmap(activation.context)
.map_bitmap(activation)
.map_or(Value::Undefined, Value::from),
SET_MAP_BITMAP => {
this.set_map_bitmap(activation, args.get(0))?;
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/file_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'gc> FileReferenceObject<'gc> {

self.0.is_initialised.set(true);

let date_proto = activation.context.avm1.prototypes().date_constructor;
let date_proto = activation.prototypes().date_constructor;
if let Some(creation_time) = result.creation_time() {
if let Ok(Value::Object(obj)) = date_proto.construct(
activation,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn call<'gc>(
myargs: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let this = match myargs.get(0).unwrap_or(&Value::Undefined) {
Value::Undefined | Value::Null => activation.context.avm1.global_object(),
Value::Undefined | Value::Null => activation.global_object(),
this_val => this_val.coerce_to_object(activation),
};
let empty = [];
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn apply<'gc>(
myargs: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let this = match myargs.get(0).unwrap_or(&Value::Undefined) {
Value::Undefined | Value::Null => activation.context.avm1.global_object(),
Value::Undefined | Value::Null => activation.global_object(),
this_val => this_val.coerce_to_object(activation),
};
let args_object = myargs.get(1).cloned().unwrap_or(Value::Undefined);
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/local_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'gc> LocalConnection<'gc> {
ActivationIdentifier::root("[LocalConnection onStatus]"),
root_clip,
);
let constructor = activation.context.avm1.prototypes().object_constructor;
let constructor = activation.prototypes().object_constructor;
let event = constructor
.construct(&mut activation, &[])?
.coerce_to_object(&mut activation);
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ mod tests {

fn setup<'gc>(activation: &mut Activation<'_, 'gc>) -> Object<'gc> {
create(&mut DeclContext {
object_proto: activation.context.avm1.prototypes().object,
fn_proto: activation.context.avm1.prototypes().function,
object_proto: activation.prototypes().object,
fn_proto: activation.prototypes().function,
strings: activation.strings(),
})
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn matrix_to_value<'gc>(
matrix.tx.to_pixels().into(),
matrix.ty.to_pixels().into(),
];
let constructor = activation.context.avm1.prototypes().matrix_constructor;
let constructor = activation.prototypes().matrix_constructor;
let object = constructor.construct(activation, &args)?;
Ok(object)
}
Expand Down Expand Up @@ -251,7 +251,7 @@ fn clone<'gc>(
this.get(istr!("tx"), activation)?,
this.get(istr!("ty"), activation)?,
];
let constructor = activation.context.avm1.prototypes().matrix_constructor;
let constructor = activation.prototypes().matrix_constructor;
let cloned = constructor.construct(activation, &args)?;
Ok(cloned)
}
Expand Down
Loading
Loading