Наследование: Microsoft.JScript.ActivationObject, IComparable
Пример #1
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);
 }
 internal JSExpandoIndexerMethod(ClassScope classScope, bool isGetter) : base(null)
 {
     this.isGetter = isGetter;
     this.classScope = classScope;
     this.GetterParams = new ParameterInfo[] { new ParameterDeclaration(Typeob.String, "field") };
     this.SetterParams = new ParameterInfo[] { new ParameterDeclaration(Typeob.String, "field"), new ParameterDeclaration(Typeob.Object, "value") };
 }
 internal void AddClassesExcluding(ClassScope excludedClass, string name, ArrayList result)
 {
     ArrayList list = new ArrayList();
     foreach (MemberInfo info in this.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
     {
         if ((info is JSVariableField) && ((JSVariableField) info).IsLiteral)
         {
             object obj2 = ((JSVariableField) info).value;
             if (obj2 is ClassScope)
             {
                 ClassScope other = (ClassScope) obj2;
                 if (((other.name == info.Name) && ((excludedClass == null) || !excludedClass.IsSameOrDerivedFrom(other))) && (other.GetMember(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0))
                 {
                     list.Add(other);
                 }
             }
         }
     }
     if (list.Count != 0)
     {
         ClassScope[] array = new ClassScope[list.Count];
         list.CopyTo(array);
         Array.Sort<ClassScope>(array);
         result.AddRange(array);
     }
 }
 internal JSExpandoIndexerMethod(ClassScope classScope, bool isGetter)
   : base(null){ //The object is never used, but it is convenient to have the field on JSMethod.
   this.isGetter = isGetter;
   this.classScope = classScope;
   
   this.GetterParams= new ParameterInfo[]{new ParameterDeclaration(Typeob.String, "field")};
   this.SetterParams = new ParameterInfo[]{new ParameterDeclaration(Typeob.String, "field"), 
             new ParameterDeclaration(Typeob.Object, "value")};
 }
 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);
             }
         }
     }
 }
Пример #6
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);
                    }
                }
            }
        }
        internal bool IsSameOrDerivedFrom(ClassScope other)
        {
            if (this == other)
            {
                return(true);
            }
            if (other.owner.isInterface)
            {
                return(this.ImplementsInterface(other));
            }
            if (base.parent == null)
            {
                return(false);
            }
            this.owner.PartiallyEvaluate();
            object obj2 = ((WithObject)base.parent).contained_object;

            return((obj2 is ClassScope) && ((ClassScope)obj2).IsSameOrDerivedFrom(other));
        }
Пример #8
0
      //Adds a list of classes to result. Superclasses always follow derived classes.

      internal void AddClassesExcluding(ClassScope excludedClass, String name, ArrayList result){
        ArrayList eligibleClasses = new ArrayList();
        foreach (MemberInfo member in this.GetMembers(BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)){
          if (member is JSVariableField && ((JSVariableField)member).IsLiteral){
            Object val = ((JSVariableField)member).value;
            if (val is ClassScope){
              ClassScope csc = (ClassScope)val;
              if (csc.name != member.Name) continue;
              if (excludedClass == null || !excludedClass.IsSameOrDerivedFrom(csc))
                if (csc.GetMember(name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly).Length > 0)
                  eligibleClasses.Add(csc);
            }
          }
        }
        if (eligibleClasses.Count == 0) return;
        ClassScope[] classes = new ClassScope[eligibleClasses.Count]; eligibleClasses.CopyTo(classes);
        Array.Sort(classes);
        result.AddRange(classes);
      }
