From 4b2907ead56e5806f441fcb7e32e1030166cb2d2 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 5 Oct 2022 12:29:21 -0500 Subject: [PATCH] avm2: Fix 'hasDefinition' and 'getDefinition' for ApplicationDomain These methods were incorrectly treating the argument as a local name, instead of a qualified name. Additionally, 'getDefinition' now throws an AVM error. --- .../flash/system/application_domain.rs | 26 ++++++++++++------ tests/tests/regression_tests.rs | 1 + .../swfs/avm2/application_domain/Test.as | 23 ++++++++++++++++ .../swfs/avm2/application_domain/output.txt | 4 +++ .../swfs/avm2/application_domain/test.fla | Bin 0 -> 3816 bytes .../swfs/avm2/application_domain/test.swf | Bin 0 -> 798 bytes 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 tests/tests/swfs/avm2/application_domain/Test.as create mode 100644 tests/tests/swfs/avm2/application_domain/output.txt create mode 100644 tests/tests/swfs/avm2/application_domain/test.fla create mode 100644 tests/tests/swfs/avm2/application_domain/test.swf diff --git a/core/src/avm2/globals/flash/system/application_domain.rs b/core/src/avm2/globals/flash/system/application_domain.rs index 07c050e41..91eb617f2 100644 --- a/core/src/avm2/globals/flash/system/application_domain.rs +++ b/core/src/avm2/globals/flash/system/application_domain.rs @@ -66,16 +66,25 @@ pub fn get_definition<'gc>( args: &[Value<'gc>], ) -> Result, Error<'gc>> { if let Some(appdomain) = this.and_then(|this| this.as_application_domain()) { - let local_name = args + let name = args .get(0) .cloned() .unwrap_or_else(|| "".into()) .coerce_to_string(activation)?; - let name = Multiname::public(local_name); - - let (qname, mut defined_script) = appdomain - .get_defining_script(&name)? - .ok_or_else(|| format!("No definition called {} exists", local_name))?; + let name = QName::from_qualified_name(name, activation.context.gc_context); + let (qname, mut defined_script) = match appdomain.get_defining_script(&name.into())? { + Some(data) => data, + None => { + return Err(Error::AvmError(crate::avm2::error::reference_error( + activation, + &format!( + "Error #1065: Variable {} is not defined.", + name.local_name() + ), + 1065, + )?)) + } + }; let globals = defined_script.globals(&mut activation.context)?; let definition = globals.get_property(&qname.into(), activation)?; @@ -92,12 +101,13 @@ pub fn has_definition<'gc>( args: &[Value<'gc>], ) -> Result, Error<'gc>> { if let Some(appdomain) = this.and_then(|this| this.as_application_domain()) { - let local_name = args + let name = args .get(0) .cloned() .unwrap_or_else(|| "".into()) .coerce_to_string(activation)?; - let qname = QName::new(Namespace::public(), local_name); + + let qname = QName::from_qualified_name(name, activation.context.gc_context); return Ok(appdomain.has_definition(qname).into()); } diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index d310f016e..3f01959cf 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -155,6 +155,7 @@ swf_tests! { (as2_super_and_this_v8, "avm1/as2_super_and_this_v8", 1), (as2_super_via_manual_prototype, "avm1/as2_super_via_manual_prototype", 1), (as3_add, "avm2/add", 1), + (as3_application_domain, "avm2/application_domain", 1), (as3_array_access, "avm2/array_access", 1), (as3_array_concat, "avm2/array_concat", 1), (as3_array_constr, "avm2/array_constr", 1), diff --git a/tests/tests/swfs/avm2/application_domain/Test.as b/tests/tests/swfs/avm2/application_domain/Test.as new file mode 100644 index 000000000..db3153ce1 --- /dev/null +++ b/tests/tests/swfs/avm2/application_domain/Test.as @@ -0,0 +1,23 @@ +package { + import flash.system.ApplicationDomain; + + public class Test { + public function Test() { + try { + ApplicationDomain.currentDomain.getDefinition("some.package.MissingClass") + } catch (e:Error) { + trace("Caught error: " + e); + } + + try { + ApplicationDomain.currentDomain.getDefinition("OtherMissingClass") + } catch (e:Error) { + trace("Caught error: " + e); + } + + trace("Has definition: " + ApplicationDomain.currentDomain.hasDefinition("flash.display.MovieClip")); + var cls = ApplicationDomain.currentDomain.getDefinition("flash.display.MovieClip"); + trace("Got class: " + cls); + } + } +} \ No newline at end of file diff --git a/tests/tests/swfs/avm2/application_domain/output.txt b/tests/tests/swfs/avm2/application_domain/output.txt new file mode 100644 index 000000000..2117542cc --- /dev/null +++ b/tests/tests/swfs/avm2/application_domain/output.txt @@ -0,0 +1,4 @@ +Caught error: ReferenceError: Error #1065: Variable MissingClass is not defined. +Caught error: ReferenceError: Error #1065: Variable OtherMissingClass is not defined. +Has definition: true +Got class: [class MovieClip] diff --git a/tests/tests/swfs/avm2/application_domain/test.fla b/tests/tests/swfs/avm2/application_domain/test.fla new file mode 100644 index 0000000000000000000000000000000000000000..e0f76c8df1a52d4d9432107b36c763dab383ca2b GIT binary patch literal 3816 zcmbtXc{G&m{~pWOnlOxg31y22VeI>sow6k|jL0y`2$9M*QDjdgYvI*0nC!b`-*?#} zD*Kig>-U*oZ+Ux9z5o0^&-t9^zVGLA-JknB=ep0iE)#t+au^6i1p=uew9c2uPKL38 zKpAIl0XfMLr6fnn~F;((j*BTMjC`9M`D?CJm`fpeYo@)jhNVr$*>aTTA{Y*XE;R? z)$8E!5@ht%wWH4vK?+GdSz3lqLR62)&E$LLU4W>IU3N`7YMMwc&n)S^;?rmonutOF#9E`{1ln+v`)QY6_F~b92Tmd1C3`+f z=Trn1J&`t5;9Uv!hW{01$V|JVHrgbW$V|)Qh&6@u1RJ0Q6s-j5<*ZscSK>(e;|tC| zWr^a%XQT@VE#G1fGC5HP-yJUq@ZwrG>*dKxj8@GNr%#Qp4=okf^F5h0N+zjx=V|b% z`+;u*#rQH&U736LL+Xp;MueFDkml{&auPwt--8Aw0E33VGdtCy!M=o)L zFY+R@-#x@NRaf#+;>F~R#cb?pg)R3DJes6xg-Ngm+#mHj)-EUzHkB4aoos_`g9h%a zB*O{?vs2cFX`Vm1Yp+BU;;)z$qQT*2PX%N1CeY$Am5oe zTcYGg3Bbv?Kp;i{V)C8H=12_2)#I`k5%A9X06itoaIm+>M5Xj}>6wl`70hZ#S2(^X zyJsfx+eV;j?&zhO5&F-ZWQ+S7=-pFr0o2GyLdwa6M-LhuJ6Ss6dbgmNsEs7aG9HPJ zpowj8TERQf<7WuA8%A^eXM+Z|yu9zSxG=6?;eUTRjB&rTWthS;c;aNjzSBA^4kev| zirfn6hDjNDTGUeCh*%w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2!ZI&4B1=b+!VC112V_M$;oZ{Dlm%+5Ht zPe#UK=fvtr9qXzKzsOqj%Xg1Xk`@uPINayOo2M)}aJZO)h|gdBi*5H=d74Pxka7!I zb-%ytcD6LYFIO1f*Lu4l9;ueu&v1lo;G2H!jgeDvBdzv}i9W-D^+{fJSU9+-`=t`p zZWvmX8*;TweXloQf$Ta<8-8&=XrTK2(w!SO#h%c<6u~jlI+05m4F<7Th9`Fm&V4ge zL^Sn~I$I@+QLmhfd)_4&tIHfkihg33mq))=Ikp_wnx(>|n*TaP)TWm3+Cs?Q1)H#A zj9btBJclFcS8ZxC#l z(LJVAW!?q<&<)?k_)nby3>b(~1C4M+A^#~Ge$~~-A*|J$KpioOIs@VAA#U#Hu8H(S z0+QX)!O;bI8Cd>ANdqDSfk6;pQ)XaJjH*|FEcr#s|3937K42ucjyjPMwLLM3P5{vB zfD8xxf|;?E^(hT=X%l@CQW)sac>py(g9!K@^uS96$U`IXXB4s3_aLH>K>pNb|J96W zExrd4b|1*!7>(~;|711(#sjZ%Apd1Ne)Rs6fII~Ak^SSyzskv9`~O=|9&T|S*y1zQ8vS=zmr&>t_G} literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/application_domain/test.swf b/tests/tests/swfs/avm2/application_domain/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..00cb0e3251160add527d0781dd0712771284da77 GIT binary patch literal 798 zcmV+(1L6EbS5qqv1pokeoRw1RZWB2a_L-Y!a!;FEVM7C?u-jIty8?m24?qc&i%NuA zi3+u9yc4IHC7DEHHw%Ax1fGCjyauljez32x(CdOnd7DEX7$ePs!LvOuq}_?ec8D+?(TKo+WC5N$Vxq~qp6@BGDFW)URD&KL^+bgQ!7!*-vMteL!MrH* zgz`$~Tve|WFSxIryHEBg|5iP|H53(B6{uItN2)k5-R<-8*&fyA_ozNQrxfjU9;?}o z8+ape{U_x4)ogFrSZ)AMKT@G7Tcg62Mv~2_%jh(-Pkq6pY2l4ogcL618$(~n$}F&U zMu8{T`u{kx{a67?W&szRQoM)@=^_-aY5;i*CI$=ZHa23|N?@G9kj1cwA%|fJ!(|M= zV7u&?fMFRs*RXLN8&zzqVB-dkuDzy3QGL4njA*Wb=4f)F8@7o|FhM1B$p(-U3v>ej zBal&_kS!@ObTjb@PLiQHA+J`yl7AqDOu2Z9Lfp2xczvN|LuhBNAT%Lg$ZNFv_bOQ% zKv^X2;bY5zvaN;5DZQZRsdGA<(bM147bH-eN=lDoQ#4#;FavCOFEu$yxx^sS zg!wHkx4aThG+yk+6Of#`mA3Tagvj=dgH&51ZEX*gd&-U`&FKJ6Eb=LB$Kq+pyb{6z zJOlLGlws-;E=-8DdyqbJ=SbU-?;ez+ cr>CFX3`