2020-02-12 19:58:33 +00:00
|
|
|
//! Global scope built-ins
|
|
|
|
|
2020-02-19 03:26:08 +00:00
|
|
|
use crate::avm2::function::FunctionObject;
|
|
|
|
use crate::avm2::names::{Namespace, QName};
|
2020-02-12 19:58:33 +00:00
|
|
|
use crate::avm2::object::{Object, TObject};
|
|
|
|
use crate::avm2::script_object::ScriptObject;
|
2020-02-19 03:26:08 +00:00
|
|
|
use gc_arena::{Collect, MutationContext};
|
2020-02-12 19:58:33 +00:00
|
|
|
|
2020-02-23 00:12:33 +00:00
|
|
|
mod flash;
|
2020-02-19 03:26:08 +00:00
|
|
|
mod function;
|
|
|
|
mod object;
|
|
|
|
|
|
|
|
/// This structure represents all system builtins' prototypes.
|
|
|
|
#[derive(Clone, Collect)]
|
|
|
|
#[collect(no_drop)]
|
|
|
|
pub struct SystemPrototypes<'gc> {
|
|
|
|
pub object: Object<'gc>,
|
|
|
|
pub function: Object<'gc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct a new global scope.
|
|
|
|
///
|
|
|
|
/// This function returns both the global scope object, as well as all builtin
|
|
|
|
/// prototypes that other parts of the VM will need to use.
|
|
|
|
pub fn construct_global_scope<'gc>(
|
|
|
|
mc: MutationContext<'gc, '_>,
|
|
|
|
) -> (Object<'gc>, SystemPrototypes<'gc>) {
|
|
|
|
let mut global_scope = ScriptObject::bare_object(mc);
|
|
|
|
|
|
|
|
let object_proto = ScriptObject::bare_object(mc);
|
|
|
|
let function_proto = function::create_proto(mc, object_proto);
|
2020-02-23 00:12:33 +00:00
|
|
|
let sprite_proto = flash::display::sprite::create_proto(mc, object_proto, function_proto);
|
|
|
|
let movieclip_proto = flash::display::movieclip::create_proto(mc, sprite_proto, function_proto);
|
2020-02-19 03:26:08 +00:00
|
|
|
|
|
|
|
object::fill_proto(mc, object_proto, function_proto);
|
|
|
|
|
|
|
|
let system_prototypes = SystemPrototypes {
|
|
|
|
object: object_proto,
|
|
|
|
function: function_proto,
|
|
|
|
};
|
2020-02-12 19:58:33 +00:00
|
|
|
|
|
|
|
global_scope
|
2020-02-19 03:26:08 +00:00
|
|
|
.install_dynamic_property(
|
|
|
|
mc,
|
|
|
|
QName::new(Namespace::public_namespace(), "Object"),
|
|
|
|
FunctionObject::from_builtin_constr(
|
|
|
|
mc,
|
|
|
|
object::constructor,
|
|
|
|
object_proto,
|
|
|
|
function_proto,
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
global_scope
|
|
|
|
.install_dynamic_property(
|
|
|
|
mc,
|
|
|
|
QName::new(Namespace::public_namespace(), "Function"),
|
|
|
|
FunctionObject::from_builtin_constr(
|
|
|
|
mc,
|
|
|
|
function::constructor,
|
|
|
|
function_proto,
|
|
|
|
function_proto,
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-02-22 17:47:03 +00:00
|
|
|
global_scope
|
|
|
|
.install_dynamic_property(
|
|
|
|
mc,
|
|
|
|
QName::new(Namespace::package("flash.display"), "Sprite"),
|
|
|
|
FunctionObject::from_builtin_constr(
|
|
|
|
mc,
|
2020-02-23 00:12:33 +00:00
|
|
|
flash::display::sprite::constructor,
|
2020-02-22 17:47:03 +00:00
|
|
|
sprite_proto,
|
|
|
|
function_proto,
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-02-21 01:29:51 +00:00
|
|
|
global_scope
|
|
|
|
.install_dynamic_property(
|
|
|
|
mc,
|
|
|
|
QName::new(Namespace::package("flash.display"), "MovieClip"),
|
|
|
|
FunctionObject::from_builtin_constr(
|
|
|
|
mc,
|
2020-02-23 00:12:33 +00:00
|
|
|
flash::display::movieclip::constructor,
|
2020-02-21 01:29:51 +00:00
|
|
|
movieclip_proto,
|
|
|
|
function_proto,
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-02-19 03:26:08 +00:00
|
|
|
|
|
|
|
(global_scope, system_prototypes)
|
2020-02-12 19:58:33 +00:00
|
|
|
}
|