Пример #9
0
 internal override AST PartiallyEvaluate()
 {
     if (this.ifaceId != null)
     {
         this.ifaceId.PartiallyEvaluate();
         this.func.implementedIface = this.ifaceId.ToIReflect();
         Type       t   = this.func.implementedIface as Type;
         ClassScope csc = this.func.implementedIface as ClassScope;
         if (t != null && !t.IsInterface || csc != null && !csc.owner.isInterface)
         {
             this.ifaceId.context.HandleError(JSError.NeedInterface);
             this.func.implementedIface = null;
         }
         if ((this.func.attributes & MethodAttributes.Abstract) != 0)
         {
             this.func.funcContext.HandleError(JSError.AbstractCannotBePrivate);
         }
     }
     else if (this.declaringObject != null)
     {
         this.declaringObject.PartiallyEvaluateAsCallable();
     }
     this.func.PartiallyEvaluate();
     if (this.inFastScope && this.func.isExpandoMethod && this.field != null && this.field.type != null)
     {
         this.field.type.expression = new ConstantWrapper(Typeob.ScriptFunction, null);
     }
     if ((this.func.attributes & MethodAttributes.Abstract) != 0 &&
         !((ClassScope)this.func.enclosing_scope).owner.isAbstract)
     {
         ((ClassScope)this.func.enclosing_scope).owner.attributes |= TypeAttributes.Abstract;
         ((ClassScope)this.func.enclosing_scope).owner.context.HandleError(JSError.CannotBeAbstract, this.name);
     }
     if (this.enclosingProperty != null)
     {
         if (!this.enclosingProperty.GetterAndSetterAreConsistent())
         {
             this.context.HandleError(JSError.GetAndSetAreInconsistent);
         }
     }
     return(this);
 }
        internal bool IsAccessibleFrom(ScriptObject scope)
        {
            while ((scope != null) && !(scope is ClassScope))
            {
                scope = scope.GetParent();
            }
            ClassScope other = (ClassScope)this.cons.enclosing_scope;

            if (base.IsPrivate)
            {
                if (scope == null)
                {
                    return(false);
                }
                if (scope != other)
                {
                    return(((ClassScope)scope).IsNestedIn(other, false));
                }
                return(true);
            }
            if (base.IsFamily)
            {
                if (scope == null)
                {
                    return(false);
                }
                if (!((ClassScope)scope).IsSameOrDerivedFrom(other))
                {
                    return(((ClassScope)scope).IsNestedIn(other, false));
                }
                return(true);
            }
            if ((base.IsFamilyOrAssembly && (scope != null)) && (((ClassScope)scope).IsSameOrDerivedFrom(other) || ((ClassScope)scope).IsNestedIn(other, false)))
            {
                return(true);
            }
            if (scope == null)
            {
                return(other.GetPackage() == null);
            }
            return(other.GetPackage() == ((ClassScope)scope).GetPackage());
        }
Пример #11
0
 internal bool IsNestedIn(ClassScope other, bool isStatic)
 {
     if (this.parent == null)
     {
         return(false);
     }
     this.owner.PartiallyEvaluate();
     if (this.owner.enclosingScope == other)
     {
         return(isStatic || !this.owner.isStatic);
     }
     else if (this.owner.enclosingScope is ClassScope)
     {
         return(((ClassScope)this.owner.enclosingScope).IsNestedIn(other, isStatic));
     }
     else
     {
         return(false);
     }
 }
Пример #12
0
        internal bool IsAccessibleFrom(ScriptObject scope) //Never call this if the member is public
        {
            while (scope != null && !(scope is ClassScope))
            {
                scope = scope.GetParent();
            }
            ClassScope thisScope = (ClassScope)this.cons.enclosing_scope;

            if (this.IsPrivate)
            {
                if (scope == null)
                {
                    return(false);
                }
                else
                {
                    return(scope == thisScope || ((ClassScope)scope).IsNestedIn(thisScope, false));
                }
            }
            else if (this.IsFamily)
            {
                if (scope == null)
                {
                    return(false);
                }
                else
                {
                    return(((ClassScope)scope).IsSameOrDerivedFrom(thisScope) || ((ClassScope)scope).IsNestedIn(thisScope, false));
                }
            }
            else //if (this.IsAssembly)
            if (scope == null) //Code is not in a class and hence it is in the default package
            {
                return(thisScope.GetPackage() == null); //null indicates default package
            }
            else
            {
                return(thisScope.GetPackage() == ((ClassScope)scope).GetPackage());
            }
        }
Пример #13
0
        public override String ToString()
        {
            Type elemType = this.elementType as Type;

            if (elemType != null)
            {
                return(elemType.FullName + TypedArray.ToRankString(this.rank));
            }
            ClassScope csc = this.elementType as ClassScope;

            if (csc != null)
            {
                return(csc.GetFullName() + TypedArray.ToRankString(this.rank));
            }
            TypedArray tarr = this.elementType as TypedArray;

            if (tarr != null)
            {
                return(tarr.ToString() + TypedArray.ToRankString(this.rank));
            }
            return(Convert.ToType(this.elementType).FullName + TypedArray.ToRankString(this.rank));
        }
