Inheritance: JSVariableField
コード例 #1
0
        internal object EvaluateAsType()
        {
            object memberValue = this.rootObject.EvaluateAsWrappedNamespace(false).GetMemberValue(base.name);

            if ((memberValue != null) && !(memberValue is Microsoft.JScript.Missing))
            {
                return(memberValue);
            }
            object obj3       = null;
            Member rootObject = this.rootObject as Member;

            if (rootObject == null)
            {
                Lookup lookup = this.rootObject as Lookup;
                if (lookup == null)
                {
                    return(null);
                }
                ConstantWrapper wrapper = lookup.PartiallyEvaluate() as ConstantWrapper;
                if (wrapper == null)
                {
                    JSGlobalField member = lookup.member as JSGlobalField;
                    if ((member == null) || !member.IsLiteral)
                    {
                        return(null);
                    }
                    obj3 = member.value;
                }
                else
                {
                    obj3 = wrapper.value;
                }
            }
            else
            {
                obj3 = rootObject.EvaluateAsType();
            }
            ClassScope scope = obj3 as ClassScope;

            if (scope != null)
            {
                MemberInfo[] infoArray = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (infoArray.Length != 0)
                {
                    JSMemberField field2 = infoArray[0] as JSMemberField;
                    if (((field2 != null) && field2.IsLiteral) && ((field2.value is ClassScope) && (field2.IsPublic || field2.IsAccessibleFrom(base.Engine.ScriptObjectStackTop()))))
                    {
                        return(field2.value);
                    }
                }
                return(null);
            }
            Type type = obj3 as Type;

            if (type != null)
            {
                return(type.GetNestedType(base.name));
            }
            return(null);
        }
コード例 #2
0
 private MemberInfo[] GetMember(string name, BindingFlags bindingAttr, bool wrapMembers)
 {
     MemberInfo[] members = this.GetLocalMember(name, bindingAttr, wrapMembers);
     if (members.Length <= 0)
     {
         if (base.parent == null)
         {
             return(new MemberInfo[0]);
         }
         if (base.parent is JSObject)
         {
             members     = ((JSObject)base.parent).GetMember(name, bindingAttr, true);
             wrapMembers = false;
         }
         else
         {
             members = base.parent.GetMember(name, bindingAttr);
         }
         foreach (MemberInfo info in members)
         {
             if (info.MemberType == MemberTypes.Field)
             {
                 FieldInfo     info2 = (FieldInfo)info;
                 JSMemberField field = info as JSMemberField;
                 if (field != null)
                 {
                     if (!field.IsStatic)
                     {
                         JSGlobalField field2 = new JSGlobalField(this, name, field.value, FieldAttributes.Public);
                         this.NameTable[name] = field2;
                         this.field_table.Add(field2);
                         info2 = field;
                     }
                 }
                 else
                 {
                     info2 = new JSPrototypeField(base.parent, (FieldInfo)info);
                     if (!this.noExpando)
                     {
                         this.NameTable[name] = info2;
                         this.field_table.Add(info2);
                     }
                 }
                 return(new MemberInfo[] { info2 });
             }
             if (!this.noExpando && (info.MemberType == MemberTypes.Method))
             {
                 FieldInfo info3 = new JSPrototypeField(base.parent, new JSGlobalField(this, name, LateBinding.GetMemberValue(base.parent, name, null, members), FieldAttributes.InitOnly | FieldAttributes.Public));
                 this.NameTable[name] = info3;
                 this.field_table.Add(info3);
                 return(new MemberInfo[] { info3 });
             }
         }
         if (wrapMembers)
         {
             return(ScriptObject.WrapMembers(members, base.parent));
         }
     }
     return(members);
 }
コード例 #3
0
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            int length = this.fields.Length;

            if (length > 0)
            {
                for (int i = 0; i < length; i++)
                {
                    JSGlobalField field = this.fields[i] as JSGlobalField;
                    if (field != null)
                    {
                        Type fieldType = field.FieldType;
                        if (((field.IsLiteral && (fieldType != Typeob.ScriptFunction)) && (fieldType != Typeob.Type)) || (field.metaData != null))
                        {
                            if (((fieldType.IsPrimitive || (fieldType == Typeob.String)) || fieldType.IsEnum) && (field.metaData == null))
                            {
                                base.compilerGlobals.classwriter.DefineField(field.Name, fieldType, field.Attributes).SetConstant(field.value);
                            }
                        }
                        else if (!(field.value is FunctionObject) || !((FunctionObject)field.value).suppressIL)
                        {
                            FieldBuilder builder2 = base.compilerGlobals.classwriter.DefineField(field.Name, fieldType, (field.Attributes & ~(FieldAttributes.Literal | FieldAttributes.InitOnly)) | FieldAttributes.Static);
                            field.metaData = builder2;
                            field.WriteCustomAttribute(base.Engine.doCRS);
                        }
                    }
                }
            }
            this.statement_block.TranslateToILInitializer(il);
        }
