avm2: Convert LoaderInfo to AS

This commit is contained in:
Aaron Hill 2023-02-23 13:18:29 -06:00
parent be16286407
commit 8831042e8f
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
8 changed files with 59 additions and 113 deletions

View File

@ -509,12 +509,6 @@ pub fn load_player_globals<'gc>(
flash::display::graphics::create_class(activation), flash::display::graphics::create_class(activation),
script script
); );
avm2_system_class!(
loaderinfo,
activation,
flash::display::loaderinfo::create_class(activation),
script
);
// package `flash.geom` // package `flash.geom`
@ -638,6 +632,7 @@ fn load_playerglobal<'gc>(
("flash.display", "BitmapData", bitmapdata), ("flash.display", "BitmapData", bitmapdata),
("flash.display", "Scene", scene), ("flash.display", "Scene", scene),
("flash.display", "FrameLabel", framelabel), ("flash.display", "FrameLabel", framelabel),
("flash.display", "LoaderInfo", loaderinfo),
("flash.display", "Stage", stage), ("flash.display", "Stage", stage),
("flash.display", "Stage3D", stage3d), ("flash.display", "Stage3D", stage3d),
("flash.display3D", "Context3D", context3d), ("flash.display3D", "Context3D", context3d),

View File

@ -7,7 +7,7 @@ pub mod display_object_container;
pub mod graphics; pub mod graphics;
pub mod interactive_object; pub mod interactive_object;
pub mod loader; pub mod loader;
pub mod loaderinfo; pub mod loader_info;
pub mod movieclip; pub mod movieclip;
pub mod shape; pub mod shape;
pub mod simplebutton; pub mod simplebutton;

View File

@ -1,3 +1,34 @@
package flash.display { package flash.display {
public class LoaderInfo {} import flash.events.EventDispatcher;
import flash.system.ApplicationDomain;
import flash.utils.ByteArray;
import flash.events.UncaughtErrorEvents;
[Ruffle(InstanceAllocator)]
[Ruffle(NativeInstanceInit)]
public class LoaderInfo extends EventDispatcher {
public function LoaderInfo() {
throw new Error("LoaderInfo cannot be constructed");
}
public native function get actionScriptVersion():uint;
public native function get applicationDomain():ApplicationDomain;
public native function get bytesLoaded():uint;
public native function get bytesTotal():uint;
public native function get content():DisplayObject;
public native function get contentType():String;
public native function get frameRate():Number;
public native function get height():int;
public native function get isURLInaccessible():Boolean;
public native function get parentAllowsChild():Boolean;
public native function get swfVersion():uint;
public native function get url():String;
public native function get width():int;
public native function get bytes():ByteArray;
public native function get loader():Loader;
public native function get loaderURL():String;
public native function get parameters():Object;
public native function get sharedEvents():EventDispatcher;
public native function get uncaughtErrorEvents():UncaughtErrorEvents;
}
} }

View File

