Example #1
0
		public void Visit(UnaryExpression expression)
		{
			switch (expression.Type)
			{
				case UnaryExpressionType.TypeOf:
					Builder.Append("typeof ");
					break;
				case UnaryExpressionType.New:
					Builder.Append("new ");
					break;
				case UnaryExpressionType.Not:
					Builder.Append("!");
					break;
				case UnaryExpressionType.Negate:
					Builder.Append("-");
					break;
				case UnaryExpressionType.Positive:
					Builder.Append("+");
					break;
				case UnaryExpressionType.PrefixPlusPlus:
					Builder.Append("++");
					break;
				case UnaryExpressionType.PrefixMinusMinus:
					Builder.Append("--");
					break;
				case UnaryExpressionType.Delete:
					Builder.Append("delete ");
					break;

			}
			expression.Expression.Accept(this);
			switch (expression.Type)
			{
				case UnaryExpressionType.PostfixPlusPlus:
					Builder.Append("++");
					break;
				case UnaryExpressionType.PostfixMinusMinus:
					Builder.Append("--");
					break;
				//case UnaryExpressionType.Void:
				//case UnaryExpressionType.Inv:
				//case UnaryExpressionType.Unknown:
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
Example #2
0
        public void Visit(UnaryExpression expression)
        {
            MemberExpression member;

            switch (expression.Type)
            {
                case UnaryExpressionType.TypeOf:

                    expression.Expression.Accept(this);
                    Result = Global.StringClass.New(Result.Class.ToLower());

                    break;

                case UnaryExpressionType.Not:
                    expression.Expression.Accept(this);
                    Result = Global.BooleanClass.New(!Result.ToBoolean());
                    break;

                case UnaryExpressionType.Negate:
                    expression.Expression.Accept(this);
                    Result = Global.NumberClass.New(-Result.ToNumber());
                    break;

                case UnaryExpressionType.Positive:
                    expression.Expression.Accept(this);
                    Result = Global.NumberClass.New(+Result.ToNumber());
                    break;

                case UnaryExpressionType.PostfixPlusPlus:

                    expression.Expression.Accept(this);
                    JsInstance temp = Result;

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);

                    Assign(member, Global.NumberClass.New(temp.ToNumber() + 1));

                    Result = temp;
                    break;

                case UnaryExpressionType.PostfixMinusMinus:

                    expression.Expression.Accept(this);
                    temp = Result;

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);

                    Assign(member, Global.NumberClass.New(temp.ToNumber() - 1));

                    Result = temp;
                    break;

                case UnaryExpressionType.PrefixPlusPlus:

                    expression.Expression.Accept(this);
                    temp = Global.NumberClass.New(Result.ToNumber() + 1);

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);
                    Assign(member, temp);

                    Result = temp;
                    break;

                case UnaryExpressionType.PrefixMinusMinus:

                    expression.Expression.Accept(this);
                    temp = Global.NumberClass.New(Result.ToNumber() - 1);

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);
                    Assign(member, temp);

                    Result = temp;
                    break;

                case UnaryExpressionType.Delete:

                    member = expression.Expression as MemberExpression;
                    if (member == null)
                        throw new NotImplementedException("delete");
                    member.Previous.Accept(this);
                    temp = Result;
                    string propertyName = null;
                    if (member.Member is PropertyExpression)
                        propertyName = ((PropertyExpression)member.Member).Text;
                    if (member.Member is Indexer)
                    {
                        ((Indexer)member.Member).Index.Accept(this);
                        propertyName = Result.ToString();
                    }
                    if (string.IsNullOrEmpty(propertyName))
                        throw new JsException(Global.TypeErrorClass.New());
                    try
                    {
                        ((JsDictionaryObject)temp).Delete(propertyName);
                    }
                    catch (JintException e)
                    {
                        throw new JsException(Global.TypeErrorClass.New());
                    }
                    Result = temp;
                    break;

                case UnaryExpressionType.Void:

                    throw new NotImplementedException("void");

                case UnaryExpressionType.Inv:

                    expression.Expression.Accept(this);
                    Result = Global.NumberClass.New(~Convert.ToUInt64(Result.ToNumber()));

                    break;

            }
        }
