protected override ExpressionResult EvaluateInternal(EvaluationContext context)
        {
            var engine = context.Engine;
            var scope  = engine.ExecutionContext.LexicalEnvironment;

            var closure = new ScriptFunctionInstance(
                engine,
                _function,
                scope,
                FunctionThisMode.Lexical,
                proto: engine.Realm.Intrinsics.Function.PrototypeObject);

            if (_function.Name is null)
            {
                closure.SetFunctionName(JsString.Empty);
            }

            return(NormalCompletion(closure));
        }
        private object BuildObjectNormal()
        {
            var  obj = _engine.Object.Construct(_properties.Length);
            bool isStrictModeCode = _engine._isStrict || StrictModeScope.IsStrictModeCode;

            for (var i = 0; i < _properties.Length; i++)
            {
                var objectProperty = _properties[i];

                if (objectProperty is null)
                {
                    // spread
                    if (_valueExpressions[i].GetValue() is ObjectInstance source)
                    {
                        source.CopyDataProperties(obj, null);
                    }
                    continue;
                }

                var property = objectProperty._value;
                var propName = objectProperty.KeyJsString ?? property.GetKey(_engine);

                PropertyDescriptor propDesc;

                if (property.Kind == PropertyKind.Init || property.Kind == PropertyKind.Data)
                {
                    var expr      = _valueExpressions[i];
                    var propValue = expr.GetValue().Clone();
                    if (expr._expression.IsFunctionWithName())
                    {
                        var functionInstance = (FunctionInstance)propValue;
                        functionInstance.SetFunctionName(propName);
                    }
                    propDesc = new PropertyDescriptor(propValue, PropertyFlag.ConfigurableEnumerableWritable);
                }
                else if (property.Kind == PropertyKind.Get || property.Kind == PropertyKind.Set)
                {
                    var function = property.Value as IFunction ?? ExceptionHelper.ThrowSyntaxError <IFunction>(_engine);

                    var functionInstance = new ScriptFunctionInstance(
                        _engine,
                        function,
                        _engine.ExecutionContext.LexicalEnvironment,
                        isStrictModeCode
                        );
                    functionInstance.SetFunctionName(propName);
                    functionInstance._prototypeDescriptor = null;

                    propDesc = new GetSetPropertyDescriptor(
                        get: property.Kind == PropertyKind.Get ? functionInstance : null,
                        set: property.Kind == PropertyKind.Set ? functionInstance : null,
                        PropertyFlag.Enumerable | PropertyFlag.Configurable);
                }
                else
                {
                    return(ExceptionHelper.ThrowArgumentOutOfRangeException <object>());
                }

                obj.DefineOwnProperty(propName, propDesc);
            }

            return(obj);
        }