avm2: Use `Gc` instead of `GcCell` in `ProxyObject`
This commit is contained in:
parent
86b8f3fe61
commit
e4499c2ed2
|
@ -1399,7 +1399,7 @@ impl<'gc> Object<'gc> {
|
|||
Self::DictionaryObject(o) => WeakObject::DictionaryObject(DictionaryObjectWeak(GcCell::downgrade(o.0))),
|
||||
Self::QNameObject(o) => WeakObject::QNameObject(QNameObjectWeak(GcCell::downgrade(o.0))),
|
||||
Self::TextFormatObject(o) => WeakObject::TextFormatObject(TextFormatObjectWeak(Gc::downgrade(o.0))),
|
||||
Self::ProxyObject(o) => WeakObject::ProxyObject(ProxyObjectWeak(GcCell::downgrade(o.0))),
|
||||
Self::ProxyObject(o) => WeakObject::ProxyObject(ProxyObjectWeak(Gc::downgrade(o.0))),
|
||||
Self::ErrorObject(o) => WeakObject::ErrorObject(ErrorObjectWeak(GcCell::downgrade(o.0))),
|
||||
Self::Stage3DObject(o) => WeakObject::Stage3DObject(Stage3DObjectWeak(Gc::downgrade(o.0))),
|
||||
Self::Context3DObject(o) => WeakObject::Context3DObject(Context3DObjectWeak(Gc::downgrade(o.0))),
|
||||
|
|
|
@ -8,7 +8,8 @@ use crate::avm2::value::Value;
|
|||
use crate::avm2::Error;
|
||||
use crate::avm2::Multiname;
|
||||
use core::fmt;
|
||||
use gc_arena::{Collect, GcCell, GcWeakCell, Mutation};
|
||||
use gc_arena::barrier::unlock;
|
||||
use gc_arena::{lock::RefLock, Collect, Gc, GcWeak, Mutation};
|
||||
use std::cell::{Ref, RefMut};
|
||||
|
||||
/// A class instance allocator that allocates Proxy objects.
|
||||
|
@ -16,9 +17,9 @@ pub fn proxy_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();
|
||||
|
||||
Ok(ProxyObject(GcCell::new(
|
||||
Ok(ProxyObject(Gc::new(
|
||||
activation.context.gc_context,
|
||||
ProxyObjectData { base },
|
||||
))
|
||||
|
@ -27,16 +28,16 @@ pub fn proxy_allocator<'gc>(
|
|||
|
||||
#[derive(Clone, Collect, Copy)]
|
||||
#[collect(no_drop)]
|
||||
pub struct ProxyObject<'gc>(pub GcCell<'gc, ProxyObjectData<'gc>>);
|
||||
pub struct ProxyObject<'gc>(pub Gc<'gc, ProxyObjectData<'gc>>);
|
||||
|
||||
#[derive(Clone, Collect, Copy, Debug)]
|
||||
#[collect(no_drop)]
|
||||
pub struct ProxyObjectWeak<'gc>(pub GcWeakCell<'gc, ProxyObjectData<'gc>>);
|
||||
pub struct ProxyObjectWeak<'gc>(pub GcWeak<'gc, ProxyObjectData<'gc>>);
|
||||
|
||||
impl fmt::Debug for ProxyObject<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ProxyObject")
|
||||
.field("ptr", &self.0.as_ptr())
|
||||
.field("ptr", &Gc::as_ptr(self.0))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -45,20 +46,20 @@ impl fmt::Debug for ProxyObject<'_> {
|
|||
#[collect(no_drop)]
|
||||
pub struct ProxyObjectData<'gc> {
|
||||
/// Base script object
|
||||
base: ScriptObjectData<'gc>,
|
||||
base: RefLock<ScriptObjectData<'gc>>,
|
||||
}
|
||||
|
||||
impl<'gc> TObject<'gc> for ProxyObject<'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), ProxyObjectData, 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>> {
|
||||
|
|
Loading…
Reference in New Issue