avm2: Implement XML.nodeKind
This commit is contained in:
parent
acd160674a
commit
d22b07167c
|
@ -16,6 +16,7 @@ package {
|
||||||
AS3 native function elements(name:*):XMLList;
|
AS3 native function elements(name:*):XMLList;
|
||||||
AS3 native function attributes():XMLList;
|
AS3 native function attributes():XMLList;
|
||||||
AS3 native function attribute(name:*):XMLList;
|
AS3 native function attribute(name:*):XMLList;
|
||||||
|
AS3 native function nodeKind():String;
|
||||||
|
|
||||||
|
|
||||||
AS3 native function toString():String;
|
AS3 native function toString():String;
|
||||||
|
@ -71,5 +72,10 @@ package {
|
||||||
var self:XML = this;
|
var self:XML = this;
|
||||||
return self.AS3::attribute(name);
|
return self.AS3::attribute(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
prototype.nodeKind = function():String {
|
||||||
|
var self:XML = this;
|
||||||
|
return self.AS3::nodeKind();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,3 +203,21 @@ pub fn call_handler<'gc>(
|
||||||
.construct(activation, args)?
|
.construct(activation, args)?
|
||||||
.into())
|
.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())
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
element
|
||||||
|
text
|
||||||
|
text
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
num_frames = 1
|
Loading…
Reference in New Issue