Inheritance: JSVariableField
Example #1
0
        internal void CheckOverloadsForDuplicates()
        {
            JSMemberField current = this;

            while (current != null)
            {
                FunctionObject func = current.value as FunctionObject;
                if (func == null)
                {
                    return;
                }
                for (JSMemberField next = current.nextOverload; next != null; next = next.nextOverload)
                {
                    FunctionObject f = (FunctionObject)next.value;
                    if (f.implementedIface != func.implementedIface)
                    {
                        continue;
                    }
                    if (Class.ParametersMatch(f.parameter_declarations, func.parameter_declarations))
                    {
                        func.funcContext.HandleError(JSError.DuplicateMethod);
                        f.funcContext.HandleError(JSError.DuplicateMethod);
                        break;
                    }
                }
                current = current.nextOverload;
            }
        }
        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);
        }
 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);
 }
Example #4
0
        private void TranslateToILSourceTextProvider()
        {
            if (this.Engine.doFast)
            {
                return;
            }

            // If the field name doesn't match this name, then don't emit the stub for source
            // text provider. The function is a private method impl and there is no way to get
            // a handle to the function. i.e. name="Bar", field.name="InterfaceA.Bar"
            if (0 != String.Compare(this.name, this.field.Name, StringComparison.Ordinal))
            {
                return;
            }

            StringBuilder sb = new StringBuilder(this.func.ToString());
            JSMemberField mf = ((JSMemberField)this.field).nextOverload;

            while (mf != null)
            {
                mf.metaData = this;
                sb.Append('\n');
                sb.Append(mf.value.ToString());
                mf = mf.nextOverload;
            }
            MethodAttributes attr = MethodAttributes.Public | MethodAttributes.Static;
            MethodBuilder    mb   = ((ClassScope)(this.func.enclosing_scope)).GetTypeBuilder().DefineMethod(this.name + " source", attr, Typeob.String, new Type[0]);
            ILGenerator      il   = mb.GetILGenerator();

            il.Emit(OpCodes.Ldstr, sb.ToString());
            il.Emit(OpCodes.Ret);
        }
 internal JSMemberField AddOverload(FunctionObject func, FieldAttributes attributeFlags)
 {
     JSMemberField nextOverload = this;
     while (nextOverload.nextOverload != null)
     {
         nextOverload = nextOverload.nextOverload;
     }
     JSMemberField field2 = nextOverload.nextOverload = new JSMemberField((ClassScope) base.obj, this.Name, func, attributeFlags);
     field2.type = base.type;
     return field2;
 }
Example #6
0
        internal JSMemberField[] GetMemberFields()
        {
            int n = this.field_table.Count;

            JSMemberField[] result = new JSMemberField[n];
            for (int i = 0; i < n; i++)
            {
                result[i] = (JSMemberField)this.field_table[i];
            }
            return(result);
        }
        internal JSMemberField[] GetMemberFields()
        {
            int count = base.field_table.Count;

            JSMemberField[] fieldArray = new JSMemberField[count];
            for (int i = 0; i < count; i++)
            {
                fieldArray[i] = (JSMemberField)base.field_table[i];
            }
            return(fieldArray);
        }
Example #8
0
        internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs)
        {
            JSMemberField field = this;

            while (field != null)
            {
                MethodInfo meth = ((JSMemberField)field).GetAsMethod(scope);
                if (meth.IsStatic)
                {
                    if ((attrs & BindingFlags.Static) == 0)
                    {
                        goto next;
                    }
                }
                else
                {
                    if ((attrs & BindingFlags.Instance) == 0)
                    {
                        goto next;
                    }
                }
                if (meth.IsPublic)
                {
                    if ((attrs & BindingFlags.Public) == 0)
                    {
                        goto next;
                    }
                }
                else
                {
                    if ((attrs & BindingFlags.NonPublic) == 0)
                    {
                        goto next;
                    }
                }
                mems.Add(meth);
next:
                field = field.nextOverload;
            }
            if ((attrs & BindingFlags.DeclaredOnly) != 0 && (attrs & BindingFlags.FlattenHierarchy) == 0)
            {
                return;
            }
            IReflect superClass = scope.GetSuperType();

            MemberInfo[] supMembers = superClass.GetMember(this.Name, attrs & ~BindingFlags.DeclaredOnly);
            foreach (MemberInfo supMember in supMembers)
            {
                if (supMember.MemberType == MemberTypes.Method)
                {
                    mems.Add(supMember);
                }
            }
        }
Example #9
0
        internal JSMemberField AddOverload(FunctionObject func, FieldAttributes attributeFlags)
        {
            JSMemberField nextOverload = this;

            while (nextOverload.nextOverload != null)
            {
                nextOverload = nextOverload.nextOverload;
            }
            JSMemberField field2 = nextOverload.nextOverload = new JSMemberField((ClassScope)base.obj, this.Name, func, attributeFlags);

            field2.type = base.type;
            return(field2);
        }
Example #10
0
        internal JSMemberField AddOverload(FunctionObject func, FieldAttributes attributeFlags)
        {
            JSMemberField last = this;

            while (last.nextOverload != null)
            {
                last = last.nextOverload;
            }
            JSMemberField f = last.nextOverload = new JSMemberField((ClassScope)this.obj, this.Name, func, attributeFlags);

            f.type = this.type;
            return(f);
        }
Example #11
0
        internal override AST PartiallyEvaluate()
        {
            if (!(this.classob.GetParent() is GlobalScope))
            {
                return(this); //The class has already been partially evaluated
            }
            this.baseType.PartiallyEvaluate();
            IReflect ir = this.baseType.ToIReflect();
            Type     bt = null;

            if (!(ir is Type) || !Convert.IsPrimitiveIntegerType(bt = (Type)ir))
            {
                this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
                this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
                bt            = Typeob.Int32;
            }

            if (this.customAttributes != null)
            {
                this.customAttributes.PartiallyEvaluate();
            }

            if (this.NeedsToBeCheckedForCLSCompliance())
            {
                if (!TypeExpression.TypeIsCLSCompliant(ir))
                {
                    this.baseType.context.HandleError(JSError.NonCLSCompliantType);
                }
                this.CheckMemberNamesForCLSCompliance();
            }

            ScriptObject scope = this.enclosingScope;

            while (!(scope is GlobalScope) && !(scope is PackageScope))
            {
                scope = scope.GetParent();
            }
            this.classob.SetParent(new WithObject(scope, typeof(Enum), true));

            Globals.ScopeStack.Push(this.classob);
            try{
                foreach (FieldInfo f in this.fields)
                {
                    JSMemberField field = (JSMemberField)f;
                    ((EnumWrapper)field.value).CoerceToBaseType(bt, field.originalContext);
                }
            }finally{
                Globals.ScopeStack.Pop();
            }
            return(this);
        }
 internal override AST PartiallyEvaluate()
 {
     if (base.classob.GetParent() is GlobalScope)
     {
         this.baseType.PartiallyEvaluate();
         IReflect reflect = this.baseType.ToIReflect();
         Type     bt      = null;
         if (!(reflect is Type) || !Microsoft.JScript.Convert.IsPrimitiveIntegerType(bt = (Type)reflect))
         {
             this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
             this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
             bt            = Typeob.Int32;
         }
         if (base.customAttributes != null)
         {
             base.customAttributes.PartiallyEvaluate();
         }
         if (base.NeedsToBeCheckedForCLSCompliance())
         {
             if (!TypeExpression.TypeIsCLSCompliant(reflect))
             {
                 this.baseType.context.HandleError(JSError.NonCLSCompliantType);
             }
             base.CheckMemberNamesForCLSCompliance();
         }
         ScriptObject enclosingScope = base.enclosingScope;
         while (!(enclosingScope is GlobalScope) && !(enclosingScope is PackageScope))
         {
             enclosingScope = enclosingScope.GetParent();
         }
         base.classob.SetParent(new WithObject(enclosingScope, Typeob.Enum, true));
         base.Globals.ScopeStack.Push(base.classob);
         try
         {
             JSMemberField[] fields = base.fields;
             for (int i = 0; i < fields.Length; i++)
             {
                 FieldInfo     info  = fields[i];
                 JSMemberField field = (JSMemberField)info;
                 ((DeclaredEnumValue)field.value).CoerceToBaseType(bt, field.originalContext);
             }
         }
         finally
         {
             base.Globals.ScopeStack.Pop();
         }
     }
     return(this);
 }
