internal static JsValue AssignToIdentifier(
                Engine engine,
                JintIdentifierExpression left,
                JintExpression right,
                bool hasEvalOrArguments)
            {
                var env    = engine.ExecutionContext.LexicalEnvironment;
                var strict = StrictModeScope.IsStrictModeCode;

                if (LexicalEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
                        env,
                        left._expressionName,
                        strict,
                        out var environmentRecord,
                        out _))
                {
                    if (strict && hasEvalOrArguments)
                    {
                        ExceptionHelper.ThrowSyntaxError(engine);
                    }

                    var rval = right.GetValue().Clone();

                    if (right._expression.IsFunctionWithName())
                    {
                        ((FunctionInstance)rval).SetFunctionName(left._expressionName.StringValue);
                    }

                    environmentRecord.SetMutableBinding(left._expressionName, rval, strict);
                    return(rval);
                }

                return(null);
            }
            protected override void Initialize()
            {
                var assignmentExpression = ((AssignmentExpression)_expression);

                _left            = Build(_engine, assignmentExpression.Left);
                _leftIdentifier  = _left as JintIdentifierExpression;
                _evalOrArguments = _leftIdentifier?.HasEvalOrArguments == true;

                _right = Build(_engine, assignmentExpression.Right);
            }
예제 #3
0
        protected override void Initialize()
        {
            var expression = (MemberExpression)_expression;

            _objectExpression           = Build(_engine, expression.Object);
            _objectIdentifierExpression = _objectExpression as JintIdentifierExpression;
            _objectThisExpression       = _objectExpression as JintThisExpression;

            if (!expression.Computed)
            {
                _determinedProperty = ((Identifier)expression.Property).Name;
            }
            else if (expression.Property.Type == Nodes.Literal)
            {
                _determinedProperty = JintLiteralExpression.ConvertToJsValue((Literal)expression.Property);
            }

            if (_determinedProperty is null)
            {
                _propertyExpression = Build(_engine, expression.Property);
            }
        }
예제 #4
0
        protected override void Initialize()
        {
            var expression = (UpdateExpression)_expression;

            _prefix   = expression.Prefix;
            _argument = Build(_engine, expression.Argument);
            if (expression.Operator == UnaryOperator.Increment)
            {
                _change = 1;
            }
            else if (expression.Operator == UnaryOperator.Decrement)
            {
                _change = -1;
            }
            else
            {
                ExceptionHelper.ThrowArgumentException();
            }

            _leftIdentifier  = _argument as JintIdentifierExpression;
            _evalOrArguments = _leftIdentifier?.HasEvalOrArguments == true;
        }
예제 #5
0
            internal static ExpressionResult?AssignToIdentifier(
                EvaluationContext context,
                JintIdentifierExpression left,
                JintExpression right,
                bool hasEvalOrArguments)
            {
                var engine = context.Engine;
                var env    = engine.ExecutionContext.LexicalEnvironment;
                var strict = StrictModeScope.IsStrictModeCode;

                if (JintEnvironment.TryGetIdentifierEnvironmentWithBinding(
                        env,
                        left._expressionName,
                        out var environmentRecord))
                {
                    if (strict && hasEvalOrArguments)
                    {
                        ExceptionHelper.ThrowSyntaxError(engine.Realm);
                    }

                    var completion = right.GetValue(context);
                    if (completion.IsAbrupt())
                    {
                        return(completion);
                    }

                    var rval = completion.Value.Clone();

                    if (right._expression.IsFunctionDefinition())
                    {
                        ((FunctionInstance)rval).SetFunctionName(left._expressionName.StringValue);
                    }

                    environmentRecord.SetMutableBinding(left._expressionName, rval, strict);
                    return(new Completion(CompletionType.Normal, rval, default));
                }

                return(null);
            }