Skip to content

Commit

Permalink
avm2: Use interned "*" character in PropertyClass::get_name and `Mu…
Browse files Browse the repository at this point in the history
…ltiname::to_qualified_name_or_star`
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Sep 11, 2024
1 parent 7ba5fa1 commit e65b52c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 9 additions & 4 deletions core/src/avm2/globals/avmplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ fn describe_internal_body<'gc>(
if !flags.contains(DescribeTypeFlags::INCLUDE_VARIABLES) {
continue;
}
let prop_class_name = vtable.slot_class_name(mc, *slot_id)?;
let prop_class_name =
vtable.slot_class_name(&mut activation.borrow_gc(), *slot_id)?;

let access = match prop {
Property::ConstSlot { .. } => "readonly",
Expand Down Expand Up @@ -356,7 +357,10 @@ fn describe_internal_body<'gc>(
continue;
}

let return_type_name = method.method.return_type().to_qualified_name_or_star(mc);
let return_type_name = method
.method
.return_type()
.to_qualified_name_or_star(&mut activation.borrow_gc());
let declared_by = method.class;

if flags.contains(DescribeTypeFlags::HIDE_OBJECT)
Expand Down Expand Up @@ -456,7 +460,8 @@ fn describe_internal_body<'gc>(
Some(ns.as_uri())
};

let accessor_type = method_type.to_qualified_name_or_star(mc);
let accessor_type =
method_type.to_qualified_name_or_star(&mut activation.borrow_gc());
let declared_by = defining_class.dollar_removed_name(mc).to_qualified_name(mc);

let accessor_obj = activation
Expand Down Expand Up @@ -544,7 +549,7 @@ fn write_params<'gc>(
for param in method.signature() {
let param_type_name = param
.param_type_name
.to_qualified_name_or_star(activation.context.gc_context);
.to_qualified_name_or_star(&mut activation.borrow_gc());
let optional = param.default_value.is_some();
let param_obj = activation
.avm2()
Expand Down
6 changes: 4 additions & 2 deletions core/src/avm2/multiname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,11 @@ impl<'gc> Multiname<'gc> {

/// Like `to_qualified_name`, but returns `*` if `self.is_any()` is true.
/// This is used by `describeType`
pub fn to_qualified_name_or_star(&self, mc: &Mutation<'gc>) -> AvmString<'gc> {
pub fn to_qualified_name_or_star(&self, context: &mut GcContext<'_, 'gc>) -> AvmString<'gc> {
let mc = context.gc_context;

if self.is_any_name() {
AvmString::new_utf8(mc, "*")
context.interner.get_char(mc, '*' as u16)
} else {
self.to_qualified_name(mc)
}
Expand Down
9 changes: 6 additions & 3 deletions core/src/avm2/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::avm2::Error;
use crate::avm2::Multiname;
use crate::avm2::TranslationUnit;
use crate::avm2::Value;
use crate::context::GcContext;
use crate::string::AvmString;
use gc_arena::{Collect, Gc, Mutation};

Expand Down Expand Up @@ -128,11 +129,13 @@ impl<'gc> PropertyClass<'gc> {
}
}

pub fn get_name(&self, mc: &Mutation<'gc>) -> AvmString<'gc> {
pub fn get_name(&self, context: &mut GcContext<'_, 'gc>) -> AvmString<'gc> {
let mc = context.gc_context;

match self {
PropertyClass::Class(class) => class.name().to_qualified_name(mc),
PropertyClass::Name(gc) => gc.0.to_qualified_name_or_star(mc),
PropertyClass::Any => AvmString::new_utf8(mc, "*"),
PropertyClass::Name(gc) => gc.0.to_qualified_name_or_star(context),
PropertyClass::Any => context.interner.get_char(mc, '*' as u16),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/avm2/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::avm2::scope::ScopeChain;
use crate::avm2::traits::{Trait, TraitKind};
use crate::avm2::value::Value;
use crate::avm2::{Class, Error, Multiname, Namespace, QName};
use crate::context::GcContext;
use crate::string::AvmString;
use gc_arena::{Collect, GcCell, Mutation};
use std::cell::Ref;
Expand Down Expand Up @@ -114,15 +115,15 @@ impl<'gc> VTable<'gc> {

pub fn slot_class_name(
&self,
mc: &Mutation<'gc>,
context: &mut GcContext<'_, 'gc>,
slot_id: u32,
) -> Result<AvmString<'gc>, Error<'gc>> {
self.0
.read()
.slot_classes
.get(slot_id as usize)
.ok_or_else(|| "Invalid slot ID".into())
.map(|c| c.get_name(mc))
.map(|c| c.get_name(context))
}

pub fn get_trait(self, name: &Multiname<'gc>) -> Option<Property> {
Expand Down

0 comments on commit e65b52c

Please sign in to comment.