Skip to content

Commit 9ea3b21

Browse files
committed
avm1: Replace GcCell with Gc in FunctionObject
This refactor replaces GcCell with Gc and uses interior mutability instead.
1 parent 0998a5b commit 9ea3b21

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

core/src/avm1/function.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::avm1::{ArrayObject, Object, ObjectPtr, ScriptObject, TObject};
1010
use crate::display_object::{DisplayObject, TDisplayObject};
1111
use crate::string::{AvmString, StringContext, SwfStrExt as _};
1212
use crate::tag_utils::SwfSlice;
13-
use gc_arena::{Collect, Gc, GcCell, Mutation};
13+
use gc_arena::{Collect, Gc, Mutation};
1414
use ruffle_macros::istr;
1515
use std::{borrow::Cow, fmt, num::NonZeroU8};
1616
use swf::{avm1::types::FunctionFlags, SwfStr};
@@ -488,12 +488,12 @@ impl<'gc> From<Gc<'gc, Avm1Function<'gc>>> for Executable<'gc> {
488488
/// Represents an `Object` that holds executable code.
489489
#[derive(Clone, Collect, Copy)]
490490
#[collect(no_drop)]
491-
pub struct FunctionObject<'gc>(GcCell<'gc, FunctionObjectData<'gc>>);
491+
pub struct FunctionObject<'gc>(Gc<'gc, FunctionObjectData<'gc>>);
492492

493493
impl fmt::Debug for FunctionObject<'_> {
494494
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
495495
f.debug_struct("FunctionObject")
496-
.field("ptr", &self.0.as_ptr())
496+
.field("ptr", &Gc::as_ptr(self.0))
497497
.finish()
498498
}
499499
}
@@ -517,7 +517,7 @@ impl<'gc> FunctionObject<'gc> {
517517
constructor: Option<Executable<'gc>>,
518518
fn_proto: Object<'gc>,
519519
) -> Self {
520-
Self(GcCell::new(
520+
Self(Gc::new(
521521
context.gc(),
522522
FunctionObjectData {
523523
base: ScriptObject::new(context, Some(fn_proto)),
@@ -590,7 +590,7 @@ impl<'gc> FunctionObject<'gc> {
590590

591591
impl<'gc> TObject<'gc> for FunctionObject<'gc> {
592592
fn raw_script_object(&self) -> ScriptObject<'gc> {
593-
self.0.read().base
593+
self.0.base
594594
}
595595

596596
fn call(
@@ -635,7 +635,7 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
635635
);
636636
}
637637
// TODO: de-duplicate code.
638-
if let Some(exec) = &self.0.read().constructor {
638+
if let Some(exec) = &self.0.constructor {
639639
let _ = exec.exec(
640640
ExecutionName::Static("[ctor]"),
641641
activation,
@@ -645,7 +645,7 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
645645
ExecutionReason::FunctionCall,
646646
(*self).into(),
647647
)?;
648-
} else if let Some(exec) = &self.0.read().function {
648+
} else if let Some(exec) = &self.0.function {
649649
let _ = exec.exec(
650650
ExecutionName::Static("[ctor]"),
651651
activation,
@@ -684,7 +684,7 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
684684
);
685685
}
686686
// TODO: de-duplicate code.
687-
if let Some(exec) = &self.0.read().constructor {
687+
if let Some(exec) = &self.0.constructor {
688688
// Native constructors will return the constructed `this`.
689689
// This allows for `new Object` etc. returning different types.
690690
let this = exec.exec(
@@ -697,7 +697,7 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
697697
(*self).into(),
698698
)?;
699699
Ok(this)
700-
} else if let Some(exec) = &self.0.read().function {
700+
} else if let Some(exec) = &self.0.function {
701701
let _ = exec.exec(
702702
ExecutionName::Static("[ctor]"),
703703
activation,
@@ -718,7 +718,7 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
718718
activation: &mut Activation<'_, 'gc>,
719719
prototype: Object<'gc>,
720720
) -> Result<Object<'gc>, Error<'gc>> {
721-
Ok(FunctionObject(GcCell::new(
721+
Ok(FunctionObject(Gc::new(
722722
activation.gc(),
723723
FunctionObjectData {
724724
base: ScriptObject::new(&activation.context.strings, Some(prototype)),
@@ -730,11 +730,11 @@ impl<'gc> TObject<'gc> for FunctionObject<'gc> {
730730
}
731731

732732
fn as_executable(&self) -> Option<Executable<'gc>> {
733-
self.0.read().function.clone()
733+
self.0.function.clone()
734734
}
735735

736736
fn as_ptr(&self) -> *const ObjectPtr {
737-
self.0.read().base.as_ptr()
737+
self.0.base.as_ptr()
738738
}
739739
}
740740

0 commit comments

Comments
 (0)