Пример #14
0
        internal override IReflect InferType(JSField inference_target)
        {
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.method));
            if (this.method != null)
            {
                ParameterInfo[] pars = this.method.GetParameters();
                if (pars == null || pars.Length == 0)
                {
                    return(this.method.ReturnType);
                }
                else
                {
                    return(pars[0].ParameterType);
                }
            }
            ScriptObject top = Globals.ScopeStack.Peek();

            while (top is WithObject)
            {
                top = top.GetParent();
            }
            if (top is GlobalScope)
            {
                return(top);
            }
            else if (top is FunctionScope && ((FunctionScope)top).isMethod)
            {
                ClassScope csc = (ClassScope)((FunctionScope)top).owner.enclosing_scope;
                if (this.isSuper)
                {
                    return(csc.GetSuperType());
                }
                else
                {
                    return(csc);
                }
            }
            return(Typeob.Object);
        }
Пример #15
0
        public override string ToString()
        {
            Type elementType = this.elementType as Type;

            if (elementType != null)
            {
                return(elementType.FullName + ToRankString(this.rank));
            }
            ClassScope scope = this.elementType as ClassScope;

            if (scope != null)
            {
                return(scope.GetFullName() + ToRankString(this.rank));
            }
            TypedArray array = this.elementType as TypedArray;

            if (array != null)
            {
                return(array.ToString() + ToRankString(this.rank));
            }
            return(Microsoft.JScript.Convert.ToType(this.elementType).FullName + ToRankString(this.rank));
        }
        private void ConvertClassScopesAndEnumWrappers(ArrayList vals)
        {
            int num   = 0;
            int count = vals.Count;

            while (num < count)
            {
                ClassScope scope = vals[num] as ClassScope;
                if (scope != null)
                {
                    vals[num] = scope.GetTypeBuilder();
                }
                else
                {
                    EnumWrapper wrapper = vals[num] as EnumWrapper;
                    if (wrapper != null)
                    {
                        vals[num] = wrapper.ToNumericValue();
                    }
                }
                num++;
            }
        }
Пример #17
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;
         }
     }
 }
Пример #18
0
 internal bool IsSameOrDerivedFrom(ClassScope other){
   if (this == other)
     return true;
   if (other.owner.isInterface)
     return this.ImplementsInterface(other);
   if (this.parent == null)
     return false;
   this.owner.PartiallyEvaluate();
   Object supertype = ((WithObject)this.parent).contained_object;
   if (supertype is ClassScope)
     return ((ClassScope)supertype).IsSameOrDerivedFrom(other);
   else
     return false;
 }
Пример #19
0
 internal bool IsNestedIn(ClassScope other, bool isStatic){
   if (this.parent == null)
     return false;
   this.owner.PartiallyEvaluate();
   if (this.owner.enclosingScope == other)
     return isStatic || !this.owner.isStatic;
   else if (this.owner.enclosingScope is ClassScope)
     return ((ClassScope)this.owner.enclosingScope).IsNestedIn(other, isStatic);
   else
     return false;
 }
