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);
            }
Exemple #2
0
        private JsValue UpdateIdentifier()
        {
            var strict = StrictModeScope.IsStrictModeCode;
            var name   = _leftIdentifier._expressionName;
            var env    = _engine.ExecutionContext.LexicalEnvironment;

            if (LexicalEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
                    env,
                    name,
                    strict,
                    out var environmentRecord,
                    out var value))
            {
                if (strict && _evalOrArguments)
                {
                    ExceptionHelper.ThrowSyntaxError(_engine);
                }

                var isInteger = value._type == InternalTypes.Integer;
                var newValue  = isInteger
                    ? JsNumber.Create(value.AsInteger() + _change)
                    : JsNumber.Create(TypeConverter.ToNumber(value) + _change);

                environmentRecord.SetMutableBinding(name.Key.Name, newValue, strict);
                return(_prefix
                    ? newValue
                    : (isInteger ? value : JsNumber.Create(TypeConverter.ToNumber(value))));
            }

            return(null);
        }
Exemple #3
0
        protected override object EvaluateInternal()
        {
            var env    = _engine.ExecutionContext.LexicalEnvironment;
            var strict = StrictModeScope.IsStrictModeCode;
            var identifierEnvironment = LexicalEnvironment.TryGetIdentifierEnvironmentWithBindingValue(env, _expressionName, strict, out var temp, out _)
                ? temp
                : JsValue.Undefined;

            return(_engine._referencePool.Rent(identifierEnvironment, _expressionName.StringValue, strict));
        }
Exemple #4
0
        protected override object EvaluateInternal()
        {
            string  baseReferenceName = null;
            JsValue baseValue         = null;
            var     isStrictModeCode  = StrictModeScope.IsStrictModeCode;

            if (_objectIdentifierExpression != null)
            {
                baseReferenceName = _objectIdentifierExpression._expressionName.Key.Name;
                var strict = isStrictModeCode;
                var env    = _engine.ExecutionContext.LexicalEnvironment;
                LexicalEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
                    env,
                    _objectIdentifierExpression._expressionName,
                    strict,
                    out _,
                    out baseValue);
            }
            else if (_objectThisExpression != null)
            {
                baseValue = _objectThisExpression.GetValue();
            }

            if (baseValue is null)
            {
                // fast checks failed
                var baseReference = _objectExpression.Evaluate();
                if (baseReference is Reference reference)
                {
                    baseReferenceName = reference.GetReferencedName().ToString();
                    baseValue         = _engine.GetValue(reference, false);
                    _engine._referencePool.Return(reference);
                }
                else
                {
                    baseValue = _engine.GetValue(baseReference, false);
                }
            }

            var property = _determinedProperty ?? _propertyExpression.GetValue();

            TypeConverter.CheckObjectCoercible(_engine, baseValue, (MemberExpression)_expression, baseReferenceName);
            return(_engine._referencePool.Rent(baseValue, TypeConverter.ToPropertyKey(property), isStrictModeCode));
        }
Exemple #5
0
        public override JsValue GetValue()
        {
            // need to notify correct node when taking shortcut
            _engine._lastSyntaxNode = _expression;

            if (!(_calculatedValue is null))
            {
                return(_calculatedValue);
            }

            var strict = StrictModeScope.IsStrictModeCode;
            var env    = _engine.ExecutionContext.LexicalEnvironment;

            return(LexicalEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
                       env,
                       _expressionName,
                       strict,
                       out _,
                       out var value)
                ? value ?? ExceptionHelper.ThrowReferenceError <JsValue>(_engine, _expressionName.Key.Name + " has not been initialized")
                : _engine.GetValue(_engine._referencePool.Rent(JsValue.Undefined, _expressionName.StringValue, strict), true));
        }