avm2: Use `Gc` instead of `GcCell` in `FontObject`

This commit is contained in:
Lord-McSweeney 2024-07-03 14:25:02 +03:00 committed by Lord-McSweeney
parent 4e15bcb9b7
commit fb168f46b3
2 changed files with 17 additions and 17 deletions

View File

@ -1413,7 +1413,7 @@ impl<'gc> Object<'gc> {
Self::ShaderDataObject(o) => WeakObject::ShaderDataObject(ShaderDataObjectWeak(Gc::downgrade(o.0))),
Self::SocketObject(o) => WeakObject::SocketObject(SocketObjectWeak(Gc::downgrade(o.0))),
Self::FileReferenceObject(o) => WeakObject::FileReferenceObject(FileReferenceObjectWeak(Gc::downgrade(o.0))),
Self::FontObject(o) => WeakObject::FontObject(FontObjectWeak(GcCell::downgrade(o.0))),
Self::FontObject(o) => WeakObject::FontObject(FontObjectWeak(Gc::downgrade(o.0))),
Self::LocalConnectionObject(o) => WeakObject::LocalConnectionObject(LocalConnectionObjectWeak(Gc::downgrade(o.0))),
}
}

View File

@ -4,8 +4,8 @@ use crate::avm2::value::Value;
use crate::avm2::{Activation, ClassObject, Error};
use crate::character::Character;
use crate::font::Font;
use gc_arena::Mutation;
use gc_arena::{Collect, GcCell, GcWeakCell};
use gc_arena::barrier::unlock;
use gc_arena::{lock::RefLock, Collect, Gc, GcWeak, Mutation};
use std::cell::{Ref, RefMut};
use std::fmt;
@ -14,7 +14,7 @@ pub fn font_allocator<'gc>(
class: ClassObject<'gc>,
activation: &mut Activation<'_, 'gc>,
) -> Result<Object<'gc>, Error<'gc>> {
let base = ScriptObjectData::new(class);
let base = ScriptObjectData::new(class).into();
let font = if let Some((movie, id)) = activation
.context
@ -35,7 +35,7 @@ pub fn font_allocator<'gc>(
None
};
Ok(FontObject(GcCell::new(
Ok(FontObject(Gc::new(
activation.context.gc_context,
FontObjectData { base, font },
))
@ -44,12 +44,16 @@ pub fn font_allocator<'gc>(
#[derive(Clone, Collect, Copy)]
#[collect(no_drop)]
pub struct FontObject<'gc>(pub GcCell<'gc, FontObjectData<'gc>>);
pub struct FontObject<'gc>(pub Gc<'gc, FontObjectData<'gc>>);
#[derive(Clone, Collect, Copy, Debug)]
#[collect(no_drop)]
pub struct FontObjectWeak<'gc>(pub GcWeak<'gc, FontObjectData<'gc>>);
impl<'gc> FontObject<'gc> {
pub fn for_font(mc: &Mutation<'gc>, class: ClassObject<'gc>, font: Font<'gc>) -> Object<'gc> {
let base = ScriptObjectData::new(class);
FontObject(GcCell::new(
let base = ScriptObjectData::new(class).into();
FontObject(Gc::new(
mc,
FontObjectData {
base,
@ -60,21 +64,17 @@ impl<'gc> FontObject<'gc> {
}
}
#[derive(Clone, Collect, Copy, Debug)]
#[collect(no_drop)]
pub struct FontObjectWeak<'gc>(pub GcWeakCell<'gc, FontObjectData<'gc>>);
impl<'gc> TObject<'gc> for FontObject<'gc> {
fn base(&self) -> Ref<ScriptObjectData<'gc>> {
Ref::map(self.0.read(), |read| &read.base)
self.0.base.borrow()
}
fn base_mut(&self, mc: &Mutation<'gc>) -> RefMut<ScriptObjectData<'gc>> {
RefMut::map(self.0.write(mc), |write| &mut write.base)
unlock!(Gc::write(mc, self.0), FontObjectData, base).borrow_mut()
}
fn as_ptr(&self) -> *const ObjectPtr {
self.0.as_ptr() as *const ObjectPtr
Gc::as_ptr(self.0) as *const ObjectPtr
}
fn value_of(&self, _mc: &Mutation<'gc>) -> Result<Value<'gc>, Error<'gc>> {
@ -82,7 +82,7 @@ impl<'gc> TObject<'gc> for FontObject<'gc> {
}
fn as_font(&self) -> Option<Font<'gc>> {
self.0.read().font
self.0.font
}
}
@ -90,7 +90,7 @@ impl<'gc> TObject<'gc> for FontObject<'gc> {
#[collect(no_drop)]
pub struct FontObjectData<'gc> {
/// Base script object
base: ScriptObjectData<'gc>,
base: RefLock<ScriptObjectData<'gc>>,
font: Option<Font<'gc>>,
}