상속: AST
예제 #1
0
        private void ParseAst(JS.AST ast, string sp)
        {
            if (ast == null)
            {
                return;
            }
            if (CheckWorker())
            {
                return;
            }

            //_logView.LogStr("JSM->" + sp + ast.ToString() + "\t\t" + ast.GetType().Name);

            if (ast is JS.FunctionDeclaration)
            {
                JS.Function func = ast as JS.Function;
                ParseAstList(func.func_obj.body.elems, sp + "  ");
            }
            else if (ast is JS.Assign)
            {
                JS.Assign ass = ast as JS.Assign;

                ParseAst(ass.left, sp + "l ");
                ParseAst(ass.right, sp + "r ");
            }
            else if (ast is JS.Binary)
            {
                JS.Binary bin = ast as JS.Binary;

                string[] parts = bin.ToString().Split('.');
                if (parts.Length > 1)
                {
                    if (parts[parts.Length - 2] == "This")
                    {
                        string calledId = parts[parts.Length - 1] + "()";

                        //dup
                        // If we have a method of this name in this file/class
                        if (_addedNodes.ContainsKey(calledId))
                        {
                            // Create an edge.
                            // A definite functional assignment link.
                            AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Aqua);
                        }
                        else
                        {
                            // It's a call to a method outside this class/file.
                            //
                            //_logView.LogStr("skipped assign ref -->" + _methodNodeId + " --------> " + calledId);
                            //
                        }
                    }
                    else if (parts[parts.Length - 2] == "self")
                    {
                        string calledId = parts[parts.Length - 1] + "()";

                        //dup
                        // If we have a method of this name in this file/class
                        if (_addedNodes.ContainsKey(calledId))
                        {
                            // Get the graph node that we're linking to.
                            //Node calledNode = _addedNodes[calledId];

                            // Create an edge.
                            // A definite functional assignment link.
                            AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Aqua);
                        }
                        else
                        {
                            // It's a call to a method outside this class/file.
                            _logView.LogStr("skipped assign ref -->" + _methodNodeId + " --------> " + calledId);
                        }
                    }
                }
            }
            else if (ast is JS.Expression)
            {
                JS.Expression expr = ast as JS.Expression;
                ParseAstList(expr.exprs, sp + "  ");
            }
            else if (ast is JS.FunctionExpression)
            {
                JS.FunctionExpression expr = ast as JS.FunctionExpression;
                ParseAstList(expr.func_obj.body.elems, sp + "  ");
            }
            else if (ast is JS.For)
            {
                JS.For fr = ast as JS.For;
                ParseAst(fr.stms, sp + "  ");
            }
            else if (ast is JS.If)
            {
                JS.If iff = ast as JS.If;
                ParseAst(iff.false_stm, sp + "f  ");
                ParseAst(iff.true_stm, sp + "t  ");
            }
            else if (ast is JS.Block)
            {
                JS.Block block = ast as JS.Block;
                ParseAstList(block.elems, sp + "  ");
            }
            else if (ast is JS.VariableStatement)
            {
                JS.VariableStatement var = ast as JS.VariableStatement;
                //var.
                ParseAstList(var.var_decls, sp + "  ");
            }
            else if (ast is JS.Return)
            {
                JS.Return ret = ast as JS.Return;

                ParseAst(ret.expression, sp + "  ");
            }
            else if (ast is JS.VariableDeclaration)
            {
                JS.VariableDeclaration var = ast as JS.VariableDeclaration;

                Microsoft.JScript.New newval = var.val as Microsoft.JScript.New;

                if (newval != null && newval.exp != null)
                {
                    //_logView.LogStr("new:" + newval.exp.ToString());
                    string[] parts = newval.exp.ToString().Split('.');
                    if (parts.Length > 0)
                    {
                        string calledId = parts[parts.Length - 1] + "()";

                        // If we have a method of this name in this file/class, then
                        // we have a possible constructor link.
                        if (_addedNodes.ContainsKey(calledId))
                        {
                            // Create an edge.
                            AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Green);
                        }
                    }
                }
                else
                {
                    if (var.val != null)
                    {
                        string   valStr = var.val.ToString();
                        string[] parts  = valStr.Split('.');

                        if (parts.Length > 1 && parts[0] == "self")
                        {
                            // dup..

                            string calledId = parts[parts.Length - 1] + "()";

                            // If we have a method of this name in this file/class, then
                            // we have a possible constructor link.
                            if (_addedNodes.ContainsKey(calledId))
                            {
                                // Create an edge.
                                AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Green);
                            }
                        }
                    }
                }

                //ParseAstList(var.var_decls, sp + "  ");
            }
            else if (ast is JS.Call)
            {
                JS.Call  call     = ast as JS.Call;
                string[] parts    = call.ToString().Split(' ');
                string[] bits     = parts[0].Split('.');
                string   calledId = bits[bits.Length - 1] + "()";

                bool methodInThisClass = true;
                if (bits.Length > 1)
                {
                    if ((bits[bits.Length - 2] != "This") &&
                        (bits[bits.Length - 2] != "self"))
                    {
                        methodInThisClass = false;
                    }
                }

                // If we have a method of this name in this file/class
                if (_addedNodes.ContainsKey(calledId))
                {
                    // Create an edge.
                    if (methodInThisClass)
                    {
                        // A definite link.
                        AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Black);
                    }
                    else
                    {
                        // A tentative link.
                        AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Gray);
                    }
                }
                else
                {
                    // It's a call to a method outside this class/file.
                    //
                    //_logView.LogStr("skipped -------->" + _methodNodeId + " --------> " + parts[0]);
                    //
                }
            }
        }
