avm1: Fix calling Function() as a function - fixes #1074

This commit is contained in:
Nathan Adams 2020-09-03 23:21:54 +02:00 committed by Mike Welsh
parent 40cdb84656
commit bcb64b9a62
2 changed files with 17 additions and 2 deletions

View File

@ -438,8 +438,9 @@ pub fn create_globals<'gc>(
Some(function_proto), Some(function_proto),
error_proto, error_proto,
); );
let function = FunctionObject::constructor( let function = FunctionObject::function_and_constructor(
gc_context, gc_context,
Executable::Native(function::function),
Executable::Native(function::constructor), Executable::Native(function::constructor),
Some(function_proto), Some(function_proto),
function_proto, function_proto,

View File

@ -7,7 +7,7 @@ use crate::avm1::{Object, ScriptObject, TObject, Value};
use enumset::EnumSet; use enumset::EnumSet;
use gc_arena::MutationContext; use gc_arena::MutationContext;
/// Implements `Function` /// Implements `new Function()`
pub fn constructor<'gc>( pub fn constructor<'gc>(
_activation: &mut Activation<'_, 'gc, '_>, _activation: &mut Activation<'_, 'gc, '_>,
_this: Object<'gc>, _this: Object<'gc>,
@ -16,6 +16,20 @@ pub fn constructor<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements `Function()`
pub fn function<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
_this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(arg) = args.get(0) {
Ok(arg.to_owned())
} else {
// Calling `Function()` seems to give a prototypeless bare object.
Ok(ScriptObject::object(activation.context.gc_context, None).into())
}
}
/// Implements `Function.prototype.call` /// Implements `Function.prototype.call`
pub fn call<'gc>( pub fn call<'gc>(
activation: &mut Activation<'_, 'gc, '_>, activation: &mut Activation<'_, 'gc, '_>,