Пример #20
0
        internal override AST PartiallyEvaluate()
        {
            if (this.alreadyPartiallyEvaluated)
            {
                return(this);
            }
            this.alreadyPartiallyEvaluated = true;
            if (this.inBrackets && this.AllParamsAreMissing())
            {
                if (this.isConstructor)
                {
                    this.args.context.HandleError(JSError.TypeMismatch);
                }
                return(new ConstantWrapper(new TypedArray(((TypeExpression) new TypeExpression(this.func).PartiallyEvaluate()).ToIReflect(), this.args.count + 1), base.context));
            }
            this.func = this.func.PartiallyEvaluateAsCallable();
            this.args = (ASTList)this.args.PartiallyEvaluate();
            IReflect[] argIRs = this.ArgIRs();
            this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets);
            if ((!this.isConstructor && !this.inBrackets) && ((this.func is Binding) && (this.args.count == 1)))
            {
                Binding func = (Binding)this.func;
                if (func.member is Type)
                {
                    Type            member  = (Type)func.member;
                    ConstantWrapper wrapper = this.args[0] as ConstantWrapper;
                    if (wrapper != null)
                    {
                        try
                        {
                            if ((wrapper.value == null) || (wrapper.value is DBNull))
                            {
                                return(this);
                            }
                            if (wrapper.isNumericLiteral && (((member == Typeob.Decimal) || (member == Typeob.Int64)) || ((member == Typeob.UInt64) || (member == Typeob.Single))))
                            {
                                return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.context.GetCode(), member, true), base.context));
                            }
                            return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.Evaluate(), member, true), base.context));
                        }
                        catch
                        {
                            wrapper.context.HandleError(JSError.TypeMismatch);
                            goto Label_0354;
                        }
                    }
                    if (!Binding.AssignmentCompatible(member, this.args[0], argIRs[0], false))
                    {
                        this.args[0].context.HandleError(JSError.ImpossibleConversion);
                    }
                }
                else if (func.member is JSVariableField)
                {
                    JSVariableField field = (JSVariableField)func.member;
                    if (field.IsLiteral)
                    {
                        if (field.value is ClassScope)
                        {
                            ClassScope scope = (ClassScope)field.value;
                            IReflect   underlyingTypeIfEnum = scope.GetUnderlyingTypeIfEnum();
                            if (underlyingTypeIfEnum != null)
                            {
                                if ((!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], underlyingTypeIfEnum) && !Microsoft.JScript.Convert.IsPromotableTo(underlyingTypeIfEnum, argIRs[0])) && ((argIRs[0] != Typeob.String) || (underlyingTypeIfEnum == scope)))
                                {
                                    this.args[0].context.HandleError(JSError.ImpossibleConversion);
                                }
                            }
                            else if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], scope) && !Microsoft.JScript.Convert.IsPromotableTo(scope, argIRs[0]))
                            {
                                this.args[0].context.HandleError(JSError.ImpossibleConversion);
                            }
                        }
                        else if (field.value is TypedArray)
                        {
                            TypedArray array = (TypedArray)field.value;
                            if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], array) && !Microsoft.JScript.Convert.IsPromotableTo(array, argIRs[0]))
                            {
                                this.args[0].context.HandleError(JSError.ImpossibleConversion);
                            }
                        }
                    }
                }
            }
Label_0354:
            return(this);
        }
Пример #21
0
 internal JSExpandoIndexerMethod(ClassScope classScope, bool isGetter)
     : base(null) //The object is never used, but it is convenient to have the field on JSMethod.
 {
     this.isGetter   = isGetter;
     this.classScope = classScope;
 }
Пример #22
0
 internal Class(Context context, AST id, TypeExpression superTypeExpression, TypeExpression[] interfaces, Block body, 
   FieldAttributes attributes, bool isAbstract, bool isFinal, bool isStatic, bool isInterface, CustomAttributeList customAttributes)
   : base(context) {
   this.name = id.ToString();
   this.superTypeExpression = superTypeExpression;
   this.interfaces = interfaces;
   this.body = body;
   this.enclosingScope = (ScriptObject)Globals.ScopeStack.Peek(1);
   this.attributes = TypeAttributes.Class|TypeAttributes.Serializable;
   this.SetAccessibility(attributes);
   if (isAbstract)
     this.attributes |= TypeAttributes.Abstract;
   this.isAbstract = isAbstract || isInterface;
   this.isAlreadyPartiallyEvaluated = false;
   if (isFinal)
     this.attributes |= TypeAttributes.Sealed;
   if (isInterface)
     this.attributes |= TypeAttributes.Interface | TypeAttributes.Abstract;
   this.isCooked = false;
   this.cookedType = null;
   this.isExpando = false;
   this.isInterface = isInterface;
   this.isStatic = isStatic;
   this.needsEngine = !isInterface;
   this.validOn = (AttributeTargets)0;
   this.allowMultiple = true;
   this.classob = (ClassScope)Globals.ScopeStack.Peek();
   this.classob.name = this.name;
   this.classob.owner = this;
   this.implicitDefaultConstructor = null;
   if (!isInterface && !(this is EnumDeclaration))
     this.SetupConstructors();
   this.EnterNameIntoEnclosingScopeAndGetOwnField(id, isStatic);
   this.fields = this.classob.GetMemberFields();
   this.superClass = null;
   this.superIR = null;
   this.superMembers = null;
   this.firstIndex = null;
   this.fieldInitializer = null;
   this.customAttributes = customAttributes;
   this.clsCompliance = CLSComplianceSpec.NotAttributed;
   this.generateCodeForExpando = false;
   this.expandoItemProp = null;
   this.getHashTableMethod = null;
   this.getItem = null;
   this.setItem = null;
 }
 internal DeclaredEnumValue(object value, string name, ClassScope classScope)
 {
     this._name       = name;
     this._classScope = classScope;
     this._value      = value;
 }
Пример #24
0
 internal DeclaredEnumValue(Object value, String name, ClassScope classScope){
   this._name = name;
   this._classScope = classScope;
   this._value = value;
 }
