From 9529a1cbdb3f589535b27d353ff9dff3e1601a2b Mon Sep 17 00:00:00 2001 From: Moulins Date: Sat, 5 Nov 2022 15:23:51 +0100 Subject: [PATCH] avm1: address Scope nitpicks --- core/src/avm1/activation.rs | 6 ++++-- core/src/avm1/scope.rs | 29 +++++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index 33a3ae572..fdb8ae434 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -2220,8 +2220,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { value => { // Note that primitives get boxed at this point. let object = value.coerce_to_object(self); - let with_scope = - Scope::new_with_scope(self.scope(), object, self.context.gc_context); + let with_scope = Gc::allocate( + self.context.gc_context, + Scope::new_with_scope(self.scope(), object), + ); let mut new_activation = self.with_new_scope("[With]", with_scope); if let ReturnType::Explicit(value) = new_activation.run_actions(code)? { Ok(FrameControl::Return(ReturnType::Explicit(value))) diff --git a/core/src/avm1/scope.rs b/core/src/avm1/scope.rs index cef5b1629..6df424d28 100644 --- a/core/src/avm1/scope.rs +++ b/core/src/avm1/scope.rs @@ -29,7 +29,7 @@ pub enum ScopeClass { } /// Represents a scope chain for an AVM1 activation. -#[derive(Copy, Clone, Debug, Collect)] +#[derive(Clone, Debug, Collect)] #[collect(no_drop)] pub struct Scope<'gc> { parent: Option>>, @@ -39,7 +39,7 @@ pub struct Scope<'gc> { impl<'gc> Scope<'gc> { /// 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 { parent: None, class: ScopeClass::Global, @@ -48,7 +48,7 @@ impl<'gc> Scope<'gc> { } /// 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 { parent: Some(parent), class: ScopeClass::Local, @@ -63,7 +63,7 @@ impl<'gc> Scope<'gc> { clip: Object<'gc>, mc: MutationContext<'gc, '_>, ) -> Gc<'gc, Self> { - let mut scope = *parent; + let mut scope = (*parent).clone(); if scope.class == ScopeClass::Target { 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 /// references will try to resolve on that object first. - pub fn new_with_scope( - parent_scope: Gc<'gc, Self>, - with_object: Object<'gc>, - mc: MutationContext<'gc, '_>, - ) -> Gc<'gc, Self> { - Gc::allocate( - mc, - Scope { - parent: Some(parent_scope), - class: ScopeClass::With, - values: with_object, - }, - ) + pub fn new_with_scope(parent_scope: Gc<'gc, Self>, with_object: Object<'gc>) -> Self { + Scope { + parent: Some(parent_scope), + class: ScopeClass::With, + values: with_object, + } } /// 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 { parent: Some(parent), class,