avm2: Add make_error_1125

This commit is contained in:
Kamil Jarosz 2024-06-17 19:23:15 +02:00
parent 4d12e0e5b4
commit 9e1248d130
2 changed files with 22 additions and 25 deletions

View File

@ -378,6 +378,24 @@ pub fn make_error_1118<'gc>(activation: &mut Activation<'_, 'gc>) -> Error<'gc>
}
}
#[inline(never)]
#[cold]
pub fn make_error_1125<'gc>(
activation: &mut Activation<'_, 'gc>,
index: usize,
range: usize,
) -> Error<'gc> {
let err = range_error(
activation,
&format!("Error #1125: The index {index} is out of range {range}."),
1125,
);
match err {
Ok(err) => Error::AvmError(err),
Err(err) => err,
}
}
#[inline(never)]
#[cold]
pub fn make_error_1127<'gc>(activation: &mut Activation<'_, 'gc>) -> Error<'gc> {

View File

@ -2,7 +2,7 @@
use crate::avm2::activation::Activation;
use crate::avm2::class::Class;
use crate::avm2::error::range_error;
use crate::avm2::error::{make_error_1125, range_error};
use crate::avm2::value::Value;
use crate::avm2::Error;
use gc_arena::Collect;
@ -170,14 +170,7 @@ impl<'gc> VectorStorage<'gc> {
if let Some(val) = self.get_optional(pos) {
Ok(val)
} else {
Err(Error::AvmError(range_error(
activation,
&format!(
"Error #1125: The index {pos} is out of range {}.",
self.length()
),
1125,
)?))
Err(make_error_1125(activation, pos, self.length()))
}
}
@ -209,14 +202,7 @@ impl<'gc> VectorStorage<'gc> {
*v = value;
Ok(())
} else {
Err(Error::AvmError(range_error(
activation,
&format!(
"Error #1125: The index {pos} is out of range {}.",
self.length()
),
1125,
)?))
Err(make_error_1125(activation, pos, self.length()))
}
}
@ -359,14 +345,7 @@ impl<'gc> VectorStorage<'gc> {
};
if position >= self.storage.len() {
Err(Error::AvmError(range_error(
activation,
&format!(
"Error #1125: The index {position} is out of range {}.",
self.length()
),
1125,
)?))
Err(make_error_1125(activation, position, self.length()))
} else {
Ok(self.storage.remove(position))
}