コード例 #4
0
ファイル: regexpliteral.cs プロジェクト: ArildF/masters
 internal override AST PartiallyEvaluate() {
   String id = "regexp "+(RegExpLiteral.counter++).ToString();
   JSGlobalField v = (JSGlobalField)((ActivationObject)this.Engine.ScriptObjectStackTop()).GetGlobalScope().AddNewField(id, null, FieldAttributes.Assembly);
   v.type = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, this.context));
   this.regExpVar = v;
   return this;
 }
コード例 #5
0
 internal void MergeWith(PackageScope p)
 {
     foreach (object obj2 in p.field_table)
     {
         JSGlobalField field = (JSGlobalField)obj2;
         ClassScope    scope = field.value as ClassScope;
         if (base.name_table[field.Name] != null)
         {
             if (scope != null)
             {
                 scope.owner.context.HandleError(JSError.DuplicateName, field.Name, true);
                 scope.owner.name = scope.owner.name + p.GetHashCode().ToString(CultureInfo.InvariantCulture);
             }
         }
         else
         {
             base.field_table.Add(field);
             base.name_table[field.Name] = field;
             if (scope != null)
             {
                 scope.owner.enclosingScope = this;
                 scope.package = this;
             }
         }
     }
 }
コード例 #6
0
        public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
        {
            FieldInfo info = (FieldInfo)base.name_table[name];

            if (info != null)
            {
                return(new MemberInfo[] { info });
            }
            FieldAttributes literal   = FieldAttributes.Literal;
            string          className = ((this.name == null) || (this.name.Length == 0)) ? name : (this.name + "." + name);
            object          type      = null;

            if ((this.name != null) && (this.name.Length > 0))
            {
                type = base.engine.GetClass(className);
            }
            if (type == null)
            {
                type = base.engine.GetType(className);
                if ((type != null) && !((Type)type).IsPublic)
                {
                    if ((bindingAttr & BindingFlags.NonPublic) == BindingFlags.Default)
                    {
                        type = null;
                    }
                    else
                    {
                        literal |= FieldAttributes.Private;
                    }
                }
            }
            else if ((((ClassScope)type).owner.attributes & TypeAttributes.Public) == TypeAttributes.AnsiClass)
            {
                if ((bindingAttr & BindingFlags.NonPublic) == BindingFlags.Default)
                {
                    type = null;
                }
                else
                {
                    literal |= FieldAttributes.Private;
                }
            }
            if (type == null)
            {
                if ((base.parent != null) && ((bindingAttr & BindingFlags.DeclaredOnly) == BindingFlags.Default))
                {
                    return(base.parent.GetMember(name, bindingAttr));
                }
                return(new MemberInfo[0]);
            }
            JSGlobalField field = (JSGlobalField)this.CreateField(name, literal, type);

            if (base.engine.doFast)
            {
                field.type = new TypeExpression(new ConstantWrapper(Typeob.Type, null));
            }
            base.name_table[name] = field;
            base.field_table.Add(field);
            return(new MemberInfo[] { field });
        }
コード例 #7
0
ファイル: regexpliteral.cs プロジェクト: ArildF/masters
 internal RegExpLiteral(String source, bool ignoreCase, bool global, bool multiline, Context context)
   : base(context) {
   this.source     = source;
   this.ignoreCase = ignoreCase;
   this.multiline  = multiline;
   this.global     = global;
   this.regExpVar  = null;
 }
コード例 #8
0
 internal override AST PartiallyEvaluate() {
   String id = "regexp "+(RegExpLiteral.counter++).ToString(CultureInfo.InvariantCulture);
   GlobalScope gs = (GlobalScope)this.Engine.GetGlobalScope().GetObject();
   JSGlobalField v = (JSGlobalField)gs.AddNewField(id, null, FieldAttributes.Assembly);
   v.type = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, this.context));
   this.regExpVar = v;
   return this;
 }
