From 588b2bb061130232a851706ce08c8633e781602d Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 3 Oct 2019 22:42:32 -0400 Subject: [PATCH] Fixes to make tests compile again --- core/src/avm1.rs | 5 +++++ core/src/avm1/activation.rs | 26 ++++++++++++++++++++++++++ core/src/avm1/globals/math.rs | 4 ++++ core/src/avm1/object.rs | 6 +++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/core/src/avm1.rs b/core/src/avm1.rs index f2a1fe0ac..e89b1a4d5 100644 --- a/core/src/avm1.rs +++ b/core/src/avm1.rs @@ -883,6 +883,11 @@ impl<'gc> Avm1<'gc> { Value::Object(self.globals) } + /// Obtain a reference to `_global`. + pub fn global_object_cell(&self) -> GcCell<'gc, Object<'gc>> { + self.globals + } + fn action_get_variable( &mut self, context: &mut ActionContext<'_, 'gc, '_>, diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index d53b1554f..8fca7d823 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -88,6 +88,32 @@ impl<'gc> Activation<'gc> { } } + /// Construct an empty stack frame with no code. + /// + /// This is primarily intended for testing purposes: the activation given + /// will prevent the AVM from panicking without a current activation. + /// We construct a single scope chain from a global object, and that's about + /// it. + pub fn from_nothing(swf_version: u8, globals: GcCell<'gc, Object<'gc>>, mc: MutationContext<'gc, '_>) -> Activation<'gc> { + let global_scope = GcCell::allocate(mc, Scope::from_global_object(globals)); + let child_scope = GcCell::allocate(mc, Scope::new_local_scope(global_scope, mc)); + + Activation { + swf_version: swf_version, + data: SwfSlice { + data: Arc::new(Vec::new()), + start: 0, + end: 0 + }, + pc: 0, + scope: child_scope, + this: globals, + arguments: None, + is_function: false, + local_registers: None + } + } + /// Create a new activation to run a block of code with a given scope. pub fn to_rescope(&self, code: SwfSlice, scope: GcCell<'gc, Scope<'gc>>) -> Self { Activation { diff --git a/core/src/avm1/globals/math.rs b/core/src/avm1/globals/math.rs index fae401fe8..e94fbd770 100644 --- a/core/src/avm1/globals/math.rs +++ b/core/src/avm1/globals/math.rs @@ -83,6 +83,7 @@ pub fn create<'gc>(gc_context: MutationContext<'gc, '_>) -> GcCell<'gc, Object<' mod tests { use super::*; use crate::avm1::Error; + use crate::avm1::activation::Activation; use crate::backend::audio::NullAudioBackend; use crate::backend::navigator::NullNavigatorBackend; use crate::display_object::DisplayObject; @@ -129,6 +130,9 @@ mod tests { navigator: &mut NullNavigatorBackend::new(), }; + let globals = avm.global_object_cell(); + avm.insert_stack_frame(Activation::from_nothing(swf_version, globals, gc_context)); + test(&mut avm, &mut context) }) } diff --git a/core/src/avm1/object.rs b/core/src/avm1/object.rs index 107a99285..db1a90beb 100644 --- a/core/src/avm1/object.rs +++ b/core/src/avm1/object.rs @@ -329,6 +329,7 @@ mod tests { use crate::backend::navigator::NullNavigatorBackend; use crate::display_object::DisplayObject; use crate::movie_clip::MovieClip; + use crate::avm1::activation::Activation; use gc_arena::rootless_arena; use rand::{rngs::SmallRng, SeedableRng}; @@ -341,7 +342,7 @@ mod tests { ) -> R, { rootless_arena(|gc_context| { - let mut avm = Avm1::new(gc_context, swf_version); + let mut avm = Avm1::new(gc_context); let movie_clip: Box = Box::new(MovieClip::new(gc_context)); let root = GcCell::allocate(gc_context, movie_clip); let mut context = ActionContext { @@ -358,6 +359,9 @@ mod tests { }; let object = GcCell::allocate(gc_context, Object::object(gc_context)); + let globals = avm.global_object_cell(); + avm.insert_stack_frame(Activation::from_nothing(swf_version, globals, gc_context)); + test(&mut avm, &mut context, object) }) }