Пример #25
0
 internal override AST PartiallyEvaluate()
 {
     if (this.alreadyPartiallyEvaluated)
     {
         return(this);
     }
     this.alreadyPartiallyEvaluated = true;
     if (this.inBrackets && this.AllParamsAreMissing())
     {
         if (this.isConstructor)
         {
             this.args.context.HandleError(JSError.TypeMismatch);
         }
         IReflect ir = ((TypeExpression)(new TypeExpression(this.func)).PartiallyEvaluate()).ToIReflect();
         return(new ConstantWrapper(new TypedArray(ir, this.args.count + 1), this.context));
     }
     this.func = this.func.PartiallyEvaluateAsCallable();
     this.args = (ASTList)this.args.PartiallyEvaluate();
     IReflect[] argIRs = this.ArgIRs();
     this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets);
     if (!this.isConstructor && !this.inBrackets && this.func is Binding && this.args.count == 1)
     {
         Binding b = (Binding)this.func;
         if (b.member is Type)
         {
             Type            t    = (Type)b.member;
             ConstantWrapper arg0 = this.args[0] as ConstantWrapper;
             if (arg0 != null)
             {
                 try{
                     if (arg0.value == null || arg0.value is DBNull)
                     {
                         return(this);
                     }
                     else if (arg0.isNumericLiteral && (t == Typeob.Decimal || t == Typeob.Int64 || t == Typeob.UInt64 || t == Typeob.Single))
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.context.GetCode(), t, true), this.context));
                     }
                     else
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.Evaluate(), t, true), this.context));
                     }
                 }catch {
                     arg0.context.HandleError(JSError.TypeMismatch);
                 }
             }
             else
             {
                 if (!Binding.AssignmentCompatible(t, this.args[0], argIRs[0], false))
                 {
                     this.args[0].context.HandleError(JSError.ImpossibleConversion);
                 }
             }
         }
         else if (b.member is JSVariableField)
         {
             JSVariableField field = (JSVariableField)b.member;
             if (field.IsLiteral)
             {
                 if (field.value is ClassScope)
                 {
                     ClassScope csc = (ClassScope)field.value;
                     IReflect   ut  = csc.GetUnderlyingTypeIfEnum();
                     if (ut != null)
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], ut) && !Convert.IsPromotableTo(ut, argIRs[0]) && (argIRs[0] != Typeob.String || ut == csc))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                     else
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], csc) && !Convert.IsPromotableTo(csc, argIRs[0]))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                 }
                 else if (field.value is TypedArray)
                 {
                     TypedArray ta = (TypedArray)field.value;
                     if (!Convert.IsPromotableTo(argIRs[0], ta) && !Convert.IsPromotableTo(ta, argIRs[0]))
                     {
                         this.args[0].context.HandleError(JSError.ImpossibleConversion);
                     }
                 }
             }
         }
     }
     return(this);
 }
Пример #26
0
 private void TranslateToILObjectForMember(ILGenerator il, Type obType, bool noValue, MemberInfo mem)
 {
     this.thereIsAnObjectOnTheStack = true;
     if (mem is IWrappedMember)
     {
         object wrappedObject = ((IWrappedMember)mem).GetWrappedObject();
         if (wrappedObject is LenientGlobalObject)
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
         }
         else if ((wrappedObject is Type) || (wrappedObject is ClassScope))
         {
             if (obType.IsAssignableFrom(Typeob.Type))
             {
                 new ConstantWrapper(wrappedObject, null).TranslateToIL(il, Typeob.Type);
             }
             else
             {
                 ScriptObject parent = base.Globals.ScopeStack.Peek();
                 while ((parent is WithObject) || (parent is BlockScope))
                 {
                     parent = parent.GetParent();
                 }
                 if (parent is FunctionScope)
                 {
                     if (((FunctionScope)parent).owner.isMethod)
                     {
                         il.Emit(OpCodes.Ldarg_0);
                     }
                     else
                     {
                         base.EmitILToLoadEngine(il);
                         il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                         parent = base.Globals.ScopeStack.Peek();
                         while ((parent is WithObject) || (parent is BlockScope))
                         {
                             il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                             parent = parent.GetParent();
                         }
                         il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                         il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                     }
                 }
                 else if (parent is ClassScope)
                 {
                     il.Emit(OpCodes.Ldarg_0);
                 }
                 for (parent = base.Globals.ScopeStack.Peek(); parent != null; parent = parent.GetParent())
                 {
                     ClassScope scope = parent as ClassScope;
                     if (scope != null)
                     {
                         if (scope.IsSameOrDerivedFrom(obType))
                         {
                             return;
                         }
                         il.Emit(OpCodes.Ldfld, scope.outerClassField);
                     }
                 }
             }
         }
         else
         {
             this.TranslateToILDefaultThisObject(il, this.lexLevel);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, obType);
         }
     }
     else
     {
         ScriptObject obj5 = base.Globals.ScopeStack.Peek();
         while ((obj5 is WithObject) || (obj5 is BlockScope))
         {
             obj5 = obj5.GetParent();
         }
         if (!(obj5 is FunctionScope) || ((FunctionScope)obj5).owner.isMethod)
         {
             il.Emit(OpCodes.Ldarg_0);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope3 = (ClassScope)obj5;
                     if (scope3.IsSameOrDerivedFrom(obType))
                     {
                         return;
                     }
                     il.Emit(OpCodes.Ldfld, scope3.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
         }
         else
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
             obj5 = base.Globals.ScopeStack.Peek();
             while ((obj5 is WithObject) || (obj5 is BlockScope))
             {
                 il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, Typeob.StackFrame);
             il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope2 = (ClassScope)obj5;
                     if (scope2.IsSameOrDerivedFrom(obType))
                     {
                         break;
                     }
                     il.Emit(OpCodes.Castclass, scope2.GetTypeBuilder());
                     il.Emit(OpCodes.Ldfld, scope2.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, obType);
         }
     }
 }
Пример #27
0
 internal JSExpandoIndexerMethod(ClassScope classScope, bool isGetter)
   : base(null){ //The object is never used, but it is convenient to have the field on JSMethod.
   this.isGetter = isGetter;
   this.classScope = classScope;
 }
Пример #28
0
 internal JSMemberField(ClassScope obj, String name, Object value, FieldAttributes attributeFlags)
     : base(name, obj, attributeFlags)
 {
     this.value        = value;
     this.nextOverload = null;
 }
 internal bool IsSameOrDerivedFrom(ClassScope other)
 {
     if (this == other)
     {
         return true;
     }
     if (other.owner.isInterface)
     {
         return this.ImplementsInterface(other);
     }
     if (base.parent == null)
     {
         return false;
     }
     this.owner.PartiallyEvaluate();
     object obj2 = ((WithObject) base.parent).contained_object;
     return ((obj2 is ClassScope) && ((ClassScope) obj2).IsSameOrDerivedFrom(other));
 }
Пример #30
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);
        }
Пример #31
0
 internal JSMemberField(ClassScope obj, String name, Object value, FieldAttributes attributeFlags)
   : base(name, obj, attributeFlags) {
   this.value = value;
   this.nextOverload = null;
 }
Пример #32
0
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] members = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                Object ob = Convert.ToObject2(this.rootObject.Evaluate(), this.Engine);
                if (ob == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope csc = ob as ClassScope;
                Type       t   = ob as Type;
                if (csc != null || t != null)
                {
                    //object is a type. Look for static members on the type only. If none are found, look for instance members on type Type.
                    if (csc != null)
                    {
                        this.members = members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        this.members = members = t.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (members.Length > 0)
                    {
                        return;             //found a binding
                    }
                    //Look for instance members on type Type
                    this.members = members = Typeob.Type.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                Namespace ns = ob as Namespace;
                if (ns != null)
                {
                    String fullname = ns.Name + "." + this.name;
                    csc = this.Engine.GetClass(fullname);
                    if (csc != null)
                    {
                        FieldAttributes attrs = FieldAttributes.Literal;
                        if ((csc.owner.attributes & TypeAttributes.Public) == 0)
                        {
                            attrs |= FieldAttributes.Private;
                        }
                        this.members = new MemberInfo[] { new JSGlobalField(null, this.name, csc, attrs) };
                        return;
                    }
                    else
                    {
                        t = this.Engine.GetType(fullname);
                        if (t != null)
                        {
                            this.members = new MemberInfo[] { t };
                            return;
                        }
                    }
                }
                else if (ob is MathObject || ob is ScriptFunction && !(ob is FunctionObject)) //It is a built in constructor function
                {
                    obType = (IReflect)ob;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);

            //Give up and go late bound if not enough is known about the object at compile time.
            if (obType == Typeob.Object && !this.isNonVirtual) //The latter provides for super in classes that extend System.Object
            {
                this.members = new MemberInfo[0];
                return;
            }

            Type ty = obType as Type;

            //Interfaces are weird, call a helper
            if (ty != null && ty.IsInterface)
            {
                this.members = JSBinder.GetInterfaceMembers(this.name, ty);
                return;
            }
            ClassScope cs = obType as ClassScope;

            if (cs != null && cs.owner.isInterface)
            {
                this.members = cs.owner.GetInterfaceMember(this.name);
                return;
            }

            //Now run up the inheritance chain until a member is found
            while (obType != null)
            {
                cs = obType as ClassScope;
                if (cs != null)
                {
                    //The FlattenHierachy flag here tells ClassScope to add in any overloads found on base classes
                    members = this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy);
                    if (members.Length > 0)
                    {
                        return;
                    }
                    obType = cs.GetSuperType();
                    continue;
                }
                ty = obType as Type;
                if (ty == null) //Dealing with the global scope via the this literal or with a built in object in fast mode
                {
                    this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                members = this.members = ty.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (members.Length > 0)
                {
                    MemberInfo mem = LateBinding.SelectMember(members);
                    if (mem == null)
                    {
                        //Found a method or methods. Need to add any overloads found in base classes.
                        //Do another lookup, this time with the DeclaredOnly flag cleared and asking only for methods
                        members = this.members = ty.GetMember(this.name, MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        if (members.Length == 0) //Dealing with an indexed property, ask again
                        {
                            this.members = ty.GetMember(this.name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        }
                    }
                    return;
                }
                obType = ty.BaseType;
            }
        }
Пример #33
0
 internal EnumWrapper(Object value, String name, ClassScope type){
   this.name = name;
   this.type = type;
   this.value = value;
 }
Пример #34
0
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] mems = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                object obj2 = Microsoft.JScript.Convert.ToObject2(this.rootObject.Evaluate(), base.Engine);
                if (obj2 == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope scope = obj2 as ClassScope;
                Type       type  = obj2 as Type;
                if ((scope != null) || (type != null))
                {
                    if (scope != null)
                    {
                        base.members = mems = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        base.members = mems = type.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (mems.Length <= 0)
                    {
                        base.members = mems = Typeob.Type.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                    }
                    return;
                }
                Namespace namespace2 = obj2 as Namespace;
                if (namespace2 != null)
                {
                    string className = namespace2.Name + "." + base.name;
                    scope = base.Engine.GetClass(className);
                    if (scope != null)
                    {
                        FieldAttributes literal = FieldAttributes.Literal;
                        if ((scope.owner.attributes & TypeAttributes.Public) == TypeAttributes.AnsiClass)
                        {
                            literal |= FieldAttributes.Private;
                        }
                        base.members = new MemberInfo[] { new JSGlobalField(null, base.name, scope, literal) };
                        return;
                    }
                    type = base.Engine.GetType(className);
                    if (type != null)
                    {
                        base.members = new MemberInfo[] { type };
                        return;
                    }
                }
                else if ((obj2 is MathObject) || ((obj2 is ScriptFunction) && !(obj2 is FunctionObject)))
                {
                    obType = (IReflect)obj2;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);
            if ((obType == Typeob.Object) && !base.isNonVirtual)
            {
                base.members = new MemberInfo[0];
            }
            else
            {
                Type t = obType as Type;
                if ((t != null) && t.IsInterface)
                {
                    base.members = JSBinder.GetInterfaceMembers(base.name, t);
                }
                else
                {
                    ClassScope scope2 = obType as ClassScope;
                    if ((scope2 != null) && scope2.owner.isInterface)
                    {
                        base.members = scope2.owner.GetInterfaceMember(base.name);
                    }
                    else
                    {
                        while (obType != null)
                        {
                            scope2 = obType as ClassScope;
                            if (scope2 != null)
                            {
                                mems = base.members = obType.GetMember(base.name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    return;
                                }
                                obType = scope2.GetSuperType();
                            }
                            else
                            {
                                t = obType as Type;
                                if (t == null)
                                {
                                    base.members = obType.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                                    return;
                                }
                                mems = base.members = t.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    if (LateBinding.SelectMember(mems) == null)
                                    {
                                        mems = base.members = t.GetMember(base.name, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        if (mems.Length == 0)
                                        {
                                            base.members = t.GetMember(base.name, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        }
                                    }
                                    return;
                                }
                                obType = t.BaseType;
                            }
                        }
                    }
                }
            }
        }
Пример #35
0
 internal EnumWrapper(Object value, String name, ClassScope type)
 {
     this.name  = name;
     this.type  = type;
     this.value = value;
 }
Пример #36
0
        private void TranslateToILObjectForMember(ILGenerator il, Type obType, bool noValue, MemberInfo mem)
        {
            this.thereIsAnObjectOnTheStack = true;
            if (mem is IWrappedMember)
            {
                Object obj = ((IWrappedMember)mem).GetWrappedObject();
                if (obj is LenientGlobalObject)
                {
                    this.EmitILToLoadEngine(il);
                    il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
                }
                else if (obj is Type || obj is ClassScope)
                {
                    if (obType.IsAssignableFrom(Typeob.Type))
                    {
                        (new ConstantWrapper(obj, null)).TranslateToIL(il, Typeob.Type);
                        return;
                    }
                    //this.name is the name of an instance member of the superclass of the class (or an outer class) in which this expression appears
                    //get class instance on stack
                    ScriptObject scope = Globals.ScopeStack.Peek();
                    while (scope is WithObject || scope is BlockScope)
                    {
                        scope = scope.GetParent();
                    }
                    if (scope is FunctionScope)
                    {
                        FunctionObject func = ((FunctionScope)scope).owner;
                        if (func.isMethod)
                        {
                            il.Emit(OpCodes.Ldarg_0);
                        }
                        else //Need to get the StackFrame.closureInstance on the stack
                        {
                            this.EmitILToLoadEngine(il);
                            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                            scope = this.Globals.ScopeStack.Peek();
                            while (scope is WithObject || scope is BlockScope)
                            {
                                il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                                scope = scope.GetParent();
                            }
                            il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                            il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        }
                    }
                    else if (scope is ClassScope)
                    {
                        il.Emit(OpCodes.Ldarg_0); //Inside instance initializer
                    }

                    //If dealing with a member of an outer class, get the outer class instance on the stack
                    scope = Globals.ScopeStack.Peek();
                    while (scope != null)
                    {
                        ClassScope csc = scope as ClassScope;
                        if (csc != null) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                        {
                            if (csc.IsSameOrDerivedFrom(obType))
                            {
                                break;
                            }
                            il.Emit(OpCodes.Ldfld, csc.outerClassField);
                        }
                        scope = scope.GetParent();
                    }
                }
                else
                {
                    this.TranslateToILDefaultThisObject(il, this.lexLevel);
                    Convert.Emit(this, il, Typeob.Object, obType);
                }
            }
            else
            {
                ScriptObject scope = Globals.ScopeStack.Peek();
                while (scope is WithObject || scope is BlockScope)
                {
                    scope = scope.GetParent();
                }
                if (scope is FunctionScope)
                {
                    FunctionObject func = ((FunctionScope)scope).owner;
                    if (!func.isMethod) //Need to get the StackFrame.closureInstance on the stack
                    {
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                        scope = this.Globals.ScopeStack.Peek();
                        while (scope is WithObject || scope is BlockScope)
                        {
                            il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                        il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        while (scope != null)
                        {
                            if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                            {
                                ClassScope csc = (ClassScope)scope;
                                if (csc.IsSameOrDerivedFrom(obType))
                                {
                                    break;
                                }
                                il.Emit(OpCodes.Castclass, csc.GetTypeBuilder());
                                il.Emit(OpCodes.Ldfld, csc.outerClassField);
                            }
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, obType);
                        return;
                    }
                }
                il.Emit(OpCodes.Ldarg_0);
                while (scope != null)
                {
                    if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                    {
                        ClassScope csc = (ClassScope)scope;
                        if (csc.IsSameOrDerivedFrom(obType))
                        {
                            break;
                        }
                        il.Emit(OpCodes.Ldfld, csc.outerClassField);
                    }
                    scope = scope.GetParent();
                }
            }
        }
 internal bool IsNestedIn(ClassScope other, bool isStatic)
 {
     if (base.parent == null)
     {
         return false;
     }
     this.owner.PartiallyEvaluate();
     if (this.owner.enclosingScope == other)
     {
         if (!isStatic)
         {
             return !this.owner.isStatic;
         }
         return true;
     }
     return ((this.owner.enclosingScope is ClassScope) && ((ClassScope) this.owner.enclosingScope).IsNestedIn(other, isStatic));
 }