From 6d51bc39640b565cad47d7f6d9400e77ddf93d15 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Sat, 23 Sep 2023 14:34:22 +0200 Subject: [PATCH] avm2: Namespace support for XML.name() --- core/src/avm2/globals/xml.rs | 9 ++------- core/src/avm2/object/xml_object.rs | 8 ++++++++ .../swfs/from_avmplus/e4x/Expressions/e11_1_1/test.toml | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index db07dfb7ede9..0f8633b2da4c 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -73,9 +73,7 @@ pub fn name<'gc>( ) -> Result, Error<'gc>> { let node = this.as_xml_object().unwrap(); if let Some(local_name) = node.local_name() { - avm2_stub_method!(activation, "XML", "name", "namespaces"); - // FIXME - use namespace - let namespace = activation.avm2().public_namespace; + let namespace = node.namespace(activation); Ok(QNameObject::from_name(activation, Multiname::new(namespace, local_name))?.into()) } else { Ok(Value::Null) @@ -162,10 +160,7 @@ pub fn namespace_internal_impl<'gc>( // b. Return the result of calling the [[GetNamespace]] method of x.[[Name]] with argument inScopeNS // FIXME: Use inScopeNS - let namespace = match node.namespace() { - Some(ns) => Namespace::package(ns, &mut activation.context.borrow_gc()), - None => activation.avm2().public_namespace, - }; + let namespace = xml.namespace(activation); Ok(NamespaceObject::from_namespace(activation, namespace)?.into()) } else { // a. Let prefix = ToString(prefix) diff --git a/core/src/avm2/object/xml_object.rs b/core/src/avm2/object/xml_object.rs index 95398f15cd6e..0e4ea071e66c 100644 --- a/core/src/avm2/object/xml_object.rs +++ b/core/src/avm2/object/xml_object.rs @@ -7,6 +7,7 @@ use crate::avm2::object::script_object::ScriptObjectData; use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject, XmlListObject}; use crate::avm2::string::AvmString; use crate::avm2::value::Value; +use crate::avm2::Namespace; use crate::avm2::{Error, Multiname}; use core::fmt; use gc_arena::{Collect, GcCell, GcWeakCell, Mutation}; @@ -75,6 +76,13 @@ impl<'gc> XmlObject<'gc> { self.0.read().node.local_name() } + pub fn namespace(&self, activation: &mut Activation<'_, 'gc>) -> Namespace<'gc> { + match self.0.read().node.namespace() { + Some(ns) => Namespace::package(ns, &mut activation.context.borrow_gc()), + None => activation.avm2().public_namespace, + } + } + pub fn matches_name(&self, multiname: &Multiname<'gc>) -> bool { self.0.read().node.matches_name(multiname) } diff --git a/tests/tests/swfs/from_avmplus/e4x/Expressions/e11_1_1/test.toml b/tests/tests/swfs/from_avmplus/e4x/Expressions/e11_1_1/test.toml index e115772d5b3a..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/e4x/Expressions/e11_1_1/test.toml +++ b/tests/tests/swfs/from_avmplus/e4x/Expressions/e11_1_1/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12351