public static FunctionObject FunctionCreate(FunctionCreateKind kind, FormalParameters parameters, FunctionStatementList body, LexicalEnvironment scope, bool strict, IValue?prototype = null) { if (prototype == null) { prototype = Interpreter.Instance().CurrentRealm().Intrinsics.FunctionPrototype; } var functionKind = kind == FunctionCreateKind.Normal ? FunctionKind.Normal : FunctionKind.NonConstructor; FunctionObject F = FunctionAllocate(prototype, strict, functionKind); return(FunctionInitialize(F, kind, parameters, body, scope)); }
public static FunctionObject FunctionInitialize(FunctionObject f, FunctionCreateKind kind, FormalParameters parameters, FunctionStatementList body, LexicalEnvironment scope) { var len = parameters.ExpectedArgumentCount(); f.DefinePropertyOrThrow("length", new PropertyDescriptor(new NumberValue(len), false, false, true)); f.Environment = scope; f.FormalParameters = parameters; f.Code = body; if (kind == FunctionCreateKind.Arrow) { f.ThisMode = ThisMode.Lexical; } else if (f.Strict) { f.ThisMode = ThisMode.Strict; } else { f.ThisMode = ThisMode.Global; } return(f); }