Skip to content

Commit

Permalink
avm2: Add a make_error_1014 function and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Mar 10, 2024
1 parent f76117a commit 788c3da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
18 changes: 18 additions & 0 deletions core/src/avm2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ pub fn make_error_1010<'gc>(
}
}

#[inline(never)]
#[cold]
pub fn make_error_1014<'gc>(
activation: &mut Activation<'_, 'gc>,
class_name: AvmString<'gc>,
) -> Error<'gc> {
let err = verify_error(
activation,
&format!("Error #1014: Class {} could not be found.", class_name),
1014,
);

match err {
Ok(err) => Error::AvmError(err),
Err(err) => err,
}
}

#[inline(never)]
#[cold]
pub fn make_error_1021<'gc>(activation: &mut Activation<'_, 'gc>) -> Error<'gc> {
Expand Down
42 changes: 10 additions & 32 deletions core/src/avm2/verify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::avm2::class::Class;
use crate::avm2::error::{
make_error_1021, make_error_1025, make_error_1032, make_error_1054, make_error_1107,
verify_error,
make_error_1014, make_error_1021, make_error_1025, make_error_1032, make_error_1054,
make_error_1107, verify_error,
};
use crate::avm2::method::BytecodeMethod;
use crate::avm2::multiname::Multiname;
Expand Down Expand Up @@ -299,27 +299,16 @@ pub fn verify_method<'gc>(

if multiname.has_lazy_component() {
// This matches FP's error message
return Err(Error::AvmError(verify_error(
activation,
"Error #1014: Class [] could not be found.",
1014,
)?));
return Err(make_error_1014(activation, "[]".into()));
}

activation
.domain()
.get_class(&multiname, activation.context.gc_context)
.ok_or_else(|| {
Error::AvmError(
verify_error(
activation,
&format!(
"Error #1014: Class {} could not be found.",
multiname.to_qualified_name(activation.context.gc_context)
),
1014,
)
.expect("Error should construct"),
make_error_1014(
activation,
multiname.to_qualified_name(activation.context.gc_context),
)
})?;
}
Expand Down Expand Up @@ -419,27 +408,16 @@ pub fn verify_method<'gc>(

if pooled_type_name.has_lazy_component() {
// This matches FP's error message
return Err(Error::AvmError(verify_error(
activation,
"Error #1014: Class [] could not be found.",
1014,
)?));
return Err(make_error_1014(activation, "[]".into()));
}

let resolved_type = activation
.domain()
.get_class(&pooled_type_name, activation.context.gc_context)
.ok_or_else(|| {
Error::AvmError(
verify_error(
activation,
&format!(
"Error #1014: Class {} could not be found.",
pooled_type_name.to_qualified_name(activation.context.gc_context)
),
1014,
)
.expect("Error should construct"),
make_error_1014(
activation,
pooled_type_name.to_qualified_name(activation.context.gc_context),
)
})?;

Expand Down

0 comments on commit 788c3da

Please sign in to comment.