コード例 #9
0
 internal RegExpLiteral(String source, bool ignoreCase, bool global, bool multiline, Context context)
     : base(context)
 {
     this.source     = source;
     this.ignoreCase = ignoreCase;
     this.multiline  = multiline;
     this.global     = global;
     this.regExpVar  = null;
 }
コード例 #10
0
        internal override AST PartiallyEvaluate()
        {
            String        id = "regexp " + (RegExpLiteral.counter++).ToString();
            JSGlobalField v  = (JSGlobalField)((ActivationObject)this.Engine.ScriptObjectStackTop()).GetGlobalScope().AddNewField(id, null, FieldAttributes.Assembly);

            v.type         = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, this.context));
            this.regExpVar = v;
            return(this);
        }
コード例 #11
0
        internal override AST PartiallyEvaluate()
        {
            String        id = "regexp " + (RegExpLiteral.counter++).ToString(CultureInfo.InvariantCulture);
            GlobalScope   gs = (GlobalScope)this.Engine.GetGlobalScope().GetObject();
            JSGlobalField v  = (JSGlobalField)gs.AddNewField(id, null, FieldAttributes.Assembly);

            v.type         = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, this.context));
            this.regExpVar = v;
            return(this);
        }
コード例 #12
0
        internal override AST PartiallyEvaluate()
        {
            string        name  = "regexp " + counter++.ToString(CultureInfo.InvariantCulture);
            GlobalScope   scope = (GlobalScope)base.Engine.GetGlobalScope().GetObject();
            JSGlobalField field = (JSGlobalField)scope.AddNewField(name, null, FieldAttributes.Assembly);

            field.type     = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, base.context));
            this.regExpVar = field;
            return(this);
        }
コード例 #13
0
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
 {
     if (((base.defaultMember != null) && construct) && brackets)
     {
         base.TranslateToILCall(il, rtype, argList, construct, brackets);
     }
     else
     {
         JSGlobalField member = base.member as JSGlobalField;
         if (((member != null) && member.IsLiteral) && (argList.count == 1))
         {
             Type type = Microsoft.JScript.Convert.ToType((IReflect)member.value);
             argList[0].TranslateToIL(il, type);
             Microsoft.JScript.Convert.Emit(this, il, type, rtype);
         }
         else
         {
             this.TranslateToILWithDupOfThisOb(il);
             argList.TranslateToIL(il, Typeob.ArrayOfObject);
             if (construct)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             if (brackets)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
         }
     }
 }
コード例 #14
0
ファイル: callableexpression.cs プロジェクト: ydunk/masters
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            if (this.defaultMember != null && construct && brackets)
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
                return;
            }
            JSGlobalField gf = this.member as JSGlobalField;

            if (gf != null && gf.IsLiteral && argList.count == 1)
            {
                Type t = Convert.ToType((IReflect)gf.value);
                argList[0].TranslateToIL(il, t);
                Convert.Emit(this, il, t, rtype);
                return;
            }
            this.TranslateToILWithDupOfThisOb(il);
            argList.TranslateToIL(il, typeof(Object[]));
            if (construct)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (brackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
コード例 #15
0
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            int nf = this.fields.Length;

            if (nf > 0)
            {
                for (int i = 0; i < nf; i++)
                {
                    JSGlobalField field = this.fields[i] as JSGlobalField;
                    if (field == null)
                    {
                        continue;
                    }
                    Type t = field.FieldType;
                    if ((field.IsLiteral && t != Typeob.ScriptFunction && t != Typeob.Type) || field.metaData != null)
                    {
                        if ((t.IsPrimitive || t == Typeob.String || t.IsEnum) && field.metaData == null)
                        {
                            FieldBuilder b = compilerGlobals.classwriter.DefineField(field.Name, t, field.Attributes);
                            b.SetConstant(field.value);
                        }
                        continue;
                    }
                    if (field.value is FunctionObject && ((FunctionObject)field.value).suppressIL)
                    {
                        continue;
                    }
                    FieldBuilder fb = compilerGlobals.classwriter.DefineField(field.Name, t,
                                                                              field.Attributes & (~(FieldAttributes.Literal | FieldAttributes.InitOnly)) | FieldAttributes.Static);
                    field.metaData = fb;
                    field.WriteCustomAttribute(this.Engine.doCRS);
                    //There is no need to store Closure objects in the fields corresponding to functions, since the initializer code
                    //for functions takes care of it. Likewise for Classes.
                }
            }
            this.statement_block.TranslateToILInitializer(il);
        }
