avm1: address Scope nitpicks
This commit is contained in:
parent
05e3e6434b
commit
9529a1cbdb
|
@ -2220,8 +2220,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
|
||||||
value => {
|
value => {
|
||||||
// Note that primitives get boxed at this point.
|
// Note that primitives get boxed at this point.
|
||||||
let object = value.coerce_to_object(self);
|
let object = value.coerce_to_object(self);
|
||||||
let with_scope =
|
let with_scope = Gc::allocate(
|
||||||
Scope::new_with_scope(self.scope(), object, self.context.gc_context);
|
self.context.gc_context,
|
||||||
|
Scope::new_with_scope(self.scope(), object),
|
||||||
|
);
|
||||||
let mut new_activation = self.with_new_scope("[With]", with_scope);
|
let mut new_activation = self.with_new_scope("[With]", with_scope);
|
||||||
if let ReturnType::Explicit(value) = new_activation.run_actions(code)? {
|
if let ReturnType::Explicit(value) = new_activation.run_actions(code)? {
|
||||||
Ok(FrameControl::Return(ReturnType::Explicit(value)))
|
Ok(FrameControl::Return(ReturnType::Explicit(value)))
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub enum ScopeClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a scope chain for an AVM1 activation.
|
/// Represents a scope chain for an AVM1 activation.
|
||||||
#[derive(Copy, Clone, Debug, Collect)]
|
#[derive(Clone, Debug, Collect)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
pub struct Scope<'gc> {
|
pub struct Scope<'gc> {
|
||||||
parent: Option<Gc<'gc, Scope<'gc>>>,
|
parent: Option<Gc<'gc, Scope<'gc>>>,
|
||||||
|
@ -39,7 +39,7 @@ pub struct Scope<'gc> {
|
||||||
|
|
||||||
impl<'gc> Scope<'gc> {
|
impl<'gc> Scope<'gc> {
|
||||||
/// Construct a global scope (one without a parent).
|
/// Construct a global scope (one without a parent).
|
||||||
pub fn from_global_object(globals: Object<'gc>) -> Scope<'gc> {
|
pub fn from_global_object(globals: Object<'gc>) -> Self {
|
||||||
Scope {
|
Scope {
|
||||||
parent: None,
|
parent: None,
|
||||||
class: ScopeClass::Global,
|
class: ScopeClass::Global,
|
||||||
|
@ -48,7 +48,7 @@ impl<'gc> Scope<'gc> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a child scope of another scope.
|
/// Construct a child scope of another scope.
|
||||||
pub fn new_local_scope(parent: Gc<'gc, Self>, mc: MutationContext<'gc, '_>) -> Scope<'gc> {
|
pub fn new_local_scope(parent: Gc<'gc, Self>, mc: MutationContext<'gc, '_>) -> Self {
|
||||||
Scope {
|
Scope {
|
||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
class: ScopeClass::Local,
|
class: ScopeClass::Local,
|
||||||
|
@ -63,7 +63,7 @@ impl<'gc> Scope<'gc> {
|
||||||
clip: Object<'gc>,
|
clip: Object<'gc>,
|
||||||
mc: MutationContext<'gc, '_>,
|
mc: MutationContext<'gc, '_>,
|
||||||
) -> Gc<'gc, Self> {
|
) -> Gc<'gc, Self> {
|
||||||
let mut scope = *parent;
|
let mut scope = (*parent).clone();
|
||||||
|
|
||||||
if scope.class == ScopeClass::Target {
|
if scope.class == ScopeClass::Target {
|
||||||
scope.values = clip;
|
scope.values = clip;
|
||||||
|
@ -78,23 +78,16 @@ impl<'gc> Scope<'gc> {
|
||||||
///
|
///
|
||||||
/// A with block adds an object to the top of the scope chain, so unqualified
|
/// A with block adds an object to the top of the scope chain, so unqualified
|
||||||
/// references will try to resolve on that object first.
|
/// references will try to resolve on that object first.
|
||||||
pub fn new_with_scope(
|
pub fn new_with_scope(parent_scope: Gc<'gc, Self>, with_object: Object<'gc>) -> Self {
|
||||||
parent_scope: Gc<'gc, Self>,
|
Scope {
|
||||||
with_object: Object<'gc>,
|
parent: Some(parent_scope),
|
||||||
mc: MutationContext<'gc, '_>,
|
class: ScopeClass::With,
|
||||||
) -> Gc<'gc, Self> {
|
values: with_object,
|
||||||
Gc::allocate(
|
}
|
||||||
mc,
|
|
||||||
Scope {
|
|
||||||
parent: Some(parent_scope),
|
|
||||||
class: ScopeClass::With,
|
|
||||||
values: with_object,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct an arbitrary scope.
|
/// Construct an arbitrary scope.
|
||||||
pub fn new(parent: Gc<'gc, Self>, class: ScopeClass, with_object: Object<'gc>) -> Scope<'gc> {
|
pub fn new(parent: Gc<'gc, Self>, class: ScopeClass, with_object: Object<'gc>) -> Self {
|
||||||
Scope {
|
Scope {
|
||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
class,
|
class,
|
||||||
|
|
Loading…
Reference in New Issue