Skip to content

Commit

Permalink
avm2: Namespace support for XML.name()
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie authored and adrian17 committed Oct 1, 2023
1 parent 30614bd commit 6d51bc3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 2 additions & 7 deletions core/src/avm2/globals/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ pub fn name<'gc>(
) -> Result<Value<'gc>, 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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions core/src/avm2/object/xml_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
num_ticks = 1
known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12351

0 comments on commit 6d51bc3

Please sign in to comment.