Skip to content

Commit cbe8d2a

Browse files
Lord-McSweeneyLord-McSweeney
authored andcommitted
avm2: Always store a Class on vtable
1 parent 257d884 commit cbe8d2a

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

core/src/avm2/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ impl<'gc> Class<'gc> {
604604
}
605605

606606
read.instance_vtable.init_vtable(
607+
self,
607608
None,
608-
self.protected_namespace(),
609609
&read.instance_traits,
610610
None,
611611
read.super_class.map(|c| c.instance_vtable()),

core/src/avm2/globals/avmplus.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,12 @@ fn describe_internal_body<'gc>(
383383
let declared_by = method.class;
384384

385385
if flags.contains(DescribeTypeFlags::HIDE_OBJECT)
386-
&& declared_by == Some(activation.avm2().classes().object)
386+
&& declared_by == activation.avm2().classes().object.inner_class_definition()
387387
{
388388
continue;
389389
}
390390

391391
let declared_by_name = declared_by
392-
.unwrap()
393-
.inner_class_definition()
394392
.name()
395393
.to_qualified_name(activation.context.gc_context);
396394

@@ -477,8 +475,6 @@ fn describe_internal_body<'gc>(
477475
let accessor_type =
478476
method_type.to_qualified_name_or_star(activation.context.gc_context);
479477
let declared_by = defining_class
480-
.unwrap()
481-
.inner_class_definition()
482478
.name()
483479
.to_qualified_name(activation.context.gc_context);
484480

core/src/avm2/object.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,15 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
597597
let ClassBoundMethod {
598598
method,
599599
scope,
600-
class,
600+
class_obj,
601+
..
601602
} = full_method;
602603

603604
return exec(
604605
method,
605606
scope.expect("Scope should exist here"),
606607
self.into(),
607-
class,
608+
class_obj,
608609
arguments,
609610
activation,
610611
self.into(), // Callee deliberately invalid.

core/src/avm2/object/class_object.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ impl<'gc> ClassObject<'gc> {
239239
class.validate_class(self.superclass_object())?;
240240

241241
self.instance_vtable().init_vtable(
242+
class,
242243
Some(self),
243-
class.protected_namespace(),
244244
&class.instance_traits(),
245245
Some(self.instance_scope()),
246246
self.superclass_object().map(|cls| cls.instance_vtable()),
@@ -275,8 +275,8 @@ impl<'gc> ClassObject<'gc> {
275275

276276
// class vtable == class traits + Class instance traits
277277
self.class_vtable().init_vtable(
278+
class,
278279
Some(self),
279-
class.protected_namespace(),
280280
&class.class_traits(),
281281
Some(self.class_scope()),
282282
Some(self.instance_of().unwrap().instance_vtable()),
@@ -516,16 +516,17 @@ impl<'gc> ClassObject<'gc> {
516516
if let Some(Property::Method { disp_id, .. }) = property {
517517
// todo: handle errors
518518
let ClassBoundMethod {
519-
class,
519+
class_obj,
520520
scope,
521521
method,
522+
..
522523
} = self.instance_vtable().get_full_method(disp_id).unwrap();
523524
let callee = FunctionObject::from_method(
524525
activation,
525526
method,
526527
scope.expect("Scope should exist here"),
527528
Some(receiver),
528-
class,
529+
class_obj,
529530
);
530531

531532
callee.call(receiver.into(), arguments, activation)
@@ -575,16 +576,17 @@ impl<'gc> ClassObject<'gc> {
575576
) => {
576577
// todo: handle errors
577578
let ClassBoundMethod {
578-
class,
579+
class_obj,
579580
scope,
580581
method,
582+
..
581583
} = self.instance_vtable().get_full_method(disp_id).unwrap();
582584
let callee = FunctionObject::from_method(
583585
activation,
584586
method,
585587
scope.expect("Scope should exist here"),
586588
Some(receiver),
587-
class,
589+
class_obj,
588590
);
589591

590592
// We call getters, but return the actual function object for normal methods
@@ -657,12 +659,13 @@ impl<'gc> ClassObject<'gc> {
657659
}) => {
658660
// todo: handle errors
659661
let ClassBoundMethod {
660-
class,
662+
class_obj,
661663
scope,
662664
method,
665+
..
663666
} = self.instance_vtable().get_full_method(disp_id).unwrap();
664667
let callee =
665-
FunctionObject::from_method(activation, method, scope.expect("Scope should exist here"), Some(receiver), class);
668+
FunctionObject::from_method(activation, method, scope.expect("Scope should exist here"), Some(receiver), class_obj);
666669

667670
callee.call(receiver.into(), &[value], activation)?;
668671
Ok(())

core/src/avm2/script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ impl<'gc> Script<'gc> {
619619
let scope = ScopeChain::new(domain);
620620

621621
globals.vtable().unwrap().init_vtable(
622+
globals.instance_class().unwrap(),
622623
globals.instance_of(),
623-
globals.instance_class().unwrap().protected_namespace(),
624624
&self.traits()?,
625625
Some(scope),
626626
None,

core/src/avm2/vtable.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use crate::avm2::property_map::PropertyMap;
77
use crate::avm2::scope::ScopeChain;
88
use crate::avm2::traits::{Trait, TraitKind};
99
use crate::avm2::value::Value;
10-
use crate::avm2::Error;
11-
use crate::avm2::Multiname;
12-
use crate::avm2::Namespace;
13-
use crate::avm2::QName;
10+
use crate::avm2::{Class, Error, Multiname, Namespace, QName};
1411
use crate::context::UpdateContext;
1512
use crate::string::AvmString;
1613
use gc_arena::{Collect, GcCell, Mutation};
@@ -52,7 +49,8 @@ pub struct VTableData<'gc> {
5249
#[derive(Collect, Clone)]
5350
#[collect(no_drop)]
5451
pub struct ClassBoundMethod<'gc> {
55-
pub class: Option<ClassObject<'gc>>,
52+
pub class: Class<'gc>,
53+
pub class_obj: Option<ClassObject<'gc>>,
5654
pub scope: Option<ScopeChain<'gc>>,
5755
pub method: Method<'gc>,
5856
}
@@ -211,8 +209,8 @@ impl<'gc> VTable<'gc> {
211209
#[allow(clippy::if_same_then_else)]
212210
pub fn init_vtable(
213211
self,
212+
defining_class_def: Class<'gc>,
214213
defining_class: Option<ClassObject<'gc>>,
215-
protected_namespace: Option<Namespace<'gc>>,
216214
traits: &[Trait<'gc>],
217215
scope: Option<ScopeChain<'gc>>,
218216
superclass_vtable: Option<Self>,
@@ -274,7 +272,7 @@ impl<'gc> VTable<'gc> {
274272

275273
write.scope = scope;
276274

277-
write.protected_namespace = protected_namespace;
275+
write.protected_namespace = defining_class_def.protected_namespace();
278276

279277
if let Some(superclass_vtable) = superclass_vtable {
280278
write.resolved_traits = superclass_vtable.0.read().resolved_traits.clone();
@@ -321,7 +319,8 @@ impl<'gc> VTable<'gc> {
321319
match trait_data.kind() {
322320
TraitKind::Method { method, .. } => {
323321
let entry = ClassBoundMethod {
324-
class: defining_class,
322+
class: defining_class_def,
323+
class_obj: defining_class,
325324
scope,
326325
method: *method,
327326
};
@@ -349,7 +348,8 @@ impl<'gc> VTable<'gc> {
349348
}
350349
TraitKind::Getter { method, .. } => {
351350
let entry = ClassBoundMethod {
352-
class: defining_class,
351+
class: defining_class_def,
352+
class_obj: defining_class,
353353
scope,
354354
method: *method,
355355
};
@@ -386,7 +386,8 @@ impl<'gc> VTable<'gc> {
386386
}
387387
TraitKind::Setter { method, .. } => {
388388
let entry = ClassBoundMethod {
389-
class: defining_class,
389+
class: defining_class_def,
390+
class_obj: defining_class,
390391
scope,
391392
method: *method,
392393
};
@@ -512,17 +513,18 @@ impl<'gc> VTable<'gc> {
512513
method: ClassBoundMethod<'gc>,
513514
) -> FunctionObject<'gc> {
514515
let ClassBoundMethod {
515-
class,
516+
class_obj,
516517
scope,
517518
method,
519+
..
518520
} = method;
519521

520522
FunctionObject::from_method(
521523
activation,
522524
method,
523525
scope.expect("Scope should exist here"),
524526
Some(receiver),
525-
class,
527+
class_obj,
526528
)
527529
}
528530

0 commit comments

Comments
 (0)