Skip to content

Commit ad19c29

Browse files
Aaron1011relrelb
authored andcommitted
Remove null from getChildByName for missing child
This matches the behavior of Flash - no error is produced.
1 parent 992e347 commit ad19c29

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

core/src/avm2/globals/flash/display/displayobjectcontainer.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,12 @@ pub fn get_child_by_name<'gc>(
168168
.cloned()
169169
.unwrap_or(Value::Undefined)
170170
.coerce_to_string(activation)?;
171-
let child = dobj.child_by_name(&name, false).ok_or_else(|| {
172-
format!(
173-
"RangeError: Display object container has no child with name {}",
174-
name
175-
)
176-
})?;
177-
178-
return Ok(child.object2());
171+
if let Some(child) = dobj.child_by_name(&name, false) {
172+
return Ok(child.object2());
173+
} else {
174+
log::warn!("Display object container has no child with name {}", name);
175+
return Ok(Value::Null);
176+
}
179177
}
180178

181179
Ok(Value::Undefined)

tests/tests/swfs/avm2/displayobjectcontainer_getchildbyname/output.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
//this.getChildByName("child_clip").child_method()
44
//Child method called
55
//this.addChild(newChild)
6-
//this.getchildByName("new_child")
6+
//this.getChildByName("new_child")
77
[object Sprite]
8+
//this.getChildByName("nonexistent_child")
9+
null
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)