Used install_instance_slots() instead of adding slots manually

This commit is contained in:
dowgird 2022-08-01 22:28:04 +02:00 committed by Adrian Wielgosik
parent fb0a984415
commit 5ccc981357
3 changed files with 14 additions and 9 deletions

View File

@ -1583,7 +1583,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
vname,
self.context.gc_context,
)?;
let so = ScriptObject::catch_scope(self.context.gc_context, &qname);
let so = ScriptObject::catch_scope(self, &qname);
self.context.avm2.push(so);
}

View File

@ -105,17 +105,18 @@ impl<'gc> ScriptObject<'gc> {
/// A special case for `newcatch` implementation. Basically a variable (q)name
/// which maps to slot 1.
pub fn catch_scope(mc: MutationContext<'gc, '_>, qname: &QName<'gc>) -> Object<'gc> {
pub fn catch_scope(
activation: &mut Activation<'_, 'gc, '_>,
qname: &QName<'gc>,
) -> Object<'gc> {
let mut base = ScriptObjectData::custom_new(None, None);
let mc = activation.context.gc_context;
let vt = VTable::newcatch(mc, &qname);
base.set_vtable(vt);
// Compilers expect `setslot 1` to work on the `newcatch` object.
// `setslot 1` maps to index 1, so we need two slots here, because Ruffle
// maps setslot arg directly to the slot array index, unlike AVM which does the
// -1 shift.
base.install_slot();
base.install_slot();
ScriptObject(GcCell::allocate(mc, base)).into()
let mut so = ScriptObject(GcCell::allocate(mc, base));
so.install_instance_slots(activation);
so.into()
}
}

View File

@ -79,6 +79,10 @@ impl<'gc> VTable<'gc> {
protected_namespace: None,
resolved_traits: rt,
method_table: vec![],
// Compilers expect `setslot 1` to work on the `newcatch` object.
// `setslot 1` maps to index 1, so we need two slots here, because Ruffle
// maps setslot arg directly to the slot array index, unlike AVM which does the
// -1 shift.
default_slots: vec![None, None],
slot_classes: vec![PropertyClass::Any, PropertyClass::Any],
},