From 8bbf8f4ea10aec6ad445755bad2ea947caf21572 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Tue, 1 Aug 2023 13:36:14 +0200 Subject: [PATCH] avm2: Use correct error in toString with invalid radix --- core/src/avm2/globals/int.rs | 8 +++++++- core/src/avm2/globals/number.rs | 8 +++++++- core/src/avm2/globals/uint.rs | 8 +++++++- .../RuntimeErrors/Error1003RadixArgOutOfRange/test.toml | 1 - 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/src/avm2/globals/int.rs b/core/src/avm2/globals/int.rs index 32ba63482..1016fe363 100644 --- a/core/src/avm2/globals/int.rs +++ b/core/src/avm2/globals/int.rs @@ -225,7 +225,13 @@ fn to_string<'gc>( .coerce_to_u32(activation)? as usize; if radix < 2 || radix > 36 { - return Err("toString can only print in bases 2 thru 36.".into()); + return Err(Error::AvmError(range_error( + activation, + &format!( + "Error #1003: The radix argument must be between 2 and 36; got {radix}." + ), + 1003, + )?)); } return Ok(print_with_radix(activation, number as f64, radix)?.into()); diff --git a/core/src/avm2/globals/number.rs b/core/src/avm2/globals/number.rs index 0475b13cb..02224bd1c 100644 --- a/core/src/avm2/globals/number.rs +++ b/core/src/avm2/globals/number.rs @@ -321,7 +321,13 @@ fn to_string<'gc>( .coerce_to_u32(activation)? as usize; if radix < 2 || radix > 36 { - return Err("toString can only print in bases 2 thru 36.".into()); + return Err(Error::AvmError(range_error( + activation, + &format!( + "Error #1003: The radix argument must be between 2 and 36; got {radix}." + ), + 1003, + )?)); } return Ok(print_with_radix(activation, number, radix)?.into()); diff --git a/core/src/avm2/globals/uint.rs b/core/src/avm2/globals/uint.rs index 0c2e5cad4..9d076f178 100644 --- a/core/src/avm2/globals/uint.rs +++ b/core/src/avm2/globals/uint.rs @@ -224,7 +224,13 @@ fn to_string<'gc>( .coerce_to_u32(activation)? as usize; if radix < 2 || radix > 36 { - return Err("toString can only print in bases 2 thru 36.".into()); + return Err(Error::AvmError(range_error( + activation, + &format!( + "Error #1003: The radix argument must be between 2 and 36; got {radix}." + ), + 1003, + )?)); } return Ok(print_with_radix(activation, number as f64, radix)?.into()); diff --git a/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1003RadixArgOutOfRange/test.toml b/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1003RadixArgOutOfRange/test.toml index 29f3cef79..cf6123969 100644 --- a/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1003RadixArgOutOfRange/test.toml +++ b/tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1003RadixArgOutOfRange/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true