@ -2,32 +2,19 @@
use crate::avm2::activation::Activation; use crate::avm2::activation::Activation;
use crate::avm2::bytearray::Endian; use crate::avm2::bytearray::Endian;
use crate::avm2::class::{Class, ClassAttributes}; use crate::avm2::object::{DomainObject, LoaderStream, Object, TObject};
use crate::avm2::method::{Method, NativeMethodImpl};
use crate::avm2::object::{loaderinfo_allocator, DomainObject, LoaderStream, Object, TObject};
use crate::avm2::value::Value; use crate::avm2::value::Value;
use crate::avm2::Multiname;
use crate::avm2::Namespace;
use crate::avm2::QName;
use crate::avm2::{AvmString, Error}; use crate::avm2::{AvmString, Error};
use crate::avm2_stub_getter; use crate::avm2_stub_getter;
use crate::display_object::TDisplayObject; use crate::display_object::TDisplayObject;
use gc_arena::GcCell;
use swf::{write_swf, Compression}; use swf::{write_swf, Compression};
pub use crate::avm2::object::loader_info_allocator;
// FIXME - Throw an actual 'Error' with the proper code // FIXME - Throw an actual 'Error' with the proper code
const INSUFFICIENT: &str = const INSUFFICIENT: &str =
"Error #2099: The loading object is not sufficiently loaded to provide this information."; "Error #2099: The loading object is not sufficiently loaded to provide this information.";
/// Implements `flash.display.LoaderInfo`'s instance constructor.
pub fn instance_init<'gc>(
_activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
Err("LoaderInfo cannot be constructed".into())
}
/// Implements `flash.display.LoaderInfo`'s native instance constructor. /// Implements `flash.display.LoaderInfo`'s native instance constructor.
pub fn native_instance_init<'gc>( pub fn native_instance_init<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
@ -41,17 +28,8 @@ pub fn native_instance_init<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements `flash.display.LoaderInfo`'s class constructor.
pub fn class_init<'gc>(
_activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
Ok(Value::Undefined)
}
/// `actionScriptVersion` getter /// `actionScriptVersion` getter
pub fn action_script_version<'gc>( pub fn get_action_script_version<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -77,7 +55,7 @@ pub fn action_script_version<'gc>(
} }
/// `applicationDomain` getter /// `applicationDomain` getter
pub fn application_domain<'gc>( pub fn get_application_domain<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -107,7 +85,7 @@ pub fn application_domain<'gc>(
} }
/// `bytesTotal` getter /// `bytesTotal` getter
pub fn bytes_total<'gc>( pub fn get_bytes_total<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -130,7 +108,7 @@ pub fn bytes_total<'gc>(
} }
/// `bytesLoaded` getter /// `bytesLoaded` getter
pub fn bytes_loaded<'gc>( pub fn get_bytes_loaded<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -157,7 +135,7 @@ pub fn bytes_loaded<'gc>(
} }
/// `content` getter /// `content` getter
pub fn content<'gc>( pub fn get_content<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -182,7 +160,7 @@ pub fn content<'gc>(
} }
/// `contentType` getter /// `contentType` getter
pub fn content_type<'gc>( pub fn get_content_type<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -205,7 +183,7 @@ pub fn content_type<'gc>(
} }
/// `frameRate` getter /// `frameRate` getter
pub fn frame_rate<'gc>( pub fn get_frame_rate<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -230,7 +208,7 @@ pub fn frame_rate<'gc>(
} }
/// `height` getter /// `height` getter
pub fn height<'gc>( pub fn get_height<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -255,7 +233,7 @@ pub fn height<'gc>(
} }
/// `isURLInaccessible` getter /// `isURLInaccessible` getter
pub fn is_url_inaccessible<'gc>( pub fn get_is_url_inaccessible<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>, _this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -265,7 +243,7 @@ pub fn is_url_inaccessible<'gc>(
} }
/// `parentAllowsChild` getter /// `parentAllowsChild` getter
pub fn parent_allows_child<'gc>( pub fn get_parent_allows_child<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>, _this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -275,7 +253,7 @@ pub fn parent_allows_child<'gc>(
} }
/// `swfVersion` getter /// `swfVersion` getter
pub fn swf_version<'gc>( pub fn get_swf_version<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -300,7 +278,7 @@ pub fn swf_version<'gc>(
} }
/// `url` getter /// `url` getter
pub fn url<'gc>( pub fn get_url<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -326,7 +304,7 @@ pub fn url<'gc>(
} }
/// `width` getter /// `width` getter
pub fn width<'gc>( pub fn get_width<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -351,7 +329,7 @@ pub fn width<'gc>(
} }
/// `bytes` getter /// `bytes` getter
pub fn bytes<'gc>( pub fn get_bytes<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -408,7 +386,7 @@ pub fn bytes<'gc>(
} }
/// `loader` getter /// `loader` getter
pub fn loader<'gc>( pub fn get_loader<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -421,7 +399,7 @@ pub fn loader<'gc>(
} }
/// `loaderURL` getter /// `loaderURL` getter
pub fn loader_url<'gc>( pub fn get_loader_url<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -445,7 +423,7 @@ pub fn loader_url<'gc>(
} }
/// `parameters` getter /// `parameters` getter
pub fn parameters<'gc>( pub fn get_parameters<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -481,7 +459,7 @@ pub fn parameters<'gc>(
} }
/// `sharedEvents` getter /// `sharedEvents` getter
pub fn shared_events<'gc>( pub fn get_shared_events<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -493,7 +471,7 @@ pub fn shared_events<'gc>(
} }
/// `uncaughtErrorEvents` getter /// `uncaughtErrorEvents` getter
pub fn uncaught_error_events<'gc>( pub fn get_uncaught_error_events<'gc>(
_activation: &mut Activation<'_, 'gc>, _activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>, this: Option<Object<'gc>>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
@ -503,61 +481,3 @@ pub fn uncaught_error_events<'gc>(
} }
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Construct `LoaderInfo`'s class.
pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Class<'gc>> {
let mc = activation.context.gc_context;
let class = Class::new(
QName::new(Namespace::package("flash.display", mc), "LoaderInfo"),
Some(Multiname::new(
Namespace::package("flash.events", mc),
"EventDispatcher",
)),
Method::from_builtin(instance_init, "<LoaderInfo instance initializer>", mc),
Method::from_builtin(class_init, "<LoaderInfo class initializer>", mc),
mc,
);
let mut write = class.write(mc);
write.set_attributes(ClassAttributes::SEALED);
write.set_instance_allocator(loaderinfo_allocator);
write.set_native_instance_init(Method::from_builtin(
native_instance_init,
"<LoaderInfo native instance initializer>",
mc,
));
const PUBLIC_INSTANCE_PROPERTIES: &[(
&str,
Option<NativeMethodImpl>,
Option<NativeMethodImpl>,
)] = &[
("actionScriptVersion", Some(action_script_version), None),
("applicationDomain", Some(application_domain), None),
("bytesLoaded", Some(bytes_loaded), None),
("bytesTotal", Some(bytes_total), None),
("content", Some(content), None),
("contentType", Some(content_type), None),
("frameRate", Some(frame_rate), None),
("height", Some(height), None),
("isURLInaccessible", Some(is_url_inaccessible), None),
("parentAllowsChild", Some(parent_allows_child), None),
("swfVersion", Some(swf_version), None),
("url", Some(url), None),
("width", Some(width), None),
("bytes", Some(bytes), None),
("loader", Some(loader), None),
("loaderURL", Some(loader_url), None),
("parameters", Some(parameters), None),
("sharedEvents", Some(shared_events), None),
("uncaughtErrorEvents", Some(uncaught_error_events), None),
];
write.define_builtin_instance_properties(
mc,
activation.avm2().public_namespace,
PUBLIC_INSTANCE_PROPERTIES,
);
class
}

