From b1056311f0241df6e766ba638f768775ba655a92 Mon Sep 17 00:00:00 2001 From: Lord-McSweeney Date: Thu, 19 Oct 2023 18:32:07 -0700 Subject: [PATCH] avm2: Implement Error 1112 --- core/src/avm2/object/class_object.rs | 19 +++++++++++++------ .../test.toml | 1 - 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/avm2/object/class_object.rs b/core/src/avm2/object/class_object.rs index ea453b864..729cb282a 100644 --- a/core/src/avm2/object/class_object.rs +++ b/core/src/avm2/object/class_object.rs @@ -2,7 +2,7 @@ use crate::avm2::activation::Activation; use crate::avm2::class::{Allocator, AllocatorFn, Class, ClassHashWrapper}; -use crate::avm2::error::{make_error_1127, type_error}; +use crate::avm2::error::{argument_error, make_error_1127, type_error}; use crate::avm2::function::Executable; use crate::avm2::method::Method; use crate::avm2::object::function_object::FunctionObject; @@ -857,11 +857,18 @@ impl<'gc> TObject<'gc> for ClassObject<'gc> { func.exec(receiver, arguments, activation, self.into()) } else { - arguments - .get(0) - .cloned() - .unwrap_or(Value::Undefined) - .coerce_to_type(activation, self.inner_class_definition()) + if arguments.len() == 1 { + arguments[0].coerce_to_type(activation, self.inner_class_definition()) + } else { + Err(Error::AvmError(argument_error( + activation, + &format!( + "Error #1112: Argument count mismatch on class coercion. Expected 1, got {}.", + arguments.len() + ), + 1112, + )?)) + } } } diff --git a/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1112ArgCountMismatchOnClassCoercion/test.toml b/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1112ArgCountMismatchOnClassCoercion/test.toml index 29f3cef79..cf6123969 100644 --- a/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1112ArgCountMismatchOnClassCoercion/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1112ArgCountMismatchOnClassCoercion/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true