From 2389422c99435f501072f7018233614510649447 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Sun, 20 Feb 2022 13:03:51 +0100 Subject: [PATCH] avm2: Add ioErrorEvent stub --- core/src/avm2/globals.rs | 5 ++ core/src/avm2/globals/flash/events.rs | 1 + .../avm2/globals/flash/events/ioerrorevent.rs | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 core/src/avm2/globals/flash/events/ioerrorevent.rs diff --git a/core/src/avm2/globals.rs b/core/src/avm2/globals.rs index 56a0915b6..82b8c7b12 100644 --- a/core/src/avm2/globals.rs +++ b/core/src/avm2/globals.rs @@ -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), diff --git a/core/src/avm2/globals/flash/events.rs b/core/src/avm2/globals/flash/events.rs index a3015d4be..288ff28eb 100644 --- a/core/src/avm2/globals/flash/events.rs +++ b/core/src/avm2/globals/flash/events.rs @@ -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; diff --git a/core/src/avm2/globals/flash/events/ioerrorevent.rs b/core/src/avm2/globals/flash/events/ioerrorevent.rs new file mode 100644 index 000000000..70cf48965 --- /dev/null +++ b/core/src/avm2/globals/flash/events/ioerrorevent.rs @@ -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>, + args: &[Value<'gc>], +) -> Result, 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>, + _args: &[Value<'gc>], +) -> Result, 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, "", mc), + Method::from_builtin(class_init, "", 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 +}