avm2: Add more Event class stubs and constants

This commit is contained in:
Adrian Wielgosik 2021-09-04 23:18:22 +02:00 committed by Adrian Wielgosik
parent bc4f790031
commit 9bd0b624fd
5 changed files with 141 additions and 1 deletions

View File

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

View File

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

View File

@ -0,0 +1,50 @@
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.KeyboardEvent`'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.KeyboardEvent`'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 `KeyboardEvent`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
QName::new(Namespace::package("flash.events"), "KeyboardEvent"),
Some(QName::new(Namespace::package("flash.events"), "Event").into()),
Method::from_builtin(instance_init, "<KeyboardEvent instance initializer>", mc),
Method::from_builtin(class_init, "<KeyboardEvent class initializer>", mc),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
const CONSTANTS: &[(&str, &str)] = &[("KEY_DOWN", "keyDown"), ("KEY_UP", "keyUp")];
write.define_public_constant_string_class_traits(CONSTANTS);
class
}

View File

@ -42,7 +42,27 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
write.set_attributes(ClassAttributes::SEALED);
const CONSTANTS: &[(&str, &str)] = &[("CLICK", "click")];
const CONSTANTS: &[(&str, &str)] = &[
("CLICK", "click"),
("CONTEXT_MENU", "contextMenu"),
("DOUBLE_CLICK", "doubleClick"),
("MIDDLE_CLICK", "middleClick"),
("MIDDLE_MOUSE_DOWN", "middleMouseDown"),
("MIDDLE_MOUSE_UP", "middleMouseUp"),
("MOUSE_DOWN", "mouseDown"),
("MOUSE_MOVE", "mouseMove"),
("MOUSE_OUT", "mouseOut"),
("MOUSE_OVER", "mouseOver"),
("MOUSE_UP", "mouseUp"),
("MOUSE_WHEEL", "mouseWheel"),
("RELEASE_OUTSIDE", "releaseOutside"),
("RIGHT_CLICK", "rightClick"),
("RIGHT_MOUSE_DOWN", "rightMouseDown"),
("RIGHT_MOUSE_UP", "rightMouseUp"),
("ROLL_OUT", "rollOut"),
("ROLL_OVER", "rollOver"),
];
write.define_public_constant_string_class_traits(CONSTANTS);
class

View File

@ -0,0 +1,56 @@
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.ProgressEvent`'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.ProgressEvent`'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 `ProgressEvent`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
QName::new(Namespace::package("flash.events"), "ProgressEvent"),
Some(QName::new(Namespace::package("flash.events"), "Event").into()),
Method::from_builtin(instance_init, "<ProgressEvent instance initializer>", mc),
Method::from_builtin(class_init, "<ProgressEvent class initializer>", mc),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
const CONSTANTS: &[(&str, &str)] = &[
("PROGRESS", "progress"),
("SOCKET_DATA", "socketData"),
("STANDARD_ERROR_DATA", "standardErrorData"),
("STANDARD_INPUT_PROGRESS", "standardInputProgress"),
("STANDARD_OUTPUT_DATA", "standardOutputData"),
];
write.define_public_constant_string_class_traits(CONSTANTS);
class
}