avm2: Add `Stage` class stub

This commit is contained in:
David Wendt 2021-04-17 16:03:19 -04:00 committed by Mike Welsh
parent 7f4a99ca60
commit 81de112774
3 changed files with 71 additions and 0 deletions

View File

@ -109,6 +109,7 @@ pub struct SystemPrototypes<'gc> {
pub graphics: Object<'gc>, pub graphics: Object<'gc>,
pub loaderinfo: Object<'gc>, pub loaderinfo: Object<'gc>,
pub bytearray: Object<'gc>, pub bytearray: Object<'gc>,
pub stage: Object<'gc>,
} }
impl<'gc> SystemPrototypes<'gc> { impl<'gc> SystemPrototypes<'gc> {
@ -153,6 +154,7 @@ impl<'gc> SystemPrototypes<'gc> {
graphics: empty, graphics: empty,
loaderinfo: empty, loaderinfo: empty,
bytearray: empty, bytearray: empty,
stage: empty,
} }
} }
} }
@ -750,6 +752,19 @@ pub fn load_player_globals<'gc>(
domain, domain,
script, script,
)?; )?;
activation
.context
.avm2
.system_prototypes
.as_mut()
.unwrap()
.stage = class(
activation,
flash::display::stage::create_class(mc),
implicit_deriver,
domain,
script,
)?;
// package `flash.geom` // package `flash.geom`
activation activation

View File

@ -14,4 +14,5 @@ pub mod movieclip;
pub mod scene; pub mod scene;
pub mod shape; pub mod shape;
pub mod sprite; pub mod sprite;
pub mod stage;
pub mod swfversion; pub mod swfversion;

View File

@ -0,0 +1,55 @@
//! `flash.display.Stage` builtin/prototype
use crate::avm2::activation::Activation;
use crate::avm2::class::{Class, ClassAttributes};
use crate::avm2::method::Method;
use crate::avm2::names::{Namespace, QName};
use crate::avm2::object::Object;
use crate::avm2::value::Value;
use crate::avm2::Error;
use gc_arena::{GcCell, MutationContext};
/// Implements `flash.display.Stage`'s instance constructor.
pub fn instance_init<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(this) = this {
activation.super_init(this, &[])?;
}
Ok(Value::Undefined)
}
/// Implements `flash.display.Stage`'s class constructor.
pub fn class_init<'gc>(
_activation: &mut Activation<'_, 'gc, '_>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
Ok(Value::Undefined)
}
/// Construct `Stage`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
QName::new(Namespace::package("flash.display"), "Stage"),
Some(
QName::new(
Namespace::package("flash.display"),
"DisplayObjectContainer",
)
.into(),
),
Method::from_builtin(instance_init),
Method::from_builtin(class_init),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
class
}