avm1: Fix calling Function() as a function - fixes #1074
This commit is contained in:
parent
40cdb84656
commit
bcb64b9a62
|
@ -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,
|
||||
|
|
|
@ -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<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`
|
||||
pub fn call<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
|
|
Loading…
Reference in New Issue