chore: Raise errors during Object.registerClass

This commit is contained in:
Nathan Adams 2020-02-29 23:13:02 +01:00
parent 7bed4d4940
commit 751b15beec
1 changed files with 4 additions and 6 deletions

View File

@ -138,17 +138,15 @@ pub fn register_class<'gc>(
_this: Object<'gc>, _this: Object<'gc>,
args: &[Value<'gc>], args: &[Value<'gc>],
) -> Result<ReturnValue<'gc>, Error> { ) -> Result<ReturnValue<'gc>, Error> {
if let Some(class_name) = args if let Some(class_name) = args.get(0).cloned() {
.get(0) let class_name = class_name.coerce_to_string(avm, context)?;
.and_then(|v| v.clone().coerce_to_string(avm, context).ok())
{
if let Some(Character::MovieClip(movie_clip)) = context if let Some(Character::MovieClip(movie_clip)) = context
.library .library
.library_for_movie_mut(context.swf.clone()) .library_for_movie_mut(context.swf.clone())
.get_character_by_export_name(&class_name) .get_character_by_export_name(&class_name)
{ {
if let Some(constructor) = args.get(1).and_then(|v| v.as_object().ok()) { if let Some(constructor) = args.get(1) {
movie_clip.set_avm1_constructor(context.gc_context, Some(constructor)); movie_clip.set_avm1_constructor(context.gc_context, Some(constructor.as_object()?));
} else { } else {
movie_clip.set_avm1_constructor(context.gc_context, None); movie_clip.set_avm1_constructor(context.gc_context, None);
} }