Inheritance: JSWrappedProperty
 public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
 {
     FieldInfo info = (FieldInfo) base.name_table[name];
     if (info != null)
     {
         return new MemberInfo[] { info };
     }
     bool flag = false;
     ScriptObject parent = base.parent;
     while (parent is FunctionScope)
     {
         FunctionScope scope = (FunctionScope) parent;
         flag = scope.isMethod && !scope.isStatic;
         JSLocalField field = (JSLocalField) scope.name_table[name];
         if (field == null)
         {
             parent = parent.GetParent();
         }
         else
         {
             if (field.IsLiteral && !(field.value is FunctionObject))
             {
                 return new MemberInfo[] { field };
             }
             JSLocalField field2 = new JSLocalField(field.Name, this, base.field_table.Count, Microsoft.JScript.Missing.Value) {
                 outerField = field,
                 debugOn = field.debugOn
             };
             if ((!field2.debugOn && this.owner.funcContext.document.debugOn) && scope.owner.funcContext.document.debugOn)
             {
                 field2.debugOn = Array.IndexOf<string>(scope.owner.formal_parameters, field.Name) >= 0;
             }
             field2.isDefined = field.isDefined;
             field2.debuggerName = "outer." + field2.Name;
             if (field.IsLiteral)
             {
                 field2.attributeFlags |= FieldAttributes.Literal;
                 field2.value = field.value;
             }
             this.AddOuterScopeField(name, field2);
             if (this.ProvidesOuterScopeLocals[parent] == null)
             {
                 this.ProvidesOuterScopeLocals[parent] = parent;
             }
             ((FunctionScope) parent).mustSaveStackLocals = true;
             return new MemberInfo[] { field2 };
         }
     }
     if ((parent is ClassScope) && flag)
     {
         MemberInfo[] member = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
         int length = member.Length;
         bool flag2 = false;
         for (int i = 0; i < length; i++)
         {
             MethodInfo info3;
             PropertyInfo info4;
             MemberInfo info2 = member[i];
             MemberTypes memberType = info2.MemberType;
             if (memberType != MemberTypes.Field)
             {
                 if (memberType == MemberTypes.Method)
                 {
                     goto Label_029E;
                 }
                 if (memberType == MemberTypes.Property)
                 {
                     goto Label_02C7;
                 }
             }
             else
             {
                 info = (FieldInfo) info2;
                 if (info.IsLiteral)
                 {
                     JSMemberField field3 = info as JSMemberField;
                     if (((field3 != null) && (field3.value is ClassScope)) && !((ClassScope) field3.value).owner.IsStatic)
                     {
                         flag2 = true;
                     }
                 }
                 if (!info.IsStatic && !info.IsLiteral)
                 {
                     member[i] = new JSClosureField(info);
                     flag2 = true;
                 }
             }
             continue;
         Label_029E:
             info3 = (MethodInfo) info2;
             if (!info3.IsStatic)
             {
                 member[i] = new JSClosureMethod(info3);
                 flag2 = true;
             }
             continue;
         Label_02C7:
             info4 = (PropertyInfo) info2;
             MethodInfo getMethod = JSProperty.GetGetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
             MethodInfo setMethod = JSProperty.GetSetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
             bool flag3 = false;
             if ((getMethod != null) && !getMethod.IsStatic)
             {
                 flag3 = true;
                 getMethod = new JSClosureMethod(getMethod);
             }
             if ((setMethod != null) && !setMethod.IsStatic)
             {
                 flag3 = true;
                 setMethod = new JSClosureMethod(setMethod);
             }
             if (flag3)
             {
                 member[i] = new JSClosureProperty(info4, getMethod, setMethod);
                 flag2 = true;
             }
         }
         if (flag2)
         {
             this.GiveOuterFunctionsTheBadNews();
         }
         if (length > 0)
         {
             return member;
         }
     }
     if ((bindingAttr & BindingFlags.DeclaredOnly) != BindingFlags.Default)
     {
         return new MemberInfo[0];
     }
     return parent.GetMember(name, bindingAttr);
 }
