Fixes to make tests compile again
This commit is contained in:
parent
5873eefb06
commit
588b2bb061
|
@ -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, '_>,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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<dyn DisplayObject> = 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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue