diff --git a/core/src/avm1/globals.rs b/core/src/avm1/globals.rs index 8bd4a987f..cff7b4e55 100644 --- a/core/src/avm1/globals.rs +++ b/core/src/avm1/globals.rs @@ -438,8 +438,9 @@ pub fn create_globals<'gc>( Some(function_proto), error_proto, ); - let function = FunctionObject::constructor( + let function = FunctionObject::function_and_constructor( gc_context, + Executable::Native(function::function), Executable::Native(function::constructor), Some(function_proto), function_proto, diff --git a/core/src/avm1/globals/function.rs b/core/src/avm1/globals/function.rs index 308ee71dc..9882645c0 100644 --- a/core/src/avm1/globals/function.rs +++ b/core/src/avm1/globals/function.rs @@ -7,7 +7,7 @@ use crate::avm1::{Object, ScriptObject, TObject, Value}; use enumset::EnumSet; use gc_arena::MutationContext; -/// Implements `Function` +/// Implements `new Function()` pub fn constructor<'gc>( _activation: &mut Activation<'_, 'gc, '_>, _this: Object<'gc>, @@ -16,6 +16,20 @@ pub fn constructor<'gc>( Ok(Value::Undefined) } +/// Implements `Function()` +pub fn function<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + _this: Object<'gc>, + args: &[Value<'gc>], +) -> Result, 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` pub fn call<'gc>( activation: &mut Activation<'_, 'gc, '_>,