avm2: Implement XML.nodeKind

This commit is contained in:
Nathan Adams 2023-03-16 00:13:57 +01:00
parent acd160674a
commit d22b07167c
7 changed files with 54 additions and 0 deletions

View File

@ -16,6 +16,7 @@ package {
AS3 native function elements(name:*):XMLList;
AS3 native function attributes():XMLList;
AS3 native function attribute(name:*):XMLList;
AS3 native function nodeKind():String;
AS3 native function toString():String;
@ -71,5 +72,10 @@ package {
var self:XML = this;
return self.AS3::attribute(name);
};
prototype.nodeKind = function():String {
var self:XML = this;
return self.AS3::nodeKind();
};
}
}

View File

@ -203,3 +203,21 @@ pub fn call_handler<'gc>(
.construct(activation, args)?
.into())
}
pub fn node_kind<'gc>(
_activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let this = this.unwrap();
let xml = this.as_xml_object().unwrap();
let name = match &*xml.node().kind() {
E4XNodeKind::Text(_) => "text",
E4XNodeKind::CData(_) => "text", // cdata pretends to be text here
E4XNodeKind::Comment(_) => "comment",
E4XNodeKind::ProcessingInstruction(_) => "processing-instruction",
E4XNodeKind::Attribute(_) => "attribute",
E4XNodeKind::Element { .. } => "element",
};
Ok(name.into())
}

View File

@ -0,0 +1,26 @@
package {
import flash.display.MovieClip;
public class Test extends MovieClip {
public function Test() {
// Taken from https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#nodeKind()
// Modified to run with what ruffle support
//XML.ignoreComments = false;
var xml:XML =
<example id="10">
<![CDATA[some cdata]]>
and some text
</example>;
trace(xml.nodeKind()); // element
trace(xml.children()[0].nodeKind()); // text
trace(xml.children()[1].nodeKind()); // text
}
}
}

View File

@ -0,0 +1,3 @@
element
text
text

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
num_frames = 1