コード例 #16
0
 internal void MergeWith(PackageScope p)
 {
     foreach (Object f in p.field_table)
     {
         JSGlobalField field = (JSGlobalField)f;
         ClassScope    csc   = field.value as ClassScope;
         if (this.name_table[field.Name] != null)
         {
             if (csc != null)
             {
                 csc.owner.context.HandleError(JSError.DuplicateName, field.Name, true);
                 csc.owner.name += p.GetHashCode().ToString();
             }
             continue;
         }
         this.field_table.Add(field);
         this.name_table[field.Name] = field;
         if (csc != null)
         {
             csc.owner.enclosingScope = this;
             csc.package = this;
         }
     }
 }
コード例 #17
0
 internal override AST PartiallyEvaluate()
 {
     string name = "regexp " + counter++.ToString(CultureInfo.InvariantCulture);
     GlobalScope scope = (GlobalScope) base.Engine.GetGlobalScope().GetObject();
     JSGlobalField field = (JSGlobalField) scope.AddNewField(name, null, FieldAttributes.Assembly);
     field.type = new TypeExpression(new ConstantWrapper(Typeob.RegExpObject, base.context));
     this.regExpVar = field;
     return this;
 }
コード例 #18
0
ファイル: wrappednamespace.cs プロジェクト: ydunk/masters
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            FieldInfo cachedfield = (FieldInfo)(this.name_table[name]);

            if (cachedfield != null)
            {
                return new MemberInfo[] { cachedfield }
            }
            ;

            FieldAttributes attrs    = FieldAttributes.Literal;
            String          fullname = this.name == null || this.name.Length == 0 ? name : this.name + "." + name;
            Object          t        = null;

            if (this.name != null && this.name.Length > 0)
            {
                t = this.engine.GetClass(fullname); //Packages will not have classes residing in the default name space
            }
            if (t == null)
            {
                t = this.engine.GetType(fullname);
                if (t != null && !((Type)t).IsPublic)
                {
                    if ((bindingAttr & BindingFlags.NonPublic) == 0)
                    {
                        t = null;
                    }
                    else
                    {
                        attrs |= FieldAttributes.Private;
                    }
                }
            }
            else
            {
                if ((((ClassScope)t).owner.attributes & TypeAttributes.Public) == 0)
                {
                    if ((bindingAttr & BindingFlags.NonPublic) == 0)
                    {
                        t = null;
                    }
                    else
                    {
                        attrs |= FieldAttributes.Private;
                    }
                }
            }
            if (t == null)
            {
                if (this.parent != null && (bindingAttr & BindingFlags.DeclaredOnly) == 0)
                {
                    return(this.parent.GetMember(name, bindingAttr));
                }
                return(new MemberInfo[0]);
            }

            JSGlobalField field = (JSGlobalField)this.CreateField(name, attrs, t);

            if (engine.doFast)
            {
                field.type = new TypeExpression(new ConstantWrapper(Typeob.Type, null));
            }
            this.name_table[name] = field;
            this.field_table.Add(field);
            return(new MemberInfo[] { field });
        }
