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:
David Wendt 2019-12-25 20:55:24 -05:00
parent 223320c98c
commit 6f48f3436f
6 changed files with 54 additions and 1 deletions

View File

@ -299,6 +299,48 @@ pub fn create_xmlnode_proto<'gc>(
None,
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
.as_script_object()
.unwrap()

View File

@ -320,7 +320,7 @@ impl<'gc> XMLNode<'gc> {
.checked_sub(1)
.and_then(|p| children.get(p).cloned());
let new_next = new_child_position
.checked_sub(1)
.checked_add(1)
.and_then(|p| children.get(p).cloned());
child.adopt_siblings(mc, new_prev, new_next)?

View File

@ -111,6 +111,7 @@ swf_tests! {
(xml_has_child_nodes, "avm1/xml_has_child_nodes", 1),
(xml_first_last_child, "avm1/xml_first_last_child", 1),
(xml_parent_and_child, "avm1/xml_parent_and_child", 1),
(xml_siblings, "avm1/xml_siblings", 1),
}
#[test]

View File

@ -0,0 +1,10 @@
null
true
true
true
true
true
true
null
null
null

Binary file not shown.

Binary file not shown.