avm2: Initial MouseEvent stubs (#5065)

* avm2: Start MouseEvent stubs

* avm2: More MouseEvent work

* chore: clippy

* chore: fmt

Co-authored-by: Adrian Wielgosik <adrian.wielgosik@gmail.com>
This commit is contained in:
Ray Redondo 2021-08-20 18:26:34 -05:00 committed by GitHub
parent 8cb5cf0252
commit 27e06af003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -544,6 +544,12 @@ pub fn load_player_globals<'gc>(
domain,
script,
)?;
class(
activation,
flash::events::mouseevent::create_class(mc),
domain,
script,
)?;
// package `flash.utils`
avm2_system_class!(
bytearray,

View File

@ -3,3 +3,4 @@
pub mod event;
pub mod eventdispatcher;
pub mod ieventdispatcher;
pub mod mouseevent;

View File

@ -0,0 +1,49 @@
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.events.MouseEvent`'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, args)?; // Event uses the first three parameters
}
Ok(Value::Undefined)
}
/// Implements `flash.events.MouseEvent`'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 `MouseEvent`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
QName::new(Namespace::package("flash.events"), "MouseEvent"),
Some(QName::new(Namespace::package("flash.events"), "Event").into()),
Method::from_builtin(instance_init, "<MouseEvent instance initializer>", mc),
Method::from_builtin(class_init, "<MouseEvent class initializer>", mc),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
const CONSTANTS: &[(&str, &str)] = &[("CLICK", "click")];
write.define_public_constant_string_class_traits(CONSTANTS);
class
}