コード例 #19
0
        internal Object EvaluateAsType()
        {
            WrappedNamespace ns     = this.rootObject.EvaluateAsWrappedNamespace(false);
            Object           result = ns.GetMemberValue(this.name);

            if (result != null && !(result is Missing))
            {
                return(result);
            }
            Object ob   = null;
            Member root = this.rootObject as Member;

            if (root == null)
            {
                Lookup lookup = this.rootObject as Lookup;
                if (lookup == null)
                {
                    return(null);
                }
                ob = lookup.PartiallyEvaluate();
                ConstantWrapper cw = ob as ConstantWrapper;
                if (cw != null)
                {
                    ob = cw.value;
                }
                else
                {
                    JSGlobalField f = lookup.member as JSGlobalField;
                    if (f != null && f.IsLiteral)
                    {
                        ob = f.value;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                ob = root.EvaluateAsType();
            }
            ClassScope csc = ob as ClassScope;

            if (csc != null)
            {
                MemberInfo[] members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                if (members.Length == 0)
                {
                    return(null);
                }
                JSMemberField field = members[0] as JSMemberField;
                if (field == null || !field.IsLiteral || !(field.value is ClassScope) || !field.IsPublic && !field.IsAccessibleFrom(this.Engine.ScriptObjectStackTop()))
                {
                    return(null);
                }
                return(field.value);
            }
            Type t = ob as Type;

            if (t != null)
            {
                return(t.GetNestedType(this.name));
            }
            return(null);
        }
コード例 #20
0
ファイル: jsobject.cs プロジェクト: ydunk/masters
 private MemberInfo[] GetMember(String name, BindingFlags bindingAttr, bool wrapMembers)
 {
     MemberInfo[] members = this.GetLocalMember(name, bindingAttr, wrapMembers);
     if (members.Length > 0)
     {
         return(members);
     }
     if (this.parent != null)
     {
         if (this.parent is JSObject)
         {
             members     = ((JSObject)this.parent).GetMember(name, bindingAttr, true);
             wrapMembers = false;
         }
         else
         {
             members = this.parent.GetMember(name, bindingAttr);
         }
         foreach (MemberInfo mem in members)
         {
             if (mem.MemberType == MemberTypes.Field)
             {
                 FieldInfo     field  = (FieldInfo)mem;
                 JSMemberField mfield = mem as JSMemberField;
                 if (mfield != null) //This can only happen when running in the Evaluator
                 {
                     if (!mfield.IsStatic)
                     {
                         JSGlobalField gfield = new JSGlobalField(this, name, mfield.value, FieldAttributes.Public);
                         this.NameTable[name] = gfield;
                         this.field_table.Add(gfield);
                         field = mfield;
                     }
                 }
                 else
                 {
                     field = new JSPrototypeField(this.parent, (FieldInfo)mem);
                     if (!this.noExpando)
                     {
                         this.NameTable[name] = field;
                         this.field_table.Add(field);
                     }
                 }
                 return(new MemberInfo[] { field });
             }
             if (!this.noExpando)
             {
                 if (mem.MemberType == MemberTypes.Method)
                 {
                     FieldInfo field = new JSPrototypeField(this.parent,
                                                            new JSGlobalField(this, name,
                                                                              LateBinding.GetMemberValue(this.parent, name, null, members),
                                                                              FieldAttributes.Public | FieldAttributes.InitOnly));
                     this.NameTable[name] = field;
                     this.field_table.Add(field);
                     return(new MemberInfo[] { field });
                 }
             }
         }
         if (wrapMembers)
         {
             return(ScriptObject.WrapMembers(members, this.parent));
         }
         else
         {
             return(members);
         }
     }
     return(new MemberInfo[0]);
 }
コード例 #21
0
ファイル: jsobject.cs プロジェクト: ArildF/masters
 private MemberInfo[] GetMember(String name, BindingFlags bindingAttr, bool wrapMembers){
   MemberInfo[] members = this.GetLocalMember(name, bindingAttr, wrapMembers);
   if (members.Length > 0) return members;
   if (this.parent != null){
     if (this.parent is JSObject){
       members = ((JSObject)this.parent).GetMember(name, bindingAttr, true);
       wrapMembers = false;
     }else
       members = this.parent.GetMember(name, bindingAttr);
     foreach (MemberInfo mem in members){
       if (mem.MemberType == MemberTypes.Field){
         FieldInfo field = (FieldInfo)mem;
         JSMemberField mfield = mem as JSMemberField;
         if (mfield != null){ //This can only happen when running in the Evaluator
           if (!mfield.IsStatic){
             JSGlobalField gfield = new JSGlobalField(this, name, mfield.value, FieldAttributes.Public);
             this.NameTable[name] = gfield;
             this.field_table.Add(gfield);
             field = mfield;
           }
         }else{
           field = new JSPrototypeField(this.parent, (FieldInfo)mem);
           if (!this.noExpando){
             this.NameTable[name] = field;
             this.field_table.Add(field);
           }
         }
         return new MemberInfo[]{field};
       }
       if (!this.noExpando){
         if (mem.MemberType == MemberTypes.Method){
         FieldInfo field = new JSPrototypeField(this.parent,
           new JSGlobalField(this, name,
           LateBinding.GetMemberValue(this.parent, name, null, members),
           FieldAttributes.Public|FieldAttributes.InitOnly));
           this.NameTable[name] = field;
           this.field_table.Add(field);
           return new MemberInfo[]{field};
         }
       }
     }
     if (wrapMembers)
       return ScriptObject.WrapMembers(members, this.parent);
     else
       return members;
   }
   return new MemberInfo[0];
 }