avm2+tests: Allow concating XMLLists; add test
This commit is contained in:
parent
2729da8ec0
commit
4c1c3cc105
|
@ -11,6 +11,7 @@ use crate::avm2::error::{
|
|||
use crate::avm2::method::{BytecodeMethod, Method, ParamConfig};
|
||||
use crate::avm2::object::{
|
||||
ArrayObject, ByteArrayObject, ClassObject, FunctionObject, NamespaceObject, ScriptObject,
|
||||
XmlListObject,
|
||||
};
|
||||
use crate::avm2::object::{Object, TObject};
|
||||
use crate::avm2::scope::{search_scope_stack, Scope, ScopeChain};
|
||||
|
@ -2114,6 +2115,10 @@ impl<'a, 'gc> Activation<'a, 'gc> {
|
|||
value1.coerce_to_string(self)?,
|
||||
s,
|
||||
)),
|
||||
(
|
||||
Value::Object(Object::XmlListObject(value1)),
|
||||
Value::Object(Object::XmlListObject(value2)),
|
||||
) => Value::Object(XmlListObject::concat(self, value1, value2).into()),
|
||||
(value1, value2) => {
|
||||
let prim_value1 = value1.coerce_to_primitive(None, self)?;
|
||||
let prim_value2 = value2.coerce_to_primitive(None, self)?;
|
||||
|
|
|
@ -136,6 +136,23 @@ impl<'gc> XmlListObject<'gc> {
|
|||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn concat(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
left: XmlListObject<'gc>,
|
||||
right: XmlListObject<'gc>,
|
||||
) -> XmlListObject<'gc> {
|
||||
if left.length() == 0 {
|
||||
right
|
||||
} else if right.length() == 0 {
|
||||
left
|
||||
} else {
|
||||
let mut out = vec![];
|
||||
out.extend(left.children().clone());
|
||||
out.extend(right.children().clone());
|
||||
Self::new(activation, out, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Collect)]
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package
|
||||
{
|
||||
import flash.display.Sprite;
|
||||
|
||||
public class Test extends Sprite
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
var test:XML = <root>
|
||||
<list1>
|
||||
<item>
|
||||
<text>Hello</text>
|
||||
</item>
|
||||
<item>
|
||||
<text>World</text>
|
||||
</item>
|
||||
</list1>
|
||||
<list2>
|
||||
<item>
|
||||
<text>from</text>
|
||||
</item>
|
||||
<item>
|
||||
<text>Ruffle!</text>
|
||||
</item>
|
||||
</list2>
|
||||
</root>;
|
||||
|
||||
var list:XMLList = test.list1.item + test.list2.item;
|
||||
|
||||
for (var i:int = 0; i < list.length(); i++)
|
||||
{
|
||||
var val:XML = list[i];
|
||||
|
||||
trace(val.text[0].toString());
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
Hello
|
||||
World
|
||||
from
|
||||
Ruffle!
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_ticks = 1
|
Loading…
Reference in New Issue