Skip to content

Commit e1b2471

Browse files
committed
avm2: Throw AVM error on calling undefined function
1 parent 2ced2d2 commit e1b2471

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

core/src/avm2/value.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -909,34 +909,27 @@ impl<'gc> Value<'gc> {
909909
name: Option<&Multiname<'gc>>,
910910
receiver: Option<Object<'gc>>,
911911
) -> Result<Object<'gc>, Error<'gc>> {
912-
self.as_object()
913-
.filter(|o| o.as_class_object().is_some() || o.as_executable().is_some())
914-
.ok_or_else(|| {
915-
if let Some(receiver) = receiver {
916-
if let Some(name) = name {
917-
format!(
918-
"Cannot call null or undefined method {} of class {}",
919-
name.to_qualified_name(activation.context.gc_context),
920-
receiver.instance_of_class_name(activation.context.gc_context)
921-
)
922-
.into()
923-
} else {
924-
format!(
925-
"Cannot call null or undefined method of class {}",
926-
receiver.instance_of_class_name(activation.context.gc_context)
927-
)
928-
.into()
929-
}
930-
} else if let Some(name) = name {
912+
match self.as_object() {
913+
Some(o) if o.as_class_object().is_some() || o.as_executable().is_some() => Ok(o),
914+
_ => {
915+
// Undefined function
916+
let name = if let Some(name) = name {
917+
name.to_qualified_name(activation.context.gc_context)
918+
} else {
919+
"value".into()
920+
};
921+
let msg = if let Some(receiver) = receiver {
931922
format!(
932-
"Cannot call null or undefined function {}",
933-
name.to_qualified_name(activation.context.gc_context)
923+
"Error #1006: {} is not a function of class {}.",
924+
name,
925+
receiver.instance_of_class_name(activation.context.gc_context)
934926
)
935-
.into()
936927
} else {
937-
"Cannot call null or undefined function".into()
938-
}
939-
})
928+
format!("Error #1006: {} is not a function.", name)
929+
};
930+
Err(Error::AvmError(type_error(activation, &msg, 1006)?))
931+
}
932+
}
940933
}
941934

942935
/// Like `coerce_to_type`, but also performs resolution of the type name.

0 commit comments

Comments
 (0)