avm2: Add make_error_2004

This commit is contained in:
Kamil Jarosz 2024-06-17 20:48:15 +02:00 committed by Nathan Adams
parent 687e049dc1
commit fae1500cc6
5 changed files with 35 additions and 26 deletions

View File

@ -423,6 +423,31 @@ pub fn make_error_1508<'gc>(activation: &mut Activation<'_, 'gc>, param_name: &s
}
}
pub enum Error2004Type {
Error,
ArgumentError,
TypeError,
}
#[inline(never)]
#[cold]
pub fn make_error_2004<'gc>(
activation: &mut Activation<'_, 'gc>,
kind: Error2004Type,
) -> Error<'gc> {
let message = "Error #2004: One of the parameters is invalid.";
let code = 2004;
let err = match kind {
Error2004Type::Error => error(activation, message, code),
Error2004Type::ArgumentError => argument_error(activation, message, code),
Error2004Type::TypeError => type_error(activation, message, code),
};
match err {
Ok(err) => Error::AvmError(err),
Err(err) => err,
}
}
#[inline(never)]
#[cold]
pub fn make_error_2006<'gc>(activation: &mut Activation<'_, 'gc>) -> Error<'gc> {

View File

@ -1,6 +1,6 @@
//! `flash.crypto` namespace
use crate::avm2::error::error;
use crate::avm2::error::{make_error_2004, Error2004Type};
use crate::avm2::object::TObject;
use crate::avm2::{Activation, Error, Object, Value};
use rand::{rngs::OsRng, RngCore};
@ -16,11 +16,7 @@ pub fn generate_random_bytes<'gc>(
.unwrap_or(&Value::Undefined)
.coerce_to_u32(activation)?;
if !(1..1025).contains(&length) {
return Err(Error::AvmError(error(
activation,
"Error #2004: One of the parameters is invalid.",
2004,
)?));
return Err(make_error_2004(activation, Error2004Type::Error));
}
let ba_class = activation.context.avm2.classes().bytearray;

View File

@ -2,7 +2,9 @@
use crate::avm2::activation::Activation;
use crate::avm2::bytearray::ByteArrayStorage;
use crate::avm2::error::{argument_error, make_error_2007, make_error_2008, range_error};
use crate::avm2::error::{
argument_error, make_error_2004, make_error_2007, make_error_2008, range_error, Error2004Type,
};
use crate::avm2::filters::FilterAvm2Ext;
pub use crate::avm2::object::bitmap_data_allocator;
use crate::avm2::object::{BitmapDataObject, ByteArrayObject, Object, TObject, VectorObject};
@ -1025,13 +1027,7 @@ pub fn draw_with_quality<'gc>(
let quality = if let Some(quality) = args.try_get_string(activation, 6)? {
match quality.parse() {
Ok(quality) => quality,
Err(_) => {
return Err(Error::AvmError(argument_error(
activation,
"Error #2004: One of the parameters is invalid.",
2004,
)?));
}
Err(_) => return Err(make_error_2004(activation, Error2004Type::ArgumentError)),
}
} else {
activation.context.stage.quality()

View File

@ -4,7 +4,7 @@
#![allow(clippy::doc_lazy_continuation)]
use crate::avm2::activation::Activation;
use crate::avm2::error::{argument_error, make_error_2008};
use crate::avm2::error::{make_error_2004, make_error_2008, Error2004Type};
use crate::avm2::globals::flash::geom::transform::object_to_matrix;
use crate::avm2::object::{Object, TObject, VectorObject};
use crate::avm2::parameters::ParametersExt;
@ -1184,11 +1184,7 @@ fn read_point<'gc>(
data_index: &mut usize,
) -> Result<Point<Twips>, Error<'gc>> {
if *data_index + 1 >= data.length() {
return Err(Error::AvmError(argument_error(
activation,
"Error #2004: One of the parameters is invalid.",
2004,
)?));
return Err(make_error_2004(activation, Error2004Type::ArgumentError));
}
let x = data
.get(*data_index, activation)

View File

@ -1,4 +1,4 @@
use crate::avm2::error::type_error;
use crate::avm2::error::{make_error_2004, Error2004Type};
use crate::avm2::parameters::ParametersExt;
use crate::avm2::{Activation, Error, Object, TObject, Value};
@ -107,11 +107,7 @@ pub fn set_client<'gc>(
ns.set_client(activation.context.gc_context, client);
}
} else {
return Err(Error::AvmError(type_error(
activation,
"Error #2004: One of the parameters is invalid.",
2004,
)?));
return Err(make_error_2004(activation, Error2004Type::TypeError));
}
Ok(Value::Undefined)