Skip to content

Commit

Permalink
core: Use Activation.gc() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh authored and torokati44 committed Dec 26, 2024
1 parent 1756e39 commit d8e6bd9
Show file tree
Hide file tree
Showing 184 changed files with 1,060 additions and 1,268 deletions.
96 changes: 36 additions & 60 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
.object()
.coerce_to_object(&mut parent_activation);
let child_scope = Gc::new(
parent_activation.context.gc(),
parent_activation.gc(),
Scope::new(
parent_activation.scope(),
scope::ScopeClass::Target,
Expand Down Expand Up @@ -408,7 +408,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
_ => panic!("No script object for display object"),
};
let child_scope = Gc::new(
self.context.gc(),
self.gc(),
Scope::new(
self.context.avm1.global_scope(),
scope::ScopeClass::Target,
Expand Down Expand Up @@ -605,14 +605,12 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let b = self.context.avm1.pop().to_primitive(self)?;

let result: Value<'_> = match (a, b) {
(Value::String(a), Value::String(b)) => {
AvmString::concat(self.context.gc(), b, a).into()
}
(Value::String(a), Value::String(b)) => AvmString::concat(self.gc(), b, a).into(),
(Value::String(a), b) => {
AvmString::concat(self.context.gc(), b.coerce_to_string(self)?, a).into()
AvmString::concat(self.gc(), b.coerce_to_string(self)?, a).into()
}
(a, Value::String(b)) => {
AvmString::concat(self.context.gc(), b, a.coerce_to_string(self)?).into()
AvmString::concat(self.gc(), b, a.coerce_to_string(self)?).into()
}
_ => (b.coerce_to_f64(self)? + a.coerce_to_f64(self)?).into(),
};
Expand Down Expand Up @@ -642,7 +640,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
};
self.context
.avm1
.push(AvmString::new(self.context.gc(), result).into());
.push(AvmString::new(self.gc(), result).into());
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -877,7 +875,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

self.context
.avm1
.set_constant_pool(Gc::new(self.context.gc(), constants));
.set_constant_pool(Gc::new(self.gc(), constants));
self.set_constant_pool(self.context.avm1.constant_pool());

Ok(FrameControl::Continue)
Expand All @@ -899,7 +897,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let func_data = parent_data.to_unbounded_subslice(action.actions);
let constant_pool = self.constant_pool();
let func = Avm1Function::from_swf_function(
self.context.gc(),
self.gc(),
swf_version,
func_data,
action,
Expand All @@ -908,14 +906,11 @@ impl<'a, 'gc> Activation<'a, 'gc> {
self.base_clip(),
);
let name = func.name();
let prototype = ScriptObject::new(
self.context.gc(),
Some(self.context.avm1.prototypes().object),
)
.into();
let prototype =
ScriptObject::new(self.gc(), Some(self.context.avm1.prototypes().object)).into();
let func_obj = FunctionObject::function(
self.context.gc(),
Gc::new(self.context.gc(), func),
self.gc(),
Gc::new(self.gc(), func),
self.context.avm1.prototypes().function,
prototype,
);
Expand Down Expand Up @@ -1103,14 +1098,14 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let sub_prototype = super_prototype.create_bare_object(self, super_prototype)?;

sub_prototype.define_value(
self.context.gc(),
self.gc(),
"constructor",
superclass.into(),
Attribute::DONT_ENUM,
);

sub_prototype.define_value(
self.context.gc(),
self.gc(),
"__constructor__",
superclass.into(),
Attribute::DONT_ENUM,
Expand Down Expand Up @@ -1472,7 +1467,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
Value::Undefined
} else {
ArrayObject::new(
self.context.gc(),
self.gc(),
self.context.avm1.prototypes().array,
(0..num_elements as i32).map(|_| self.context.avm1.pop()),
)
Expand All @@ -1489,10 +1484,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 = ScriptObject::new(
self.context.gc(),
Some(self.context.avm1.prototypes().object),
);
let object = ScriptObject::new(self.gc(), Some(self.context.avm1.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 @@ -1529,7 +1521,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
}

let prototype = constructor.get("prototype", self)?.coerce_to_object(self);
prototype.set_interfaces(self.context.gc(), interfaces);
prototype.set_interfaces(self.gc(), interfaces);

Ok(FrameControl::Continue)
}
Expand Down Expand Up @@ -1606,7 +1598,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
};
self.context
.avm1
.push(AvmString::new_utf8(self.context.gc(), result).into());
.push(AvmString::new_utf8(self.gc(), result).into());
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -1650,7 +1642,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let result = &s[start.min(end)..end];
self.context
.avm1
.push(AvmString::new(self.context.gc(), result).into());
.push(AvmString::new(self.gc(), result).into());
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -1823,9 +1815,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
SwfValue::Int(v) => v.into(),
SwfValue::Float(v) => v.into(),
SwfValue::Double(v) => v.into(),
SwfValue::Str(v) => {
AvmString::new(self.context.gc(), v.decode(self.encoding())).into()
}
SwfValue::Str(v) => AvmString::new(self.gc(), v.decode(self.encoding())).into(),
SwfValue::Register(v) => self.current_register(v),
SwfValue::ConstantPool(i) => {
if let Some(value) = self.constant_pool().get(i as usize) {
Expand Down Expand Up @@ -2020,11 +2010,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
.object()
.coerce_to_object(self);

self.set_scope(Scope::new_target_scope(
self.scope(),
clip_obj,
self.context.gc(),
));
self.set_scope(Scope::new_target_scope(self.scope(), clip_obj, self.gc()));
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -2101,7 +2087,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
// TODO(Herschel): Result with non-string operands?
let a = self.context.avm1.pop().coerce_to_string(self)?;
let b = self.context.avm1.pop().coerce_to_string(self)?;
let s = AvmString::concat(self.context.gc(), b, a);
let s = AvmString::concat(self.gc(), b, a);
self.context.avm1.push(s.into());
Ok(FrameControl::Continue)
}
Expand Down Expand Up @@ -2135,7 +2121,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let result = &s[start.min(end)..end];
self.context
.avm1
.push(AvmString::new(self.context.gc(), result).into());
.push(AvmString::new(self.gc(), result).into());
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -2180,7 +2166,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let param = self.context.avm1.pop().coerce_to_object(self);
let result = if let Some(display_object) = param.as_display_object() {
let path = display_object.path();
AvmString::new(self.context.gc(), path).into()
AvmString::new(self.gc(), path).into()
} else {
Value::Undefined
};
Expand Down Expand Up @@ -2214,7 +2200,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
self.context.stage.set_quality(self.context, new_quality);
self.context
.stage
.set_use_bitmap_downsampling(self.context.gc(), use_bitmap_downsamping);
.set_use_bitmap_downsampling(self.gc(), use_bitmap_downsamping);
Ok(FrameControl::Continue)
}

Expand Down Expand Up @@ -2276,10 +2262,8 @@ impl<'a, 'gc> Activation<'a, 'gc> {

match catch_vars {
CatchVar::Var(name) => {
let name = AvmString::new(
activation.context.gc(),
name.decode(activation.encoding()),
);
let name =
AvmString::new(activation.gc(), name.decode(activation.encoding()));
activation.set_variable(name, value.to_owned())?
}
CatchVar::Register(id) => {
Expand Down Expand Up @@ -2399,10 +2383,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
value => {
// Note that primitives get boxed at this point.
let object = value.coerce_to_object(self);
let with_scope = Gc::new(
self.context.gc(),
Scope::new_with_scope(self.scope(), object),
);
let with_scope = Gc::new(self.gc(), Scope::new_with_scope(self.scope(), object));
let mut new_activation = self.with_new_scope("[With]", with_scope);
if let ReturnType::Explicit(value) = new_activation.run_actions(code)? {
Ok(FrameControl::Return(ReturnType::Explicit(value)))
Expand Down Expand Up @@ -2676,7 +2657,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
child.object()
}
} else {
let name = AvmString::new(self.context.gc(), name);
let name = AvmString::new(self.gc(), name);
if path_has_slash {
object.get(name, self).unwrap()
} else {
Expand Down Expand Up @@ -2791,7 +2772,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
true,
path_has_slash,
)? {
let var_name = AvmString::new(self.context.gc(), var_name);
let var_name = AvmString::new(self.gc(), var_name);
if object.has_property(self, var_name) {
return Ok(CallableValue::Callable(object, object.get(var_name, self)?));
}
Expand Down Expand Up @@ -2877,7 +2858,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
if let Some(object) =
self.resolve_target_path(avm1_root, *scope.locals(), path, true, true)?
{
let var_name = AvmString::new(self.context.gc(), var_name);
let var_name = AvmString::new(self.gc(), var_name);
object.set(var_name, value, self)?;
return Ok(());
}
Expand All @@ -2904,9 +2885,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
level
} else {
let level: DisplayObject<'_> =
MovieClip::new(self.base_clip().movie(), self.context.gc()).into();
MovieClip::new(self.base_clip().movie(), self.gc()).into();

level.set_depth(self.context.gc(), level_id);
level.set_depth(self.gc(), level_id);
level.set_default_root_name(self.context);
self.get_root_parent_container()
.and_then(|c| c.replace_at_depth(self.context, level, level_id));
Expand Down Expand Up @@ -2989,7 +2970,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

pub fn set_scope_to_display_object(&mut self, object: DisplayObject<'gc>) {
self.scope = Gc::new(
self.context.gc(),
self.gc(),
Scope::new(
self.scope,
ScopeClass::Target,
Expand Down Expand Up @@ -3059,8 +3040,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
/// This inserts a value as a stored property on the local scope. If the property already
/// exists, it will be forcefully overwritten. Used internally to initialize objects.
pub fn force_define_local(&mut self, name: AvmString<'gc>, value: Value<'gc>) {
self.scope
.force_define_local(name, value, self.context.gc())
self.scope.force_define_local(name, value, self.gc())
}

/// Returns value of `this` as a reference.
Expand Down Expand Up @@ -3165,11 +3145,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {

let clip_obj = self.target_clip_or_root().object().coerce_to_object(self);

self.set_scope(Scope::new_target_scope(
self.scope(),
clip_obj,
self.context.gc(),
));
self.set_scope(Scope::new_target_scope(self.scope(), clip_obj, self.gc()));
Ok(FrameControl::Continue)
}
}
10 changes: 5 additions & 5 deletions core/src/avm1/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ mod tests {
#[test]
fn dump_empty_object() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.context.gc(), None);
let object = ScriptObject::new(activation.gc(), None);
assert_eq!(
VariableDumper::dump(&object.into(), " ", activation),
"[object #0] {}"
Expand All @@ -274,8 +274,8 @@ mod tests {
#[test]
fn dump_object() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.context.gc(), None);
let child = ScriptObject::new(activation.context.gc(), None);
let object = ScriptObject::new(activation.gc(), None);
let child = ScriptObject::new(activation.gc(), None);
object.set("self", object.into(), activation)?;
object.set("test", "value".into(), activation)?;
object.set("child", child.into(), activation)?;
Expand All @@ -292,8 +292,8 @@ mod tests {
#[test]
fn dump_variables() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.context.gc(), None);
let child = ScriptObject::new(activation.context.gc(), None);
let object = ScriptObject::new(activation.gc(), None);
let child = ScriptObject::new(activation.gc(), None);
object.set("self", object.into(), activation)?;
object.set("test", "value".into(), activation)?;
object.set("child", child.into(), activation)?;
Expand Down
8 changes: 4 additions & 4 deletions core/src/avm1/flv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ fn avm1_object_from_flv_variables<'gc>(
variables: Vec<FlvVariable>,
) -> Avm1Value<'gc> {
let object_proto = activation.context.avm1.prototypes().object;
let info_object = ScriptObject::new(activation.context.gc(), Some(object_proto));
let info_object = ScriptObject::new(activation.gc(), Some(object_proto));

for value in variables {
let property_name = value.name;

info_object
.set(
AvmString::new_utf8_bytes(activation.context.gc(), property_name),
AvmString::new_utf8_bytes(activation.gc(), property_name),
value.data.to_avm1_value(activation),
activation,
)
Expand All @@ -40,7 +40,7 @@ fn avm1_array_from_flv_values<'gc>(
values: Vec<FlvValue>,
) -> Avm1Value<'gc> {
ArrayObject::new(
activation.context.gc(),
activation.gc(),
activation.context.avm1.prototypes().array,
values.iter().map(|v| v.clone().to_avm1_value(activation)),
)
Expand All @@ -59,7 +59,7 @@ impl<'gc> FlvValueAvm1Ext<'gc> for FlvValue<'_> {
}
FlvValue::StrictArray(values) => avm1_array_from_flv_values(activation, values),
FlvValue::String(string_data) | FlvValue::LongString(string_data) => {
AvmString::new_utf8_bytes(activation.context.gc(), string_data).into()
AvmString::new_utf8_bytes(activation.gc(), string_data).into()
}
FlvValue::Date {
unix_time,
Expand Down
Loading

0 comments on commit d8e6bd9

Please sign in to comment.