Example #13
0
 private void TranslateToILSourceTextProvider()
 {
     if (!base.Engine.doFast && (string.Compare(this.name, this.field.Name, StringComparison.Ordinal) == 0))
     {
         StringBuilder builder = new StringBuilder(this.func.ToString());
         for (JSMemberField field = ((JSMemberField)this.field).nextOverload; field != null; field = field.nextOverload)
         {
             field.metaData = this;
             builder.Append('\n');
             builder.Append(field.value.ToString());
         }
         MethodAttributes attributes  = MethodAttributes.Static | MethodAttributes.Public;
         ILGenerator      iLGenerator = ((ClassScope)this.func.enclosing_scope).GetTypeBuilder().DefineMethod(this.name + " source", attributes, Typeob.String, new Type[0]).GetILGenerator();
         iLGenerator.Emit(OpCodes.Ldstr, builder.ToString());
         iLGenerator.Emit(OpCodes.Ret);
     }
 }
Example #14
0
        internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs)
        {
            for (JSMemberField field = this; field != null; field = field.nextOverload)
            {
                MethodInfo asMethod = field.GetAsMethod(scope);
                if (asMethod.IsStatic)
                {
                    if ((attrs & BindingFlags.Static) != BindingFlags.Default)
                    {
                        goto Label_0020;
                    }
                    continue;
                }
                if ((attrs & BindingFlags.Instance) == BindingFlags.Default)
                {
                    continue;
                }
Label_0020:
                if (asMethod.IsPublic)
                {
                    if ((attrs & BindingFlags.Public) != BindingFlags.Default)
                    {
                        goto Label_0036;
                    }
                    continue;
                }
                if ((attrs & BindingFlags.NonPublic) == BindingFlags.Default)
                {
                    continue;
                }
Label_0036:
                mems.Add(asMethod);
            }
            if (((attrs & BindingFlags.DeclaredOnly) == BindingFlags.Default) || ((attrs & BindingFlags.FlattenHierarchy) != BindingFlags.Default))
            {
                foreach (MemberInfo info2 in scope.GetSuperType().GetMember(this.Name, attrs & ~BindingFlags.DeclaredOnly))
                {
                    if (info2.MemberType == MemberTypes.Method)
                    {
                        mems.Add(info2);
                    }
                }
            }
        }
Example #15
0
 internal void CheckOverloadsForDuplicates()
 {
     for (JSMemberField field = this; field != null; field = field.nextOverload)
     {
         FunctionObject obj2 = field.value as FunctionObject;
         if (obj2 == null)
         {
             return;
         }
         for (JSMemberField field2 = field.nextOverload; field2 != null; field2 = field2.nextOverload)
         {
             FunctionObject obj3 = (FunctionObject)field2.value;
             if ((obj3.implementedIface == obj2.implementedIface) && Class.ParametersMatch(obj3.parameter_declarations, obj2.parameter_declarations))
             {
                 obj2.funcContext.HandleError(JSError.DuplicateMethod);
                 obj3.funcContext.HandleError(JSError.DuplicateMethod);
                 break;
             }
         }
     }
 }
Example #16
0
        private void TranslateToILSourceTextProvider()
        {
            if (this.Engine.doFast)
            {
                return;
            }
            StringBuilder sb = new StringBuilder(this.func.ToString());
            JSMemberField mf = ((JSMemberField)this.field).nextOverload;

            while (mf != null)
            {
                mf.metaData = this;
                sb.Append('\n');
                sb.Append(mf.value.ToString());
                mf = mf.nextOverload;
            }
            MethodAttributes attr = MethodAttributes.Public | MethodAttributes.Static;
            MethodBuilder    mb   = ((ClassScope)(this.func.enclosing_scope)).GetTypeBuilder().DefineMethod(this.name + " source", attr, Typeob.String, new Type[0]);
            ILGenerator      il   = mb.GetILGenerator();

            il.Emit(OpCodes.Ldstr, sb.ToString());
            il.Emit(OpCodes.Ret);
        }
