avm2: install_const_late always appends slots

This commit is contained in:
Adrian Wielgosik 2021-12-04 21:57:40 +01:00 committed by Adrian Wielgosik
parent b4d444175d
commit 24247dff0b
4 changed files with 6 additions and 31 deletions

View File

@ -314,7 +314,7 @@ fn function<'gc>(
let method = Method::from_builtin(nf, name, mc); let method = Method::from_builtin(nf, name, mc);
let as3fn = FunctionObject::from_method(activation, method, scope, None, None).into(); let as3fn = FunctionObject::from_method(activation, method, scope, None, None).into();
domain.export_definition(qname, script, mc)?; domain.export_definition(qname, script, mc)?;
global.install_const_late(mc, None, qname, as3fn); global.install_const_late(mc, qname, as3fn);
Ok(()) Ok(())
} }
@ -332,7 +332,7 @@ fn dynamic_class<'gc>(
let class = class_object.inner_class_definition(); let class = class_object.inner_class_definition();
let name = class.read().name(); let name = class.read().name();
global.install_const_late(mc, None, name, class_object.into()); global.install_const_late(mc, name, class_object.into());
domain.export_definition(name, script, mc) domain.export_definition(name, script, mc)
} }
@ -375,7 +375,6 @@ fn class<'gc>(
let class_object = ClassObject::from_class(activation, class_def, super_class)?; let class_object = ClassObject::from_class(activation, class_def, super_class)?;
global.install_const_late( global.install_const_late(
activation.context.gc_context, activation.context.gc_context,
None,
class_name, class_name,
class_object.into(), class_object.into(),
); );
@ -395,7 +394,7 @@ fn constant<'gc>(
let (_, mut global, mut domain) = script.init(); let (_, mut global, mut domain) = script.init();
let name = QName::new(Namespace::package(package), name); let name = QName::new(Namespace::package(package), name);
domain.export_definition(name, script, mc)?; domain.export_definition(name, script, mc)?;
global.install_const_late(mc, None, name, value); global.install_const_late(mc, name, value);
Ok(()) Ok(())
} }

View File

@ -73,7 +73,6 @@ pub fn class_init<'gc>(
globals.install_const_late( globals.install_const_late(
activation.context.gc_context, activation.context.gc_context,
None,
int_vector_name, int_vector_name,
int_vector_class.into(), int_vector_class.into(),
); );
@ -89,7 +88,6 @@ pub fn class_init<'gc>(
globals.install_const_late( globals.install_const_late(
activation.context.gc_context, activation.context.gc_context,
None,
uint_vector_name, uint_vector_name,
uint_vector_class.into(), uint_vector_class.into(),
); );
@ -105,7 +103,6 @@ pub fn class_init<'gc>(
globals.install_const_late( globals.install_const_late(
activation.context.gc_context, activation.context.gc_context,
None,
number_vector_name, number_vector_name,
number_vector_class.into(), number_vector_class.into(),
); );
@ -120,7 +117,6 @@ pub fn class_init<'gc>(
globals.install_const_late( globals.install_const_late(
activation.context.gc_context, activation.context.gc_context,
None,
object_vector_name, object_vector_name,
object_vector_class.into(), object_vector_class.into(),
); );

View File

@ -560,18 +560,15 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
} }
/// Install a const trait on the global object. /// Install a const trait on the global object.
/// This should only ever be called on the `global` object, during initialization. /// This should only ever be called on the `global` object, during initialization.
fn install_const_late( fn install_const_late(
&mut self, &mut self,
mc: MutationContext<'gc, '_>, mc: MutationContext<'gc, '_>,
slot_id: Option<u32>,
name: QName<'gc>, name: QName<'gc>,
value: Value<'gc>, value: Value<'gc>,
) { ) {
let new_slot_id = self.vtable().unwrap().install_const_trait_late(mc, slot_id, name, value.clone()); let new_slot_id = self.vtable().unwrap().install_const_trait_late(mc, name, value.clone());
self.base_mut(mc).install_const_slot_late(new_slot_id, value); self.base_mut(mc).install_const_slot_late(new_slot_id, value);
} }

View File

@ -288,30 +288,13 @@ impl<'gc> VTable<'gc> {
pub fn install_const_trait_late( pub fn install_const_trait_late(
self, self,
mc: MutationContext<'gc, '_>, mc: MutationContext<'gc, '_>,
slot_id: Option<u32>,
name: QName<'gc>, name: QName<'gc>,
value: Value<'gc>, value: Value<'gc>,
) -> u32 { ) -> u32 {
let mut write = self.0.write(mc); let mut write = self.0.write(mc);
let new_slot_id = if let Some(slot_id) = slot_id { write.default_slots.push(Some(value));
let new_slot_id = write.default_slots.len() as u32 - 1;
if slot_id == 0 {
write.default_slots.push(Some(value));
write.default_slots.len() as u32 - 1
} else {
// Should be safe from slot conflicts, as `global` has a fresh Object vtable.
if slot_id as usize >= write.default_slots.len() {
write.default_slots.resize_with(slot_id as usize + 1, Default::default);
}
write.default_slots[slot_id as usize] = Some(value);
slot_id
}
} else {
write.default_slots.push(Some(value));
write.default_slots.len() as u32 - 1
};
write.resolved_traits.insert(name, Property::new_slot(new_slot_id)); write.resolved_traits.insert(name, Property::new_slot(new_slot_id));
new_slot_id new_slot_id