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()?); 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 .stack_frames
.last() .last()
.unwrap() .unwrap()
.clone() .clone()
.read() .read()
.resolve(fn_name.as_string()?, self, context)? .resolve(fn_name, self, context)?
.resolve(self, context)? .resolve(self, context)?
.as_object()?; .as_object()
let prototype = constructor {
if let Ok(prototype) = constructor
.get("prototype", self, context)? .get("prototype", self, context)?
.resolve(self, context)? .resolve(self, context)?
.as_object()?; .as_object()
{
let this = prototype.new(self, context, prototype, &args)?; let this = prototype.new(self, context, prototype, &args)?;
constructor constructor
.call(self, context, this, &args)? .call(self, context, this, &args)?
.resolve(self, context)?; .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(()) Ok(())
} }