avm1: Push Undefined when trying to construct invalid object

This commit is contained in:
Mike Welsh 2019-12-18 13:34:19 -08:00
parent bb6a4c119c
commit 9079b69991
1 changed files with 32 additions and 19 deletions

View File

@ -1682,27 +1682,40 @@ impl<'gc> Avm1<'gc> {
args.push(self.pop()?);
}
let constructor = self
let mut ret = Value::Undefined;
if let Ok(fn_name) = fn_name.as_string() {
if let Ok(constructor) = self
.stack_frames
.last()
.unwrap()
.clone()
.read()
.resolve(fn_name.as_string()?, self, context)?
.resolve(fn_name, self, context)?
.resolve(self, context)?
.as_object()?;
let prototype = constructor
.as_object()
{
if let Ok(prototype) = constructor
.get("prototype", self, context)?
.resolve(self, context)?
.as_object()?;
.as_object()
{
let this = prototype.new(self, context, prototype, &args)?;
constructor
.call(self, context, this, &args)?
.resolve(self, context)?;
ret = this.into();
} else {
log::warn!("NewObject: Constructor has invalid prototype: {}", fn_name);
}
} else {
log::warn!("NewObject: Object is not a function: {}", fn_name);
}
} else {
log::warn!("NewObject: Expected String for object name: {:?}", fn_name);
}
self.push(this);
self.push(ret);
Ok(())
}