예제 #2
0
        AST Function(AST parent, FunctionType ft)
        {
            FunctionType synthetic_type = ft;
            string name;
            AST member_expr = null;

            if (ts.MatchToken (Token.NAME)) {
                name = ts.GetString;
                if (!ts.MatchToken (Token.LP)) {
                    if (allow_member_expr_as_function_name) {
                        // Extension to ECMA: if 'function <name>' does not follow
                        // by '(', assume <name> starts memberExpr
                        // FIXME: is StringLiteral the correct AST to build?
                        decompiler.AddName (name);
                        AST member_expr_head = new StringLiteral (null, name,
                                      new Location (ts.SourceName, ts.LineNumber));
                        name = "";
                        member_expr = MemberExprTail (parent, false, member_expr_head);
                    }
                    MustMatchToken (Token.LP, "msg.no.paren.parms");
                }
            } else if (ts.MatchToken (Token.LP)) {
                // Anonymous function
                name = "";
            } else {
                name = "";
                if (allow_member_expr_as_function_name) {
                    // Note that memberExpr can not start with '(' like
                    // in function (1+2).toString(), because 'function (' already
                    // processed as anonymous function
                    member_expr = MemberExpr (parent, false);
                }
                MustMatchToken (Token.LP, "msg.no.paren.parms");
            }

            if (member_expr != null) {
                synthetic_type = FunctionType.Expression;
                decompiler.AddToken (Token.ASSIGN);
            }

            bool nested = InsideFunction;
            Function fn = CreateFunction (parent, synthetic_type, name);

            if (nested)
                fn.CheckThis = true;

            if (nested || nesting_of_with > 0) {
                // 1. Nested functions are not affected by the dynamic scope flag
                // as dynamic scope is already a parent of their scope.
                // 2. Functions defined under the with statement also immune to
                // this setup, in which case dynamic scope is ignored in favor
                // of with object.
                fn.IgnoreDynamicScope = true;
            }

            // FIXME: which is old version of Decompiler.MarkFunctionStart
            int functionSourceStart = decompiler.MarkFunctionStart ((int) synthetic_type);

            if (name != "")
                decompiler.AddName (name);

            int saved_nesting_of_with = nesting_of_with;
            nesting_of_with = 0;

            FormalParameterList _params = new FormalParameterList (new Location (ts.SourceName, ts.LineNumber));
            Block body;

            try {
                decompiler.AddToken (Token.LP);
                if (!ts.MatchToken (Token.RP)) {
                    bool first = true;
                    do {
                        if (!first)
                            decompiler.AddToken (Token.COMMA);
                        first = false;
                        MustMatchToken (Token.NAME, "msg.no.parm");
                        string s = ts.GetString;
                        _params.Add (s, String.Empty, new Location (ts.SourceName, ts.LineNumber));
                        decompiler.AddName (s);
                    } while (ts.MatchToken (Token.COMMA));
                    MustMatchToken (Token.RP, "msg.no.paren.after.parms");
                }
                decompiler.AddToken (Token.RP);

                MustMatchToken (Token.LC, "msg.no.brace.body");
                decompiler.AddEOL (Token.LC);
                body = ParseFunctionBody (fn);
                MustMatchToken (Token.RC, "msg.no.brace.after.body");

                decompiler.AddToken (Token.RC);
                decompiler.MarkFunctionEnd (functionSourceStart);

                fn.func_obj.source = decompiler.SourceToString (functionSourceStart);

                if (ft != FunctionType.Expression) {
                    CheckWellTerminatedFunction ();
                    if (member_expr == null)
                        decompiler.AddToken (Token.EOL);
                    else
                        decompiler.AddEOL (Token.SEMI);
                }
            } finally {
                nesting_of_with = saved_nesting_of_with;
            }

            fn.Init (body, _params);
            AST pn;

            if (member_expr == null) {
                // FIXME
                pn = fn;

                // FIXME, research about createExprStatementNoReturn
                if (ft == FunctionType.ExpressionStatement)
                    pn = null;
            } else {
                // FIXME
                pn = fn;
                Assign assign = new Assign (null, JSToken.Assign, new Location (ts.SourceName, ts.LineNumber));
                assign.Init (member_expr, pn, false);
                pn = assign;

            #if false
                // FIXME, research about createExprStatement
                if (ft != FunctionType.Expression)
                    ;
            #endif
            }
            return pn;
        }