Ejemplo n.º 2
0
        public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
        {
            FieldInfo info = (FieldInfo)base.name_table[name];

            if (info != null)
            {
                return(new MemberInfo[] { info });
            }
            bool         flag   = false;
            ScriptObject parent = base.parent;

            while (parent is FunctionScope)
            {
                FunctionScope scope = (FunctionScope)parent;
                flag = scope.isMethod && !scope.isStatic;
                JSLocalField field = (JSLocalField)scope.name_table[name];
                if (field == null)
                {
                    parent = parent.GetParent();
                }
                else
                {
                    if (field.IsLiteral && !(field.value is FunctionObject))
                    {
                        return(new MemberInfo[] { field });
                    }
                    JSLocalField field2 = new JSLocalField(field.Name, this, base.field_table.Count, Microsoft.JScript.Missing.Value)
                    {
                        outerField = field,
                        debugOn    = field.debugOn
                    };
                    if ((!field2.debugOn && this.owner.funcContext.document.debugOn) && scope.owner.funcContext.document.debugOn)
                    {
                        field2.debugOn = Array.IndexOf <string>(scope.owner.formal_parameters, field.Name) >= 0;
                    }
                    field2.isDefined    = field.isDefined;
                    field2.debuggerName = "outer." + field2.Name;
                    if (field.IsLiteral)
                    {
                        field2.attributeFlags |= FieldAttributes.Literal;
                        field2.value           = field.value;
                    }
                    this.AddOuterScopeField(name, field2);
                    if (this.ProvidesOuterScopeLocals[parent] == null)
                    {
                        this.ProvidesOuterScopeLocals[parent] = parent;
                    }
                    ((FunctionScope)parent).mustSaveStackLocals = true;
                    return(new MemberInfo[] { field2 });
                }
            }
            if ((parent is ClassScope) && flag)
            {
                MemberInfo[] member = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
                int          length = member.Length;
                bool         flag2  = false;
                for (int i = 0; i < length; i++)
                {
                    MethodInfo   info3;
                    PropertyInfo info4;
                    MemberInfo   info2      = member[i];
                    MemberTypes  memberType = info2.MemberType;
                    if (memberType != MemberTypes.Field)
                    {
                        if (memberType == MemberTypes.Method)
                        {
                            goto Label_029E;
                        }
                        if (memberType == MemberTypes.Property)
                        {
                            goto Label_02C7;
                        }
                    }
                    else
                    {
                        info = (FieldInfo)info2;
                        if (info.IsLiteral)
                        {
                            JSMemberField field3 = info as JSMemberField;
                            if (((field3 != null) && (field3.value is ClassScope)) && !((ClassScope)field3.value).owner.IsStatic)
                            {
                                flag2 = true;
                            }
                        }
                        if (!info.IsStatic && !info.IsLiteral)
                        {
                            member[i] = new JSClosureField(info);
                            flag2     = true;
                        }
                    }
                    continue;
Label_029E:
                    info3 = (MethodInfo)info2;
                    if (!info3.IsStatic)
                    {
                        member[i] = new JSClosureMethod(info3);
                        flag2     = true;
                    }
                    continue;
Label_02C7:
                    info4 = (PropertyInfo)info2;
                    MethodInfo getMethod = JSProperty.GetGetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
                    MethodInfo setMethod = JSProperty.GetSetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
                    bool       flag3     = false;
                    if ((getMethod != null) && !getMethod.IsStatic)
                    {
                        flag3     = true;
                        getMethod = new JSClosureMethod(getMethod);
                    }
                    if ((setMethod != null) && !setMethod.IsStatic)
                    {
                        flag3     = true;
                        setMethod = new JSClosureMethod(setMethod);
                    }
                    if (flag3)
                    {
                        member[i] = new JSClosureProperty(info4, getMethod, setMethod);
                        flag2     = true;
                    }
                }
                if (flag2)
                {
                    this.GiveOuterFunctionsTheBadNews();
                }
                if (length > 0)
                {
                    return(member);
                }
            }
            if ((bindingAttr & BindingFlags.DeclaredOnly) != BindingFlags.Default)
            {
                return(new MemberInfo[0]);
            }
            return(parent.GetMember(name, bindingAttr));
        }
 public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr){
   FieldInfo field = (FieldInfo)(this.name_table[name]);
   if (field != null) return new MemberInfo[]{field};
   bool nestedInInstanceMethod = false;
   ScriptObject parent = this.parent;
   //Treat locals of outer functions as if they were locals of this function
   while (parent is FunctionScope){
     FunctionScope fscope = (FunctionScope)parent;
     nestedInInstanceMethod = fscope.isMethod && !fscope.isStatic;
     JSLocalField lfield = (JSLocalField)fscope.name_table[name];
     if (lfield == null){
       parent = parent.GetParent();
       continue;
     }
     if (lfield.IsLiteral && !(lfield.value is FunctionObject))
       return new MemberInfo[]{lfield};
     JSLocalField f = new JSLocalField(lfield.Name, this, this.field_table.Count, Missing.Value);
     f.outerField = lfield;
     f.debugOn = lfield.debugOn;
     if (!f.debugOn && this.owner.funcContext.document.debugOn && fscope.owner.funcContext.document.debugOn){
       //Check to see it is off because outer field is a parameter
       f.debugOn = Array.IndexOf(fscope.owner.formal_parameters, lfield.Name) >= 0;
     }
     f.isDefined = lfield.isDefined;
     f.debuggerName = "outer" + "." + f.Name;
     if (lfield.IsLiteral){
       f.attributeFlags |= FieldAttributes.Literal;
       f.value = lfield.value;
     }
     this.AddOuterScopeField(name, f);
     if (this.ProvidesOuterScopeLocals[parent] == null) this.ProvidesOuterScopeLocals[parent] = parent;
     ((FunctionScope)parent).mustSaveStackLocals = true;
     return new MemberInfo[]{f};
   }
   if (parent is ClassScope && nestedInInstanceMethod){
     //return class members as if they were local to the function. It is more convenient to wrap up instance members
     //at this stage than it is to figure out later that a special case is involved.
     MemberInfo[] members = parent.GetMember(name, bindingAttr&~BindingFlags.DeclaredOnly);
     int n = members.Length;
     bool giveBadNews = false;
     for (int i = 0; i < n; i++){
       MemberInfo member = members[i];
       switch(member.MemberType){
         case MemberTypes.Field:
           field = (FieldInfo)member;
           if (field.IsLiteral){
             JSMemberField mfield = field as JSMemberField;
             if (mfield != null && mfield.value is ClassScope && !((ClassScope)mfield.value).owner.IsStatic)
               giveBadNews = true;
           }
           if (!field.IsStatic && !field.IsLiteral){
             members[i] = new JSClosureField(field);
             giveBadNews = true;
           }
           break;
         case MemberTypes.Method:
           MethodInfo meth = (MethodInfo)member;
           if (!meth.IsStatic){
             members[i] = new JSClosureMethod(meth);
             giveBadNews = true;
           }
           break;
         case MemberTypes.Property:
           PropertyInfo prop = (PropertyInfo)member;
           MethodInfo getMeth = JSProperty.GetGetMethod(prop, (bindingAttr&BindingFlags.NonPublic) != 0);
           MethodInfo setMeth = JSProperty.GetSetMethod(prop, (bindingAttr&BindingFlags.NonPublic) != 0);
           bool nonStatic = false;
           if (getMeth != null && !getMeth.IsStatic){
             nonStatic = true;
             getMeth = new JSClosureMethod(getMeth);
           }
           if (setMeth != null && !setMeth.IsStatic){
             nonStatic = true;
             setMeth = new JSClosureMethod(setMeth);
           }
           if (nonStatic){
             members[i] = new JSClosureProperty(prop, getMeth, setMeth);
             giveBadNews = true;
           }
           break;
       }
     }
     if (giveBadNews) this.GiveOuterFunctionsTheBadNews(); //They have to create explicit stack frames
     if (n > 0) return members;
   }
   if ((bindingAttr&BindingFlags.DeclaredOnly) != 0) return new MemberInfo[0];
   return parent.GetMember(name, bindingAttr);
 }
