From 5941d6cf668dbcdbb51586977ccb99ba36eace0c Mon Sep 17 00:00:00 2001 From: David Wendt Date: Sat, 20 Mar 2021 23:13:19 -0400 Subject: [PATCH] avm2: Impl `LoaderInfo.swfVersion` --- .../avm2/globals/flash/display/loaderinfo.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/avm2/globals/flash/display/loaderinfo.rs b/core/src/avm2/globals/flash/display/loaderinfo.rs index d058a0f26..1fb957d7c 100644 --- a/core/src/avm2/globals/flash/display/loaderinfo.rs +++ b/core/src/avm2/globals/flash/display/loaderinfo.rs @@ -190,6 +190,25 @@ pub fn is_url_inaccessible<'gc>( Ok(false.into()) } +/// `swfVersion` getter +pub fn swf_version<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(this) = this { + if let Some(loader_stream) = this.as_loader_stream() { + match &*loader_stream { + LoaderStream::SWF(root, _) => { + return Ok(root.header().version.into()); + } + } + } + } + + Ok(Value::Undefined) +} + /// Derive `LoaderInfoObject` impls. pub fn loaderinfo_deriver<'gc>( base_proto: Object<'gc>, @@ -250,6 +269,10 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> QName::new(Namespace::public(), "isURLInaccessible"), Method::from_builtin(is_url_inaccessible), )); + write.define_instance_trait(Trait::from_getter( + QName::new(Namespace::public(), "swfVersion"), + Method::from_builtin(swf_version), + )); class }