View File

@ -35,6 +35,7 @@ include "flash/display/BitmapData.as"
include "flash/display/InteractiveObject.as" include "flash/display/InteractiveObject.as"
include "flash/display/DisplayObjectContainer.as" include "flash/display/DisplayObjectContainer.as"
include "flash/display/Stage.as" include "flash/display/Stage.as"
include "flash/display/LoaderInfo.as"
include "flash/display/ActionScriptVersion.as" include "flash/display/ActionScriptVersion.as"
include "flash/display/BitmapDataChannel.as" include "flash/display/BitmapDataChannel.as"

View File

@ -9,7 +9,6 @@ include "Array.as"
include "Boolean.as" include "Boolean.as"
include "Date.as" include "Date.as"
include "flash/display/LoaderInfo.as"
include "flash/media/SoundTransform.as" include "flash/media/SoundTransform.as"
include "flash/system/ApplicationDomain.as" include "flash/system/ApplicationDomain.as"
include "Function.as" include "Function.as"

View File

@ -71,7 +71,7 @@ pub use crate::avm2::object::event_object::{event_allocator, EventObject};
pub use crate::avm2::object::function_object::{function_allocator, FunctionObject}; pub use crate::avm2::object::function_object::{function_allocator, FunctionObject};
pub use crate::avm2::object::index_buffer_3d_object::IndexBuffer3DObject; pub use crate::avm2::object::index_buffer_3d_object::IndexBuffer3DObject;
pub use crate::avm2::object::loaderinfo_object::{ pub use crate::avm2::object::loaderinfo_object::{
loaderinfo_allocator, LoaderInfoObject, LoaderStream, loader_info_allocator, LoaderInfoObject, LoaderStream,
}; };
pub use crate::avm2::object::namespace_object::{namespace_allocator, NamespaceObject}; pub use crate::avm2::object::namespace_object::{namespace_allocator, NamespaceObject};
pub use crate::avm2::object::primitive_object::{primitive_allocator, PrimitiveObject}; pub use crate::avm2::object::primitive_object::{primitive_allocator, PrimitiveObject};

View File

@ -16,7 +16,7 @@ use std::cell::{Ref, RefMut};
use std::sync::Arc; use std::sync::Arc;
/// A class instance allocator that allocates LoaderInfo objects. /// A class instance allocator that allocates LoaderInfo objects.
pub fn loaderinfo_allocator<'gc>( pub fn loader_info_allocator<'gc>(
class: ClassObject<'gc>, class: ClassObject<'gc>,
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
) -> Result<Object<'gc>, Error<'gc>> { ) -> Result<Object<'gc>, Error<'gc>> {