From f753d840b645a6c4b440f3d2d72150cab8662b70 Mon Sep 17 00:00:00 2001 From: Lord-McSweeney Date: Fri, 4 Aug 2023 04:02:31 -0700 Subject: [PATCH] avm2: Add errors #2024, #2150, and #3738 --- .../flash/display/display_object_container.rs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/core/src/avm2/globals/flash/display/display_object_container.rs b/core/src/avm2/globals/flash/display/display_object_container.rs index 97cc8f5c5..fe1fcdc47 100644 --- a/core/src/avm2/globals/flash/display/display_object_container.rs +++ b/core/src/avm2/globals/flash/display/display_object_container.rs @@ -38,14 +38,31 @@ fn validate_add_operation<'gc>( .as_container() .ok_or("ArgumentError: Parent is not a DisplayObjectContainer")?; + if let DisplayObject::Stage(_) = proposed_child { + return Err(Error::AvmError(argument_error( + activation, + "Error #3783: A Stage object cannot be added as the child of another object.", + 3783, + )?)); + } + + if DisplayObject::ptr_eq(proposed_child, new_parent) { + return Err(Error::AvmError(argument_error( + activation, + "Error #2024: An object cannot be added as a child of itself.", + 2024, + )?)); + } + let mut checking_parent = Some(new_parent); while let Some(tp) = checking_parent { if DisplayObject::ptr_eq(tp, proposed_child) { - return Err( - "ArgumentError: Proposed child is an ancestor of the proposed parent, you cannot add the child to the parent" - .into(), - ); + return Err(Error::AvmError(argument_error( + activation, + "Error #2150: An object cannot be added as a child to one of it's children (or children's children, etc.).", + 2150, + )?)); } checking_parent = tp.parent(); @@ -476,11 +493,11 @@ pub fn swap_children<'gc>( let index0 = ctr .iter_render_list() .position(|a| DisplayObject::ptr_eq(a, child0)) - .ok_or("ArgumentError: Child is not a child of this display object")?; + .ok_or(make_error_2025(activation))?; let index1 = ctr .iter_render_list() .position(|a| DisplayObject::ptr_eq(a, child1)) - .ok_or("ArgumentError: Child is not a child of this display object")?; + .ok_or(make_error_2025(activation))?; child0.set_placed_by_script(activation.context.gc_context, true); child1.set_placed_by_script(activation.context.gc_context, true);