Expose `previousSibling` and `nextSibling` to ActionScript.
This commit also fixes a bug caused by excessive use of copypaste, which was detected by the included test.
This commit is contained in:
parent
223320c98c
commit
6f48f3436f
|
@ -299,6 +299,48 @@ pub fn create_xmlnode_proto<'gc>(
|
||||||
None,
|
None,
|
||||||
ReadOnly.into(),
|
ReadOnly.into(),
|
||||||
);
|
);
|
||||||
|
xmlnode_proto.add_property(
|
||||||
|
gc_context,
|
||||||
|
"previousSibling",
|
||||||
|
Executable::Native(|avm, ac, this: Object<'gc>, _args| {
|
||||||
|
if let Some(node) = this.as_xml_node() {
|
||||||
|
return Ok(node
|
||||||
|
.prev_sibling()
|
||||||
|
.unwrap_or(None)
|
||||||
|
.map(|mut parent| {
|
||||||
|
parent
|
||||||
|
.script_object(ac.gc_context, Some(avm.prototypes.xml_node))
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| Value::Null.into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined.into())
|
||||||
|
}),
|
||||||
|
None,
|
||||||
|
ReadOnly.into(),
|
||||||
|
);
|
||||||
|
xmlnode_proto.add_property(
|
||||||
|
gc_context,
|
||||||
|
"nextSibling",
|
||||||
|
Executable::Native(|avm, ac, this: Object<'gc>, _args| {
|
||||||
|
if let Some(node) = this.as_xml_node() {
|
||||||
|
return Ok(node
|
||||||
|
.next_sibling()
|
||||||
|
.unwrap_or(None)
|
||||||
|
.map(|mut parent| {
|
||||||
|
parent
|
||||||
|
.script_object(ac.gc_context, Some(avm.prototypes.xml_node))
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| Value::Null.into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined.into())
|
||||||
|
}),
|
||||||
|
None,
|
||||||
|
ReadOnly.into(),
|
||||||
|
);
|
||||||
xmlnode_proto
|
xmlnode_proto
|
||||||
.as_script_object()
|
.as_script_object()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -320,7 +320,7 @@ impl<'gc> XMLNode<'gc> {
|
||||||
.checked_sub(1)
|
.checked_sub(1)
|
||||||
.and_then(|p| children.get(p).cloned());
|
.and_then(|p| children.get(p).cloned());
|
||||||
let new_next = new_child_position
|
let new_next = new_child_position
|
||||||
.checked_sub(1)
|
.checked_add(1)
|
||||||
.and_then(|p| children.get(p).cloned());
|
.and_then(|p| children.get(p).cloned());
|
||||||
|
|
||||||
child.adopt_siblings(mc, new_prev, new_next)?
|
child.adopt_siblings(mc, new_prev, new_next)?
|
||||||
|
|
|
@ -111,6 +111,7 @@ swf_tests! {
|
||||||
(xml_has_child_nodes, "avm1/xml_has_child_nodes", 1),
|
(xml_has_child_nodes, "avm1/xml_has_child_nodes", 1),
|
||||||
(xml_first_last_child, "avm1/xml_first_last_child", 1),
|
(xml_first_last_child, "avm1/xml_first_last_child", 1),
|
||||||
(xml_parent_and_child, "avm1/xml_parent_and_child", 1),
|
(xml_parent_and_child, "avm1/xml_parent_and_child", 1),
|
||||||
|
(xml_siblings, "avm1/xml_siblings", 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
null
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue