Allow system prototypes to be initialized after the fact.

This commit is contained in:
David Wendt 2020-08-04 22:54:50 -04:00
parent b1bcceaa78
commit a8e267ed16
1 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use crate::avm2::object::{Object, TObject};
use crate::avm2::scope::Scope;
use crate::avm2::script::Script;
use crate::avm2::script::TranslationUnit;
use crate::avm2::script_object::ScriptObject;
use crate::avm2::value::Value;
use crate::context::UpdateContext;
use crate::tag_utils::SwfSlice;
@ -56,7 +57,7 @@ pub struct Avm2<'gc> {
globals: Object<'gc>,
/// System prototypes.
system_prototypes: SystemPrototypes<'gc>,
system_prototypes: Option<SystemPrototypes<'gc>>,
#[cfg(feature = "avm_debug")]
pub debug_output: bool,
@ -65,12 +66,12 @@ pub struct Avm2<'gc> {
impl<'gc> Avm2<'gc> {
/// Construct a new AVM interpreter.
pub fn new(mc: MutationContext<'gc, '_>) -> Self {
let (globals, system_prototypes) = globals::construct_global_scope(mc);
let globals = ScriptObject::bare_object(mc);
Self {
stack: Vec::new(),
globals,
system_prototypes,
system_prototypes: None,
#[cfg(feature = "avm_debug")]
debug_output: false,
@ -83,8 +84,10 @@ impl<'gc> Avm2<'gc> {
}
/// Return the current set of system prototypes.
///
/// This function panics if the interpreter has not yet been initialized.
pub fn prototypes(&self) -> &SystemPrototypes<'gc> {
&self.system_prototypes
self.system_prototypes.as_ref().unwrap()
}
/// Run a script's initializer method.