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);
            }
Esempio n. 2
0
 public JintCallExpression(Engine engine, CallExpression expression) : base(engine, expression)
 {
     _initialized       = false;
     _isDebugMode       = engine.Options.IsDebugMode;
     _maxRecursionDepth = engine.Options.MaxRecursionDepth;
     _calleeExpression  = Build(engine, expression.Callee);
 }
Esempio n. 3
0
        protected override void Initialize(EvaluationContext context)
        {
            var expression = (BinaryExpression)_expression;

            _left  = Build(context.Engine, expression.Left);
            _right = Build(context.Engine, expression.Right);
        }
Esempio n. 4
0
        protected override void Initialize(EvaluationContext context)
        {
            var engine = context.Engine;

            _tagIdentifier = Build(engine, _taggedTemplateExpression.Tag);
            _quasi         = new JintTemplateLiteralExpression(_taggedTemplateExpression.Quasi);
            _quasi.DoInitialize(context);
        }
Esempio n. 5
0
        protected override void Initialize(EvaluationContext context)
        {
            var engine     = context.Engine;
            var expression = (CallExpression)_expression;

            _calleeExpression = Build(engine, expression.Callee);
            var cachedArgumentsHolder = new CachedArgumentsHolder
            {
                JintArguments = new JintExpression[expression.Arguments.Count]
            };
            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);
            }
        private JsValue NamedEvaluation(EvaluationContext context, JintExpression expression)
        {
            var rval = expression.GetValue(context).Value;

            if (expression._expression.IsAnonymousFunctionDefinition() && _left._expression.Type == Nodes.Identifier)
            {
                ((FunctionInstance)rval).SetFunctionName(((Identifier)_left._expression).Name);
            }

            return(rval);
        }
Esempio n. 8
0
        public NullishCoalescingExpression(Engine engine, BinaryExpression expression) : base(expression)
        {
            _left = Build(engine, expression.Left);

            // we can create a fast path for common literal case like variable ?? 0
            if (expression.Right is Literal l)
            {
                _constant = JintLiteralExpression.ConvertToJsValue(l);
            }
            else
            {
                _right = Build(engine, expression.Right);
            }
        }
        protected override void Initialize()
        {
            var expression = (NewExpression)_expression;

            _calleeExpression = Build(_engine, expression.Callee);

            if (expression.Arguments.Count <= 0)
            {
                return;
            }

            _jintArguments = new JintExpression[expression.Arguments.Count];
            for (var i = 0; i < _jintArguments.Length; i++)
            {
                var argument = expression.Arguments[i];
                _jintArguments[i] = Build(_engine, argument);
                _hasSpreads      |= argument.Type == Nodes.SpreadElement;
            }
        }
Esempio n. 10
0
        protected override void Initialize(EvaluationContext context)
        {
            _memberExpression = (MemberExpression)_expression;
            _objectExpression = Build(context.Engine, _memberExpression.Object);

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

            if (_determinedProperty is null)
            {
                _propertyExpression = Build(context.Engine, _memberExpression.Property);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
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);
            }
Esempio n. 13
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;
        }
Esempio n. 14
0
 public JintLogicalAndExpression(Engine engine, BinaryExpression expression) : base(engine, expression)
 {
     _left  = Build(engine, expression.Left);
     _right = Build(engine, expression.Right);
 }
Esempio n. 15
0
 public JintConditionalExpression(Engine engine, ConditionalExpression expression) : base(expression)
 {
     _test       = Build(engine, expression.Test);
     _consequent = Build(engine, expression.Consequent);
     _alternate  = Build(engine, expression.Alternate);
 }
 private JintUnaryExpression(Engine engine, UnaryExpression expression) : base(engine, expression)
 {
     _argument = Build(engine, expression.Argument);
     _operator = expression.Operator;
 }
Esempio n. 17
0
 protected override void Initialize(EvaluationContext context)
 {
     _right = Build(context.Engine, ((AssignmentExpression)_expression).Right);
 }
Esempio n. 18
0
 private JintBinaryExpression(Engine engine, BinaryExpression expression) : base(engine, expression)
 {
     _left         = Build(engine, expression.Left);
     _right        = Build(engine, expression.Right);
     _operatorType = expression.Operator;
 }
 protected override void Initialize()
 {
     _tagIdentifier = Build(_engine, _taggedTemplateExpression.Tag);
     _quasi         = (JintTemplateLiteralExpression)Build(_engine, _taggedTemplateExpression.Quasi);
     _quasi.DoInitialize();
 }
Esempio n. 20
0
 protected override void Initialize()
 {
     _right = Build(_engine, ((AssignmentExpression)_expression).Right);
 }
 private JintAssignmentExpression(Engine engine, AssignmentExpression expression) : base(engine, expression)
 {
     _left     = Build(engine, expression.Left);
     _right    = Build(engine, expression.Right);
     _operator = expression.Operator;
 }
Esempio n. 22
0
 public JintSpreadExpression(Engine engine, SpreadElement expression) : base(expression)
 {
     _argument     = Build(engine, expression.Argument);
     _argumentName = (expression.Argument as Identifier)?.Name;
 }