Example #3
0
        public void Visit(UnaryExpression expression)
        {
            MemberExpression member;

            switch (expression.Type) {
                case UnaryExpressionType.TypeOf:

                    expression.Expression.Accept(this);

                    if (Result == null)
                        Result = Global.StringClass.New(JsUndefined.Instance.Type);
                    else if (Result is JsNull)
                        Result = Global.StringClass.New(JsInstance.TYPE_OBJECT);
                    else if (Result is JsFunction)
                        Result = Global.StringClass.New(JsInstance.TYPEOF_FUNCTION);
                    else
                        Result = Global.StringClass.New(Result.Type);

                    break;

                case UnaryExpressionType.Not:
                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    Result = Global.BooleanClass.New(!Result.ToBoolean());
                    break;

                case UnaryExpressionType.Negate:
                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    Result = Global.NumberClass.New(-Result.ToNumber());
                    break;

                case UnaryExpressionType.Positive:
                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    Result = Global.NumberClass.New(+Result.ToNumber());
                    break;

                case UnaryExpressionType.PostfixPlusPlus:

                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    JsInstance value = Result;

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);

                    Assign(member, Global.NumberClass.New(value.ToNumber() + 1));

                    Result = value;

                    break;

                case UnaryExpressionType.PostfixMinusMinus:

                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    value = Result;

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);

                    Assign(member, Global.NumberClass.New(value.ToNumber() - 1));

                    Result = value;

                    break;

                case UnaryExpressionType.PrefixPlusPlus:

                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    value = Global.NumberClass.New(Result.ToNumber() + 1);

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);
                    Assign(member, value);

                    break;

                case UnaryExpressionType.PrefixMinusMinus:

                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    value = Global.NumberClass.New(Result.ToNumber() - 1);

                    member = expression.Expression as MemberExpression ?? new MemberExpression(expression.Expression, null);
                    Assign(member, value);

                    break;

                case UnaryExpressionType.Delete:

                    member = expression.Expression as MemberExpression;
                    if (member == null)
                        throw new NotImplementedException("delete");
                    member.Previous.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    value = Result;
                    string propertyName = null;
                    if (member.Member is PropertyExpression)
                        propertyName = ((PropertyExpression)member.Member).Text;
                    if (member.Member is Indexer) {
                        ((Indexer)member.Member).Index.Accept(this);
                        propertyName = Result.ToString();
                    }
                    if (string.IsNullOrEmpty(propertyName))
                        throw new JsException(Global.TypeErrorClass.New());
                    try {
                        ((JsDictionaryObject)value).Delete(propertyName);
                    }
                    catch (JintException) {
                        throw new JsException(Global.TypeErrorClass.New());
                    }
                    Result = value;
                    break;

                case UnaryExpressionType.Void:

                    expression.Expression.Accept(this);
                    Result = JsUndefined.Instance;
                    break;

                case UnaryExpressionType.Inv:

                    expression.Expression.Accept(this);
                    EnsureIdentifierIsDefined(Result);
                    Result = Global.NumberClass.New(0 - Result.ToNumber() - 1);
                    break;

            }
        }
Example #4
0
        void Analyze(UnaryExpression Stmt)
        {
            SetCurrentLineAndCharNos(Stmt);

            if (Stmt.Type == UnaryExpressionType.Not && Stmt.Expression == null)
            {
                if (JintStack.Count > 0)
                {
                    if (JintStack[JintStack.Count - 1].State == JintState.MethodCallArgument)
                    {
                        JintStack.Add(new JintItem(Stmt.Source, JintState.MethodCallArgumentTaintPointer, this));
                    }
                }
            }

            if (Stmt.Expression != null)
            {
                Analyze(Stmt.Expression);
            }
        }