Example #17
0
        internal ConstructorInfo[] GetAsConstructors(object proto)
        {
            JSMemberField nextOverload = this;
            int           num          = 0;

            while (nextOverload != null)
            {
                nextOverload = nextOverload.nextOverload;
                num++;
            }
            ConstructorInfo[] infoArray = new ConstructorInfo[num];
            nextOverload = this;
            num          = 0;
            while (nextOverload != null)
            {
                FunctionObject cons = (FunctionObject)nextOverload.value;
                cons.isConstructor = true;
                cons.proto         = proto;
                infoArray[num++]   = new JSConstructor(cons);
                nextOverload       = nextOverload.nextOverload;
            }
            return(infoArray);
        }
Example #18
0
        internal ConstructorInfo[] GetAsConstructors(Object proto)
        {
            JSMemberField field = this;
            int           n     = 0;

            while (field != null)
            {
                field = field.nextOverload;
                n++;
            }
            ConstructorInfo[] result = new ConstructorInfo[n];
            field = this;
            n     = 0;
            while (field != null)
            {
                Debug.Assert(field.IsLiteral);
                FunctionObject func = (FunctionObject)field.value;
                func.isConstructor = true;
                func.proto         = proto;
                result[n++]        = new JSConstructor(func);
                field = field.nextOverload;
            }
            return(result);
        }
Example #19
0
 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]);
 }
Example #20
0
 private void CheckFieldDeclarationConsistency(JSMemberField field){
   Object index = this.firstIndex[field.Name];
   if (index == null) return; //There is no super class member with the same name as the field
   for (int i = (int)index, n = this.superMembers.Length; i < n; i++){
     Object supMem = this.superMembers[i];
     if (!(supMem is MemberInfo)) return;
     MemberInfo member = (MemberInfo)supMem;
     if (!member.Name.Equals(field.Name)) return; 
     if (this.CanSee(member)){
       String supMemberName = this.GetFullNameFor(member);
       field.originalContext.HandleError(JSError.HidesParentMember, supMemberName, this.IsInTheSameCompilationUnit(member));
       return;
     }
   }
 }
Example #21
0
 internal JSMemberField(ClassScope obj, String name, Object value, FieldAttributes attributeFlags)
   : base(name, obj, attributeFlags) {
   this.value = value;
   this.nextOverload = null;
 }
Example #22
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));
        }
 internal ConstructorInfo[] GetAsConstructors(object proto)
 {
     JSMemberField nextOverload = this;
     int num = 0;
     while (nextOverload != null)
     {
         nextOverload = nextOverload.nextOverload;
         num++;
     }
     ConstructorInfo[] infoArray = new ConstructorInfo[num];
     nextOverload = this;
     num = 0;
     while (nextOverload != null)
     {
         FunctionObject cons = (FunctionObject) nextOverload.value;
         cons.isConstructor = true;
         cons.proto = proto;
         infoArray[num++] = new JSConstructor(cons);
         nextOverload = nextOverload.nextOverload;
     }
     return infoArray;
 }
Example #24
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));
        }
Example #25
0
 internal JSMemberField[] GetMemberFields(){
   int n = this.field_table.Count;
   JSMemberField[] result = new JSMemberField[n];
   for (int i = 0; i < n; i++) result[i] = (JSMemberField)this.field_table[i];
   return result;
 }
Example #26
0
 internal JSMemberField(ClassScope obj, String name, Object value, FieldAttributes attributeFlags)
     : base(name, obj, attributeFlags)
 {
     this.value        = value;
     this.nextOverload = null;
 }
        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);
        }
 internal JSMemberField[] GetMemberFields()
 {
     int count = base.field_table.Count;
     JSMemberField[] fieldArray = new JSMemberField[count];
     for (int i = 0; i < count; i++)
     {
         fieldArray[i] = (JSMemberField) base.field_table[i];
     }
     return fieldArray;
 }