avm2: Add ioErrorEvent stub

This commit is contained in:
Adrian Wielgosik 2022-02-20 13:03:51 +01:00 committed by Adrian Wielgosik
parent 388dc6fe31
commit 2389422c99
3 changed files with 57 additions and 0 deletions

View File

@ -573,6 +573,11 @@ pub fn load_player_globals<'gc>(
flash::events::mouseevent::create_class(mc),
script
);
class(
activation,
flash::events::ioerrorevent::create_class(mc),
script,
)?;
class(
activation,
flash::events::keyboardevent::create_class(mc),

View File

@ -6,6 +6,7 @@ pub mod eventdispatcher;
pub mod eventphase;
pub mod fullscreenevent;
pub mod ieventdispatcher;
pub mod ioerrorevent;
pub mod keyboardevent;
pub mod mouseevent;
pub mod progressevent;

View File

@ -0,0 +1,51 @@
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.IOErrorEvent`'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)?; // ErrorEvent, Event use these
}
Ok(Value::Undefined)
}
/// Implements `flash.events.IOErrorEvent`'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 `IOErrorEvent`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
QName::new(Namespace::package("flash.events"), "IOErrorEvent"),
// TODO: this should derive IOErrorEvent -> ErrorEvent -> TextEvent -> Event
Some(QName::new(Namespace::package("flash.events"), "Event").into()),
Method::from_builtin(instance_init, "<IOErrorEvent instance initializer>", mc),
Method::from_builtin(class_init, "<IOErrorEvent class initializer>", mc),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
const CONSTANTS: &[(&str, &str)] = &[("IO_ERROR", "ioError")];
write.define_public_constant_string_class_traits(CONSTANTS);
class
}