예제 #3
0
        AST AssignExpr(AST parent, bool in_for_init)
        {
            AST pn = CondExpr (parent, in_for_init);
            int tt = ts.PeekToken ();

            // omitted: "invalid assignment left-hand side" check.
            if (tt == Token.ASSIGN) {
                ts.GetToken ();
                decompiler.AddToken (Token.ASSIGN);
                Assign assign = new Assign (parent, JSToken.Assign, new Location (ts.SourceName, ts.LineNumber));
                assign.Init (pn, AssignExpr (assign, in_for_init), false);
                pn = assign;
                return pn;
            } else if (tt == Token.ASSIGNOP) {
                ts.GetToken ();
                int op = ts.GetOp ();
                decompiler.AddAssignOp (op);
                Assign assign = new Assign (parent, ToJSToken (op, tt), new Location (ts.SourceName, ts.LineNumber));
                assign.Init (pn, AssignExpr (assign, in_for_init), false);
                pn = assign;
            }
            return pn;
        }
예제 #4
0
        private void AddMethod(string className, string methodName, Assign ass)
        {
            JSClassItem classItem = _classLookup[className] as JSClassItem;
            if (classItem == null)
            {
                // We haven't defined this type yet, do so here.
                classItem = new JSClassItem(className, className, _fileItem);
                //classItem.Icon = Properties.Resources.JSClassItem;
                _fileItem.Classes.Add(classItem);

                _classLookup.Add(className, classItem);
                _projectBrowser.AddLookup(classItem, classItem.GetID(), _invert);
            }

            // TODO methods need parent method ids in their ids, e.g. Hierarchy.js is breaking

            JSMethodItem methodItem = new JSMethodItem(methodName + "()", classItem);
            //methodItem.Icon = Properties.Resources.JSMethodItem;
            methodItem.MethodInfo = ass.right;
            classItem.Methods.Add(methodItem);
            _projectBrowser.AddLookup(methodItem, methodItem.GetID(), _invert);
        }
        internal override AST PartiallyEvaluate()
        {
            this.ctor = this.ctor.PartiallyEvaluateAsCallable();
            ASTList args  = new ASTList(this.args.context);
            ASTList list2 = new ASTList(this.args.context);
            int     num   = 0;
            int     count = this.args.count;

            while (num < count)
            {
                AST    ast  = this.args[num];
                Assign elem = ast as Assign;
                if (elem != null)
                {
                    elem.rhside = elem.rhside.PartiallyEvaluate();
                    list2.Append(elem);
                }
                else
                {
                    args.Append(ast.PartiallyEvaluate());
                }
                num++;
            }
            int num3 = args.count;

            IReflect[] argIRs = new IReflect[num3];
            for (int i = 0; i < num3; i++)
            {
                AST ast2 = args[i];
                if (ast2 is ConstantWrapper)
                {
                    object argument = ast2.Evaluate();
                    if ((argIRs[i] = TypeOfArgument(argument)) == null)
                    {
                        goto Label_0120;
                    }
                    this.positionalArgValues.Add(argument);
                    continue;
                }
                if ((ast2 is ArrayLiteral) && ((ArrayLiteral)ast2).IsOkToUseInCustomAttribute())
                {
                    argIRs[i] = Typeob.ArrayObject;
                    this.positionalArgValues.Add(ast2.Evaluate());
                    continue;
                }
Label_0120:
                ast2.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);
            }
            this.type = this.ctor.ResolveCustomAttribute(args, argIRs, this.target);
            if (this.type == null)
            {
                return(null);
            }
            if (Microsoft.JScript.Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute))
            {
                base.context.HandleError(JSError.CannotUseStaticSecurityAttribute);
                return(null);
            }
            ParameterInfo[] parameters = ((ConstructorInfo)((Binding)this.ctor).member).GetParameters();
            int             num5       = 0;
            int             num6       = this.positionalArgValues.Count;

            foreach (ParameterInfo info2 in parameters)
            {
                IReflect reflect = (info2 is ParameterDeclaration) ? ((ParameterDeclaration)info2).ParameterIReflect : info2.ParameterType;
                if (num5 < num6)
                {
                    object obj3 = this.positionalArgValues[num5];
                    this.positionalArgValues[num5] = Microsoft.JScript.Convert.Coerce(obj3, reflect, obj3 is ArrayObject);
                    num5++;
                }
                else
                {
                    object defaultParameterValue;
                    if (TypeReferences.GetDefaultParameterValue(info2) == System.Convert.DBNull)
                    {
                        defaultParameterValue = Microsoft.JScript.Convert.Coerce(null, reflect);
                    }
                    else
                    {
                        defaultParameterValue = TypeReferences.GetDefaultParameterValue(info2);
                    }
                    this.positionalArgValues.Add(defaultParameterValue);
                }
            }
            int num7 = 0;
            int num8 = list2.count;

            while (num7 < num8)
            {
                Assign assign2 = (Assign)list2[num7];
                if ((assign2.lhside is Lookup) && ((assign2.rhside is ConstantWrapper) || ((assign2.rhside is ArrayLiteral) && ((ArrayLiteral)assign2.rhside).IsOkToUseInCustomAttribute())))
                {
                    object   obj5     = assign2.rhside.Evaluate();
                    IReflect reflect2 = null;
                    if ((obj5 is ArrayObject) || (((reflect2 = TypeOfArgument(obj5)) != null) && (reflect2 != Typeob.Object)))
                    {
                        string       name   = ((Lookup)assign2.lhside).Name;
                        MemberInfo[] member = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance);
                        if ((member == null) || (member.Length == 0))
                        {
                            assign2.context.HandleError(JSError.NoSuchMember);
                            return(null);
                        }
                        if (member.Length == 1)
                        {
                            MemberInfo info3 = member[0];
                            if (info3 is FieldInfo)
                            {
                                FieldInfo info4 = (FieldInfo)info3;
                                if (info4.IsLiteral || info4.IsInitOnly)
                                {
                                    goto Label_04B6;
                                }
                                try
                                {
                                    IReflect reflect3 = (info4 is JSVariableField) ? ((JSVariableField)info4).GetInferredType(null) : info4.FieldType;
                                    obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect3, obj5 is ArrayObject);
                                    this.namedArgFields.Add(info3);
                                    this.namedArgFieldValues.Add(obj5);
                                    goto Label_04C9;
                                }
                                catch (JScriptException)
                                {
                                    assign2.rhside.context.HandleError(JSError.TypeMismatch);
                                    return(null);
                                }
                            }
                            if (info3 is PropertyInfo)
                            {
                                PropertyInfo prop      = (PropertyInfo)info3;
                                MethodInfo   setMethod = JSProperty.GetSetMethod(prop, false);
                                if (setMethod != null)
                                {
                                    ParameterInfo[] infoArray3 = setMethod.GetParameters();
                                    if ((infoArray3 != null) && (infoArray3.Length == 1))
                                    {
                                        try
                                        {
                                            IReflect reflect4 = (infoArray3[0] is ParameterDeclaration) ? ((ParameterDeclaration)infoArray3[0]).ParameterIReflect : infoArray3[0].ParameterType;
                                            obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect4, obj5 is ArrayObject);
                                            this.namedArgProperties.Add(info3);
                                            this.namedArgPropertyValues.Add(obj5);
                                            goto Label_04C9;
                                        }
                                        catch (JScriptException)
                                        {
                                            assign2.rhside.context.HandleError(JSError.TypeMismatch);
                                            return(null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
Label_04B6:
                assign2.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);

Label_04C9:
                num7++;
            }
            if (!this.CheckIfTargetOK(this.type))
            {
                return(null);
            }
            try
            {
                Type type = this.type as Type;
                if ((type != null) && (this.target is AssemblyCustomAttributeList))
                {
                    if (type.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyCultureAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            string str2 = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            if ((base.Engine.PEFileKind != PEFileKinds.Dll) && (str2.Length > 0))
                            {
                                base.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                                return(null);
                            }
                            base.Engine.Globals.assemblyCulture = new CultureInfo(str2);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyDelaySignAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyDelaySign = Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyFlagsAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyFlags = (AssemblyFlags)((uint)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(uint)));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyFileAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyFileName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyFileNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyFileName != null) && (base.Engine.Globals.assemblyKeyFileName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyFileName        = null;
                                base.Engine.Globals.assemblyKeyFileNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyNameAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyName != null) && (base.Engine.Globals.assemblyKeyName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyName        = null;
                                base.Engine.Globals.assemblyKeyNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyVersionAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyVersion = this.ParseVersion(Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.CLSCompliantAttribute")
                    {
                        base.Engine.isCLSCompliant = ((this.args == null) || (this.args.count == 0)) || Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        return(this);
                    }
                }
            }
            catch (ArgumentException)
            {
                base.context.HandleError(JSError.InvalidCall);
            }
            return(this);
        }
예제 #6
0
        internal override AST PartiallyEvaluate()
        {
            this.ctor = this.ctor.PartiallyEvaluateAsCallable();

            //first weed out assignment expressions and use them as property initializers
            ASTList positionalArgs = new ASTList(this.args.context);
            ASTList namedArgs      = new ASTList(this.args.context);

            for (int i = 0, m = this.args.count; i < m; i++)
            {
                AST    arg    = this.args[i];
                Assign assign = arg as Assign;
                if (assign != null)
                {
                    assign.rhside = assign.rhside.PartiallyEvaluate();
                    namedArgs.Append(assign);
                }
                else
                {
                    positionalArgs.Append(arg.PartiallyEvaluate());
                }
            }

            int n = positionalArgs.count;

            IReflect[] argIRs = new IReflect[n];
            for (int i = 0; i < n; i++)
            {
                AST arg = positionalArgs[i];
                // only accept ConstantWrappers
                if (arg is ConstantWrapper)
                {
                    Object argument = arg.Evaluate();
                    if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null)
                    {
                        this.positionalArgValues.Add(argument);
                        continue;
                    }
                }
                else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute())
                {
                    argIRs[i] = Typeob.ArrayObject;
                    this.positionalArgValues.Add(arg.Evaluate());
                    continue;
                }
                arg.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null); // the custom attribute is not good and it will be ignored
            }

            //Get the custom attribute and the appropriate constructor (under the covers)
            this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target);
            if (this.type == null)
            {
                return(null);
            }
            if (Convert.IsPromotableTo((IReflect)this.type, typeof(CodeAccessSecurityAttribute)))
            {
                this.context.HandleError(JSError.CannotUseStaticSecurityAttribute);
                return(null);
            }


            //Coerce the positional arguments to the right type and supply default values for optional parameters
            ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member;

            ParameterInfo[] parameters = c.GetParameters();
            int             j          = 0;
            int             len        = this.positionalArgValues.Count;

            foreach (ParameterInfo p in parameters)
            {
                IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType;
                if (j < len)
                {
                    Object value = this.positionalArgValues[j];
                    this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject);
                    j++;
                }
                else
                {
                    Object value;
                    if (p.DefaultValue == System.Convert.DBNull)
                    {
                        value = Convert.Coerce(null, ir);
                    }
                    else
                    {
                        value = p.DefaultValue;
                    }
                    this.positionalArgValues.Add(value);
                }
            }

            //Check validity of property/field initializers
            for (int i = 0, m = namedArgs.count; i < m; i++)
            {
                Assign assign = (Assign)namedArgs[i];
                if (assign.lhside is Lookup &&
                    (assign.rhside is ConstantWrapper ||
                     (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute())))
                {
                    Object   value   = assign.rhside.Evaluate();
                    IReflect argType = null;
                    if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object))
                    {
                        String        name    = ((Lookup)assign.lhside).Name;
                        MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance);
                        if (members == null || members.Length == 0)
                        {
                            assign.context.HandleError(JSError.NoSuchMember);
                            return(null);
                        }
                        if (members.Length == 1)
                        {
                            MemberInfo member = members[0];
                            if (member is FieldInfo)
                            {
                                FieldInfo fieldInfo = (FieldInfo)member;
                                if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly)
                                {
                                    try{
                                        IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType;
                                        value = Convert.Coerce(value, ir, value is ArrayObject);
                                        this.namedArgFields.Add(member);
                                        this.namedArgFieldValues.Add(value);
                                        continue;
                                    }catch (JScriptException) {
                                        assign.rhside.context.HandleError(JSError.TypeMismatch);
                                        return(null); // the custom attribute is not good and it will be ignored
                                    }
                                }
                            }
                            else if (member is PropertyInfo)
                            {
                                PropertyInfo propertyInfo  = (PropertyInfo)member;
                                MethodInfo   setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false);
                                if (setMethodInfo != null)
                                {
                                    ParameterInfo [] paramInfo = setMethodInfo.GetParameters();
                                    if (paramInfo != null && paramInfo.Length == 1)
                                    {
                                        try{
                                            IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType;
                                            value = Convert.Coerce(value, ir, value is ArrayObject);
                                            this.namedArgProperties.Add(member);
                                            this.namedArgPropertyValues.Add(value);
                                        }catch (JScriptException) {
                                            assign.rhside.context.HandleError(JSError.TypeMismatch);
                                            return(null); // the custom attribute is not good and it will be ignored
                                        }
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
                assign.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);
            }

            if (!this.CheckIfTargetOK(this.type))
            {
                return(null); //Ignore attribute
            }
            //Consume and discard assembly name attributes
            try{
                Type ty = this.type as Type;
                if (ty != null && this.target is AssemblyCustomAttributeList)
                {
                    if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyCultureAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            String cultureId = Convert.ToString(this.positionalArgValues[0]);
                            if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0)
                            {
                                this.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                                return(null);
                            }
                            this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId);
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false);
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]);
                            if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0)
                            {
                                this.Engine.Globals.assemblyKeyFileName = null;
                            }
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]);
                            if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0)
                            {
                                this.Engine.Globals.assemblyKeyName = null;
                            }
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyVersionAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0]));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.CLSCompliantAttribute")
                    {
                        this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false);
                        return(this);
                    }
                }
            }catch (ArgumentException) {
                this.context.HandleError(JSError.InvalidCall);
            }

            return(this);
        }