Ejemplo n.º 4
0
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            FieldInfo field = (FieldInfo)(this.name_table[name]);

            if (field != null)
            {
                return new MemberInfo[] { field }
            }
            ;
            bool         nestedInInstanceMethod = false;
            ScriptObject parent = this.parent;

            //Treat locals of outer functions as if they were locals of this function
            while (parent is FunctionScope)
            {
                FunctionScope fscope = (FunctionScope)parent;

                nestedInInstanceMethod = fscope.isMethod && !fscope.isStatic;
                JSLocalField lfield = (JSLocalField)fscope.name_table[name];
                if (lfield == null)
                {
                    parent = parent.GetParent();
                    continue;
                }
                if (lfield.IsLiteral && !(lfield.value is FunctionObject))
                {
                    return new MemberInfo[] { lfield }
                }
                ;
                JSLocalField f = new JSLocalField(lfield.Name, this, this.field_table.Count, Missing.Value);
                f.outerField = lfield;
                f.debugOn    = lfield.debugOn;
                if (!f.debugOn && this.owner.funcContext.document.debugOn && fscope.owner.funcContext.document.debugOn)
                {
                    //Check to see it is off because outer field is a parameter
                    f.debugOn = Array.IndexOf(fscope.owner.formal_parameters, lfield.Name) >= 0;
                }
                f.isDefined    = lfield.isDefined;
                f.debuggerName = "outer" + "." + f.Name;
                if (lfield.IsLiteral)
                {
                    f.attributeFlags |= FieldAttributes.Literal;
                    f.value           = lfield.value;
                }
                this.AddOuterScopeField(name, f);
                if (this.ProvidesOuterScopeLocals[parent] == null)
                {
                    this.ProvidesOuterScopeLocals[parent] = parent;
                }
                ((FunctionScope)parent).mustSaveStackLocals = true;
                return(new MemberInfo[] { f });
            }
            if (parent is ClassScope && nestedInInstanceMethod)
            {
                //return class members as if they were local to the function. It is more convenient to wrap up instance members
                //at this stage than it is to figure out later that a special case is involved.
                MemberInfo[] members     = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
                int          n           = members.Length;
                bool         giveBadNews = false;
                for (int i = 0; i < n; i++)
                {
                    MemberInfo member = members[i];
                    switch (member.MemberType)
                    {
                    case MemberTypes.Field:
                        field = (FieldInfo)member;
                        if (field.IsLiteral)
                        {
                            JSMemberField mfield = field as JSMemberField;
                            if (mfield != null && mfield.value is ClassScope && !((ClassScope)mfield.value).owner.IsStatic)
                            {
                                giveBadNews = true;
                            }
                        }
                        if (!field.IsStatic && !field.IsLiteral)
                        {
                            members[i]  = new JSClosureField(field);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Method:
                        MethodInfo meth = (MethodInfo)member;
                        if (!meth.IsStatic)
                        {
                            members[i]  = new JSClosureMethod(meth);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Property:
                        PropertyInfo prop      = (PropertyInfo)member;
                        MethodInfo   getMeth   = JSProperty.GetGetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        MethodInfo   setMeth   = JSProperty.GetSetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        bool         nonStatic = false;
                        if (getMeth != null && !getMeth.IsStatic)
                        {
                            nonStatic = true;
                            getMeth   = new JSClosureMethod(getMeth);
                        }
                        if (setMeth != null && !setMeth.IsStatic)
                        {
                            nonStatic = true;
                            setMeth   = new JSClosureMethod(setMeth);
                        }
                        if (nonStatic)
                        {
                            members[i]  = new JSClosureProperty(prop, getMeth, setMeth);
                            giveBadNews = true;
                        }
                        break;
                    }
                }
                if (giveBadNews)
                {
                    this.GiveOuterFunctionsTheBadNews();        //They have to create explicit stack frames
                }
                if (n > 0)
                {
                    return(members);
                }
            }
            if ((bindingAttr & BindingFlags.DeclaredOnly) != 0)
            {
                return(new MemberInfo[0]);
            }
            return(parent.GetMember(name, bindingAttr));
        }