Inheritance: System.Reflection.PropertyInfo
        internal override void SetMemberValue(string name, object value)
        {
            bool flag = false;

            if (!this.recursive)
            {
                this.recursive = true;
                try
                {
                    FieldInfo field = this.reflectObj.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                    if (field == null)
                    {
                        PropertyInfo property = this.reflectObj.GetProperty(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                        if (property != null)
                        {
                            JSProperty.SetValue(property, this.namedItem, value, null);
                            flag = true;
                        }
                    }
                    else
                    {
                        field.SetValue(this.namedItem, value);
                        flag = true;
                    }
                    if (!flag && (base.parent != null))
                    {
                        base.parent.SetMemberValue(name, value);
                    }
                }
                finally
                {
                    this.recursive = false;
                }
            }
        }
Exemple #2
0
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if (method != null && !method.IsStatic)
                    {
                        MemberInfo[] propMethods = new MemberInfo[1];
                        propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
                        return(propMethods);
                    }
                }
            }
            MemberInfo[] members = reflect.GetMember(name, bindingAttr);
            if (members != null && members.Length > 0)
            {
                return(ScriptObject.WrapMembers(members, namedItem));
            }
            return(null);
        }
        public override String ToString()
        {
            Type       t    = this.members[0].DeclaringType;
            MethodInfo meth = (t == null ? null :  t.GetMethod(this.name + " source"));

            if (meth == null)
            {
                StringBuilder result    = new StringBuilder();
                bool          firstTime = true;
                foreach (MemberInfo mem in this.members)
                {
                    if (mem is MethodInfo || (mem is PropertyInfo && JSProperty.GetGetMethod((PropertyInfo)mem, false) != null))
                    {
                        if (!firstTime)
                        {
                            result.Append("\n");
                        }
                        else
                        {
                            firstTime = false;
                        }
                        result.Append(mem.ToString());
                    }
                }
                if (result.Length > 0)
                {
                    return(result.ToString());
                }
                return("function " + this.name + "() {\n    [native code]\n}");
            }
            return((String)meth.Invoke(null, null));
        }
Exemple #4
0
        internal override Object GetMemberValue(String name)
        {
            Object retValue = Missing.Value;

            if (!this.recursive)
            {
                this.recursive = true;
                try{
                    FieldInfo field = this.reflectObj.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                    if (field == null)
                    {
                        PropertyInfo prop = this.reflectObj.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                        if (prop != null)
                        {
                            retValue = JSProperty.GetValue(prop, this.namedItem, null);
                        }
                    }
                    else
                    {
                        retValue = field.GetValue(this.namedItem);
                    }

                    if (retValue is Missing && null != parent)
                    {
                        retValue = parent.GetMemberValue(name);
                    }
                }finally{
                    this.recursive = false;
                }
            }
            return(retValue);
        }
Exemple #5
0
        internal bool inStaticInitializerCode; //Set this to true when partially evaluating the initializer of a static variable, false otherwise

        internal ClassScope(AST name, GlobalScope scope)
            : base(scope) //The parent must be set to a proper value before the class can be used.
        {
            this.name                 = name.ToString();
            this.engine               = scope.engine;
            this.fast                 = scope.fast;
            this.noExpando            = true;
            this.isKnownAtCompileTime = true;
            this.owner                = null; //set by Class constructor
            this.constructors         = new JSConstructor[0];
            ScriptObject enclosingScope = this.engine.ScriptObjectStackTop();

            while (enclosingScope is WithObject)
            {
                enclosingScope = enclosingScope.GetParent();
            }
            if (enclosingScope is ClassScope)
            {
                this.package = ((ClassScope)enclosingScope).GetPackage();
            }
            else if (enclosingScope is PackageScope)
            {
                this.package = (PackageScope)enclosingScope;
            }
            else
            {
                this.package = null;
            }
            this.itemProp                = null;
            this.outerClassField         = null;
            this.inStaticInitializerCode = false;
        }
Exemple #6
0
        internal static object GetValue(PropertyInfo prop, object obj, object[] index)
        {
            JSProperty property = prop as JSProperty;

            if (property != null)
            {
                return(property.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            JSWrappedProperty property2 = prop as JSWrappedProperty;

            if (property2 != null)
            {
                return(property2.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            MethodInfo getMethod = GetGetMethod(prop, false);

            if (getMethod != null)
            {
                try
                {
                    return(getMethod.Invoke(obj, BindingFlags.ExactBinding, null, index, null));
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
            }
            throw new MissingMethodException();
        }
Exemple #7
0
        public override string ToString()
        {
            Type       declaringType = this.members[0].DeclaringType;
            MethodInfo info          = (declaringType == null) ? null : declaringType.GetMethod(base.name + " source");

            if (info != null)
            {
                return((string)info.Invoke(null, null));
            }
            StringBuilder builder = new StringBuilder();
            bool          flag    = true;

            foreach (MemberInfo info2 in this.members)
            {
                if ((info2 is MethodInfo) || ((info2 is PropertyInfo) && (JSProperty.GetGetMethod((PropertyInfo)info2, false) != null)))
                {
                    if (!flag)
                    {
                        builder.Append("\n");
                    }
                    else
                    {
                        flag = false;
                    }
                    builder.Append(info2.ToString());
                }
            }
            if (builder.Length > 0)
            {
                return(builder.ToString());
            }
            return("function " + base.name + "() {\n    [native code]\n}");
        }
 internal ClassScope(AST name, GlobalScope scope) : base(scope)
 {
     this.name = name.ToString();
     base.engine = scope.engine;
     base.fast = scope.fast;
     this.noExpando = true;
     base.isKnownAtCompileTime = true;
     this.owner = null;
     this.constructors = new JSConstructor[0];
     ScriptObject parent = base.engine.ScriptObjectStackTop();
     while (parent is WithObject)
     {
         parent = parent.GetParent();
     }
     if (parent is ClassScope)
     {
         this.package = ((ClassScope) parent).GetPackage();
     }
     else if (parent is PackageScope)
     {
         this.package = (PackageScope) parent;
     }
     else
     {
         this.package = null;
     }
     this.itemProp = null;
     this.outerClassField = null;
     this.inStaticInitializerCode = false;
     this.staticInitializerUsesEval = false;
     this.instanceInitializerUsesEval = false;
 }
Exemple #9
0
        internal static void SetValue(PropertyInfo prop, object obj, object value, object[] index)
        {
            JSProperty property = prop as JSProperty;

            if (property != null)
            {
                property.SetValue(obj, value, BindingFlags.ExactBinding, null, index, null);
            }
            else
            {
                MethodInfo setMethod = GetSetMethod(prop, false);
                if (setMethod == null)
                {
                    throw new MissingMethodException();
                }
                int      n      = (index == null) ? 0 : index.Length;
                object[] target = new object[n + 1];
                if (n > 0)
                {
                    ArrayObject.Copy(index, 0, target, 0, n);
                }
                target[n] = value;
                setMethod.Invoke(obj, BindingFlags.ExactBinding, null, target, null);
            }
        }
        internal ClassScope(AST name, GlobalScope scope) : base(scope)
        {
            this.name                 = name.ToString();
            base.engine               = scope.engine;
            base.fast                 = scope.fast;
            this.noExpando            = true;
            base.isKnownAtCompileTime = true;
            this.owner                = null;
            this.constructors         = new JSConstructor[0];
            ScriptObject parent = base.engine.ScriptObjectStackTop();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            if (parent is ClassScope)
            {
                this.package = ((ClassScope)parent).GetPackage();
            }
            else if (parent is PackageScope)
            {
                this.package = (PackageScope)parent;
            }
            else
            {
                this.package = null;
            }
            this.itemProp                    = null;
            this.outerClassField             = null;
            this.inStaticInitializerCode     = false;
            this.staticInitializerUsesEval   = false;
            this.instanceInitializerUsesEval = false;
        }
        internal override object GetMemberValue(string name)
        {
            object memberValue = Microsoft.JScript.Missing.Value;

            if (!this.recursive)
            {
                this.recursive = true;
                try
                {
                    FieldInfo field = this.reflectObj.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                    if (field == null)
                    {
                        PropertyInfo property = this.reflectObj.GetProperty(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                        if (property != null)
                        {
                            memberValue = JSProperty.GetValue(property, this.namedItem, null);
                        }
                    }
                    else
                    {
                        memberValue = field.GetValue(this.namedItem);
                    }
                    if ((memberValue is Microsoft.JScript.Missing) && (base.parent != null))
                    {
                        memberValue = base.parent.GetMemberValue(name);
                    }
                }
                finally
                {
                    this.recursive = false;
                }
            }
            return(memberValue);
        }
Exemple #12
0
        internal override void SetMemberValue(String name, Object value)
        {
            bool assigned = false;

            if (!this.recursive)
            {
                this.recursive = true;
                try{
                    FieldInfo field = this.reflectObj.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                    if (field == null)
                    {
                        PropertyInfo prop = this.reflectObj.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                        if (prop != null)
                        {
                            JSProperty.SetValue(prop, this.namedItem, value, null);
                            assigned = true;
                        }
                    }
                    else
                    {
                        field.SetValue(this.namedItem, value);
                        assigned = true;
                    }

                    if (!assigned && null != parent)
                    {
                        parent.SetMemberValue(name, value);
                    }
                }finally{
                    this.recursive = false;
                }
            }
        }
Exemple #13
0
 internal static MethodInfo GetSetMethod(PropertyInfo prop, bool nonPublic)
 {
     if (prop != null)
     {
         JSProperty property = prop as JSProperty;
         if (property != null)
         {
             return(property.GetSetMethod(nonPublic));
         }
         MethodInfo setMethod = prop.GetSetMethod(nonPublic);
         if (setMethod != null)
         {
             return(setMethod);
         }
         Type declaringType = prop.DeclaringType;
         if (declaringType == null)
         {
             return(null);
         }
         Type baseType = declaringType.BaseType;
         if (baseType == null)
         {
             return(null);
         }
         setMethod = prop.GetGetMethod(nonPublic);
         if (setMethod == null)
         {
             return(null);
         }
         BindingFlags @public = BindingFlags.Public;
         if (setMethod.IsStatic)
         {
             @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static;
         }
         else
         {
             @public |= BindingFlags.Instance;
         }
         if (nonPublic)
         {
             @public |= BindingFlags.NonPublic;
         }
         string name = prop.Name;
         prop = null;
         try
         {
             prop = baseType.GetProperty(name, @public, null, null, new Type[0], null);
         }
         catch (AmbiguousMatchException)
         {
         }
         if (prop != null)
         {
             return(GetSetMethod(prop, nonPublic));
         }
     }
     return(null);
 }
Exemple #14
0
        public override MethodInfo GetSetMethod(bool nonPublic)
        {
            MethodInfo meth = JSProperty.GetSetMethod(this.property, nonPublic);

            if (meth == null)
            {
                return(null);
            }
            return(new JSWrappedMethod(meth, this.obj));
        }
Exemple #15
0
        internal static MemberInfo WrapMember(MemberInfo member, Object obj)
        {
            switch (member.MemberType)
            {
            case MemberTypes.Field:
                FieldInfo field = (FieldInfo)member;
                if (field.IsStatic || field.IsLiteral)
                {
                    return(field);
                }
                else if (!(field is JSWrappedField))
                {
                    return(new JSWrappedField(field, obj));
                }
                else
                {
                    return(field);
                }

            case MemberTypes.Method:
                MethodInfo method = (MethodInfo)member;
                if (method.IsStatic)
                {
                    return(method);
                }
                else if (!(method is JSWrappedMethod))
                {
                    return(new JSWrappedMethod(method, obj));
                }
                else
                {
                    return(method);
                }

            case MemberTypes.Property:
                PropertyInfo property = (PropertyInfo)member;
                if (property is JSWrappedProperty)
                {
                    return(property);
                }
                MethodInfo getMethod = JSProperty.GetGetMethod(property, true);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, true);
                if ((getMethod == null || getMethod.IsStatic) && (setMethod == null || setMethod.IsStatic))
                {
                    return(property);
                }
                else
                {
                    return(new JSWrappedProperty(property, obj));
                }

            default:
                return(member);
            }
        }
Exemple #16
0
        internal static MemberInfo WrapMember(MemberInfo member, object obj)
        {
            MemberTypes memberType = member.MemberType;

            if (memberType != MemberTypes.Field)
            {
                if (memberType != MemberTypes.Method)
                {
                    if (memberType != MemberTypes.Property)
                    {
                        return(member);
                    }
                    PropertyInfo prop = (PropertyInfo)member;
                    if (prop is JSWrappedProperty)
                    {
                        return(prop);
                    }
                    MethodInfo getMethod = JSProperty.GetGetMethod(prop, true);
                    MethodInfo setMethod = JSProperty.GetSetMethod(prop, true);
                    if (((getMethod == null) || getMethod.IsStatic) && ((setMethod == null) || setMethod.IsStatic))
                    {
                        return(prop);
                    }
                    return(new JSWrappedProperty(prop, obj));
                }
            }
            else
            {
                FieldInfo field = (FieldInfo)member;
                if (field.IsStatic || field.IsLiteral)
                {
                    return(field);
                }
                if (field is JSWrappedField)
                {
                    return(field);
                }
                return(new JSWrappedField(field, obj));
            }
            MethodInfo method = (MethodInfo)member;

            if (method.IsStatic)
            {
                return(method);
            }
            if (method is JSWrappedMethod)
            {
                return(method);
            }
            return(new JSWrappedMethod(method, obj));
        }
        internal override object GetMemberValue(string name)
        {
            FieldInfo field = (FieldInfo)this.NameTable[name];

            if ((field == null) && this.isASubClass)
            {
                field = this.subClassIR.GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field != null)
                {
                    if (field.DeclaringType == Typeob.ScriptObject)
                    {
                        return(Microsoft.JScript.Missing.Value);
                    }
                }
                else
                {
                    PropertyInfo property = this.subClassIR.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
                    if ((property != null) && !property.DeclaringType.IsAssignableFrom(Typeob.JSObject))
                    {
                        return(JSProperty.GetGetMethod(property, false).Invoke(this, BindingFlags.SuppressChangeType, null, null, null));
                    }
                    try
                    {
                        MethodInfo method = this.subClassIR.GetMethod(name, BindingFlags.Public | BindingFlags.Static);
                        if (method != null)
                        {
                            Type declaringType = method.DeclaringType;
                            if (((declaringType != Typeob.JSObject) && (declaringType != Typeob.ScriptObject)) && (declaringType != Typeob.Object))
                            {
                                return(new BuiltinFunction(this, method));
                            }
                        }
                    }
                    catch (AmbiguousMatchException)
                    {
                    }
                }
            }
            if (field != null)
            {
                return(field.GetValue(this));
            }
            if (base.parent != null)
            {
                return(base.parent.GetMemberValue(name));
            }
            return(Microsoft.JScript.Missing.Value);
        }
        internal override object Evaluate()
        {
            ConstructorInfo member = (ConstructorInfo)((Binding)this.ctor).member;

            ParameterInfo[] parameters = member.GetParameters();
            int             length     = parameters.Length;

            for (int i = this.positionalArgValues.Count; i < length; i++)
            {
                this.positionalArgValues.Add(Microsoft.JScript.Convert.CoerceT(null, parameters[i].ParameterType));
            }
            object[] array = new object[length];
            this.positionalArgValues.CopyTo(0, array, 0, length);
            object obj2  = member.Invoke(BindingFlags.ExactBinding, null, array, null);
            int    num3  = 0;
            int    count = this.namedArgProperties.Count;

            while (num3 < count)
            {
                JSProperty property = this.namedArgProperties[num3] as JSProperty;
                if (property != null)
                {
                    property.SetValue(obj2, Microsoft.JScript.Convert.Coerce(this.namedArgPropertyValues[num3], property.PropertyIR()), null);
                }
                else
                {
                    ((PropertyInfo)this.namedArgProperties[num3]).SetValue(obj2, this.namedArgPropertyValues[num3], null);
                }
                num3++;
            }
            int num5 = 0;
            int num6 = this.namedArgFields.Count;

            while (num5 < num6)
            {
                JSVariableField field = this.namedArgFields[num5] as JSVariableField;
                if (field != null)
                {
                    field.SetValue(obj2, Microsoft.JScript.Convert.Coerce(this.namedArgFieldValues[num5], field.GetInferredType(null)));
                }
                else
                {
                    ((FieldInfo)this.namedArgFields[num5]).SetValue(obj2, this.namedArgFieldValues[num5]);
                }
                num5++;
            }
            return(obj2);
        }
 private void ConvertFieldAndPropertyInfos(ArrayList vals)
 {
     for (int i = 0, n = vals.Count; i < n; i++)
     {
         JSField jsfld = vals[i] as JSField;
         if (jsfld != null)
         {
             vals[i] = jsfld.GetMetaData(); continue;
         }
         JSProperty jsprop = vals[i] as JSProperty;
         if (jsprop != null)
         {
             vals[i] = jsprop.metaData; continue;
         }
     }
 }
        internal override void CheckIfOKToUseInSuperConstructorCall()
        {
            FieldInfo member = base.member as FieldInfo;

            if (member != null)
            {
                if (!member.IsStatic)
                {
                    base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
            }
            else
            {
                MethodInfo getMethod = base.member as MethodInfo;
                if (getMethod != null)
                {
                    if (!getMethod.IsStatic)
                    {
                        base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                    }
                }
                else
                {
                    PropertyInfo prop = base.member as PropertyInfo;
                    if (prop != null)
                    {
                        getMethod = JSProperty.GetGetMethod(prop, true);
                        if ((getMethod != null) && !getMethod.IsStatic)
                        {
                            base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                        }
                        else
                        {
                            getMethod = JSProperty.GetSetMethod(prop, true);
                            if ((getMethod != null) && !getMethod.IsStatic)
                            {
                                base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                            }
                        }
                    }
                }
            }
        }
Exemple #21
0
        internal override void CheckIfOKToUseInSuperConstructorCall()
        {
            FieldInfo f = this.member as FieldInfo;

            if (f != null)
            {
                if (!f.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                return;
            }
            MethodInfo m = this.member as MethodInfo;

            if (m != null)
            {
                if (!m.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                return;
            }
            PropertyInfo p = this.member as PropertyInfo;

            if (p != null)
            {
                m = JSProperty.GetGetMethod(p, true);
                if (m != null && !m.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                else
                {
                    m = JSProperty.GetSetMethod(p, true);
                    if (m != null && !m.IsStatic)
                    {
                        this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                    }
                }
            }
        }
        internal override Object Evaluate()
        {
            ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member;

            ParameterInfo[] pars = c.GetParameters();
            int             pn   = pars.Length;

            for (int i = positionalArgValues.Count; i < pn; i++)
            {
                positionalArgValues.Add(Convert.CoerceT(null, pars[i].ParameterType));
            }
            Object[] pArgVals = new Object[pn]; positionalArgValues.CopyTo(0, pArgVals, 0, pn);
            Object   ca       = c.Invoke(BindingFlags.ExactBinding, null, pArgVals, null);

            for (int i = 0, n = this.namedArgProperties.Count; i < n; i++)
            {
                JSProperty prop = this.namedArgProperties[i] as JSProperty;
                if (prop != null)
                {
                    prop.SetValue(ca, Convert.Coerce(this.namedArgPropertyValues[i], prop.PropertyIR()), null);
                }
                else
                {
                    ((PropertyInfo)this.namedArgProperties[i]).SetValue(ca, this.namedArgPropertyValues[i], null);
                }
            }
            for (int i = 0, n = this.namedArgFields.Count; i < n; i++)
            {
                JSVariableField field = this.namedArgFields[i] as JSVariableField;
                if (field != null)
                {
                    field.SetValue(ca, Convert.Coerce(this.namedArgFieldValues[i], field.GetInferredType(null)));
                }
                else
                {
                    ((FieldInfo)this.namedArgFields[i]).SetValue(ca, this.namedArgFieldValues[i]);
                }
            }
            return(ca);
        }
        internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue)
        {
            string   str;
            IReflect reflect = this.InferType(null);
            Type     t       = (reflect is Type) ? ((Type)reflect) : null;

            if (reflect is ClassScope)
            {
                t = ((ClassScope)reflect).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if ((defaultMembers != null) && (defaultMembers.Length > 0))
            {
                try
                {
                    PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs);
                    if (prop == null)
                    {
                        goto Label_00B1;
                    }
                    this.method = JSProperty.GetSetMethod(prop, true);
                    if (this.method == null)
                    {
                        base.context.HandleError(JSError.AssignmentToReadOnly, true);
                    }
                    if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, base.context, 0, false, true))
                    {
                        this.method = null;
                    }
                }
                catch (AmbiguousMatchException)
                {
                    base.context.HandleError(JSError.AmbiguousMatch);
                }
                return;
            }
Label_00B1:
            str = (reflect is ClassScope) ? ((ClassScope)reflect).GetName() : ((Type)reflect).Name;
            base.context.HandleError(JSError.NotIndexable, str);
        }
Exemple #24
0
 internal bool inStaticInitializerCode; //Set this to true when partially evaluating the initializer of a static variable, false otherwise
 
 internal ClassScope(AST name, GlobalScope scope)
   : base(scope) { //The parent must be set to a proper value before the class can be used.
   this.name = name.ToString();
   this.engine = scope.engine;
   this.fast = scope.fast;
   this.noExpando = true;
   this.isKnownAtCompileTime = true;
   this.owner = null; //set by Class constructor
   this.constructors = new JSConstructor[0];
   ScriptObject enclosingScope = this.engine.ScriptObjectStackTop();
   while (enclosingScope is WithObject)
     enclosingScope = enclosingScope.GetParent();
   if (enclosingScope is ClassScope)
     this.package = ((ClassScope)enclosingScope).GetPackage();
   else if (enclosingScope is PackageScope)
     this.package = (PackageScope)enclosingScope;
   else
     this.package = null;
   this.itemProp = null;
   this.outerClassField = null;
   this.inStaticInitializerCode = false;
 }
Exemple #25
0
        internal static Object GetValue(PropertyInfo prop, Object obj, Object[] index)
        {
            JSProperty jsprop = prop as JSProperty;

            if (jsprop != null)
            {
                return(jsprop.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            JSWrappedProperty jswrappedprop = prop as JSWrappedProperty;

            if (jswrappedprop != null)
            {
                return(jswrappedprop.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            MethodInfo meth = JSProperty.GetGetMethod(prop, false);

            if (meth != null)
            {
                return(meth.Invoke(obj, BindingFlags.ExactBinding, null, index, null));
            }
            throw new MissingMethodException();
        }
        private void ConvertFieldAndPropertyInfos(ArrayList vals)
        {
            int num   = 0;
            int count = vals.Count;

            while (num < count)
            {
                JSField field = vals[num] as JSField;
                if (field != null)
                {
                    vals[num] = field.GetMetaData();
                }
                else
                {
                    JSProperty property = vals[num] as JSProperty;
                    if (property != null)
                    {
                        vals[num] = property.metaData;
                    }
                }
                num++;
            }
        }
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if ((method != null) && !method.IsStatic)
                    {
                        return(new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) });
                    }
                }
            }
            MemberInfo[] member = reflect.GetMember(name, bindingAttr);
            if ((member != null) && (member.Length > 0))
            {
                return(ScriptObject.WrapMembers(member, namedItem));
            }
            return(null);
        }
Exemple #28
0
        internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue)
        {
            IReflect ir = this.InferType(null);
            Type     t  = ir is Type ? (Type)ir : null;

            if (ir is ClassScope)
            {
                t = ((ClassScope)ir).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if (defaultMembers != null && defaultMembers.Length > 0)
            {
                try{
                    PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs); //Returns property getters as well
                    if (prop != null)
                    {
                        this.method = JSProperty.GetSetMethod(prop, true);
                        if (this.method == null)
                        {
                            this.context.HandleError(JSError.AssignmentToReadOnly, true);
                        }
                        if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, this.context, 0, false, true))
                        {
                            this.method = null;
                        }
                        return;
                    }
                }catch (AmbiguousMatchException) {
                    this.context.HandleError(JSError.AmbiguousMatch);
                    return;
                }
            }
            String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name;

            this.context.HandleError(JSError.NotIndexable, tname);
        }
        public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
        {
            MemberInfoList mems = new MemberInfoList();
            FieldInfo      elem = (FieldInfo)base.name_table[name];

            if (elem == null)
            {
                goto Label_0139;
            }
            if (elem.IsPublic)
            {
                if ((bindingAttr & BindingFlags.Public) != BindingFlags.Default)
                {
                    goto Label_0040;
                }
                goto Label_0139;
            }
            if ((bindingAttr & BindingFlags.NonPublic) == BindingFlags.Default)
            {
                goto Label_0139;
            }
Label_0040:
            if (!elem.IsLiteral)
            {
                goto Label_011E;
            }
            object obj2 = ((JSMemberField)elem).value;

            if (obj2 is FunctionObject)
            {
                FunctionObject obj3 = (FunctionObject)obj2;
                if (obj3.isConstructor)
                {
                    return(new MemberInfo[0]);
                }
                if (obj3.isExpandoMethod)
                {
                    if ((bindingAttr & BindingFlags.Instance) != BindingFlags.Default)
                    {
                        mems.Add(elem);
                    }
                }
                else
                {
                    ((JSMemberField)elem).AddOverloadedMembers(mems, this, bindingAttr | BindingFlags.DeclaredOnly);
                }
                goto Label_0139;
            }
            if (!(obj2 is JSProperty))
            {
                if (((obj2 is ClassScope) && ((bindingAttr & BindingFlags.Instance) != BindingFlags.Default)) && !((ClassScope)obj2).owner.isStatic)
                {
                    mems.Add(elem);
                    goto Label_0139;
                }
                goto Label_011E;
            }
            JSProperty property = (JSProperty)obj2;
            MethodInfo info2    = (property.getter != null) ? property.getter : property.setter;

            if (info2.IsStatic)
            {
                if ((bindingAttr & BindingFlags.Static) != BindingFlags.Default)
                {
                    goto Label_00EC;
                }
                goto Label_0139;
            }
            if ((bindingAttr & BindingFlags.Instance) == BindingFlags.Default)
            {
                goto Label_0139;
            }
Label_00EC:
            mems.Add(property);
            goto Label_0139;
Label_011E:
            if (elem.IsStatic)
            {
                if ((bindingAttr & BindingFlags.Static) != BindingFlags.Default)
                {
                    goto Label_0132;
                }
                goto Label_0139;
            }
            if ((bindingAttr & BindingFlags.Instance) == BindingFlags.Default)
            {
                goto Label_0139;
            }
Label_0132:
            mems.Add(elem);
Label_0139:
            if (((this.owner != null) && this.owner.isInterface) && ((bindingAttr & BindingFlags.DeclaredOnly) == BindingFlags.Default))
            {
                return(this.owner.GetInterfaceMember(name));
            }
            if ((base.parent != null) && ((bindingAttr & BindingFlags.DeclaredOnly) == BindingFlags.Default))
            {
                MemberInfo[] member = base.parent.GetMember(name, bindingAttr);
                if (member != null)
                {
                    foreach (MemberInfo info3 in member)
                    {
                        if (info3.MemberType == MemberTypes.Field)
                        {
                            elem = (FieldInfo)info3;
                            if ((!elem.IsStatic && !elem.IsLiteral) && !(elem is JSWrappedField))
                            {
                                elem = new JSWrappedField(elem, base.parent);
                            }
                            mems.Add(elem);
                        }
                        else
                        {
                            mems.Add(ScriptObject.WrapMember(info3, base.parent));
                        }
                    }
                }
            }
            return(mems.ToArray());
        }
 internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes, bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes) : base(context)
 {
     this.completion = new Completion();
     MethodAttributes privateScope = MethodAttributes.PrivateScope;
     if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
     {
         privateScope = MethodAttributes.Public;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
     {
         privateScope = MethodAttributes.Private;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
     {
         privateScope = MethodAttributes.Assembly;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
     {
         privateScope = MethodAttributes.Family;
     }
     else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
     {
         privateScope = MethodAttributes.FamORAssem;
     }
     else
     {
         privateScope = MethodAttributes.Public;
     }
     if (((attributes & FieldAttributes.Static) != FieldAttributes.PrivateScope) || !isMethod)
     {
         privateScope |= MethodAttributes.Static;
     }
     else
     {
         privateScope |= MethodAttributes.NewSlot | MethodAttributes.Virtual;
     }
     if (isAbstract)
     {
         privateScope |= MethodAttributes.Abstract;
     }
     if (isFinal)
     {
         privateScope |= MethodAttributes.Final;
     }
     this.name = id.ToString();
     this.isMethod = isMethod;
     if (ifaceId != null)
     {
         if (isMethod)
         {
             this.ifaceId = new TypeExpression(ifaceId);
             privateScope &= ~MethodAttributes.MemberAccessMask;
             privateScope |= MethodAttributes.Final | MethodAttributes.Private;
         }
         else
         {
             this.declaringObject = new Member(ifaceId.context, ifaceId, id);
             this.name = this.declaringObject.ToString();
         }
     }
     ScriptObject obj2 = base.Globals.ScopeStack.Peek();
     if (((attributes == FieldAttributes.PrivateScope) && !isAbstract) && !isFinal)
     {
         if (obj2 is ClassScope)
         {
             attributes |= FieldAttributes.Public;
         }
     }
     else if (!(obj2 is ClassScope))
     {
         base.context.HandleError(JSError.NotInsideClass);
         attributes = FieldAttributes.PrivateScope;
         privateScope = MethodAttributes.Public;
     }
     if (obj2 is ActivationObject)
     {
         this.inFastScope = ((ActivationObject) obj2).fast;
         string name = this.name;
         if (isGetter)
         {
             privateScope |= MethodAttributes.SpecialName;
             this.name = "get_" + this.name;
             if (return_type == null)
             {
                 return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
             }
         }
         else if (isSetter)
         {
             privateScope |= MethodAttributes.SpecialName;
             this.name = "set_" + this.name;
             return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
         }
         attributes &= FieldAttributes.FieldAccessMask;
         MethodAttributes attributes3 = privateScope & MethodAttributes.MemberAccessMask;
         if ((((privateScope & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((privateScope & MethodAttributes.Final) == MethodAttributes.PrivateScope)) && (((attributes3 == MethodAttributes.Private) || (attributes3 == MethodAttributes.Assembly)) || (attributes3 == MethodAttributes.FamANDAssem)))
         {
             privateScope |= MethodAttributes.CheckAccessOnOverride;
         }
         this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, privateScope, customAttributes, this.isMethod);
         if (this.declaringObject == null)
         {
             string str2 = this.name;
             if (this.ifaceId != null)
             {
                 str2 = ifaceId.ToString() + "." + str2;
             }
             JSVariableField field = (JSVariableField) ((ActivationObject) obj2).name_table[str2];
             if ((field != null) && ((!(field is JSMemberField) || !(((JSMemberField) field).value is FunctionObject)) || this.func.isExpandoMethod))
             {
                 if (name != this.name)
                 {
                     field.originalContext.HandleError(JSError.ClashWithProperty);
                 }
                 else
                 {
                     id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
                     if (field.value is FunctionObject)
                     {
                         ((FunctionObject) field.value).suppressIL = true;
                     }
                 }
             }
             if (this.isMethod)
             {
                 if ((!(field is JSMemberField) || !(((JSMemberField) field).value is FunctionObject)) || (name != this.name))
                 {
                     this.field = ((ActivationObject) obj2).AddNewField(str2, this.func, attributes | FieldAttributes.Literal);
                     if (name == this.name)
                     {
                         this.field.type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, base.context));
                     }
                 }
                 else
                 {
                     this.field = ((JSMemberField) field).AddOverload(this.func, attributes | FieldAttributes.Literal);
                 }
             }
             else if (obj2 is FunctionScope)
             {
                 if (this.inFastScope)
                 {
                     attributes |= FieldAttributes.Literal;
                 }
                 this.field = ((FunctionScope) obj2).AddNewField(this.name, attributes, this.func);
                 if (this.field is JSLocalField)
                 {
                     JSLocalField field2 = (JSLocalField) this.field;
                     if (this.inFastScope)
                     {
                         field2.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
                         field2.attributeFlags |= FieldAttributes.Literal;
                     }
                     field2.debugOn = base.context.document.debugOn;
                     field2.isDefined = true;
                 }
             }
             else if (this.inFastScope)
             {
                 this.field = ((ActivationObject) obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal);
                 this.field.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context));
             }
             else
             {
                 this.field = ((ActivationObject) obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Static);
             }
             this.field.originalContext = context;
             if (name != this.name)
             {
                 string str3 = name;
                 if (this.ifaceId != null)
                 {
                     str3 = ifaceId.ToString() + "." + name;
                 }
                 FieldInfo info = (FieldInfo) ((ClassScope) obj2).name_table[str3];
                 if (info != null)
                 {
                     if (info.IsLiteral)
                     {
                         object obj3 = ((JSVariableField) info).value;
                         if (obj3 is JSProperty)
                         {
                             this.enclosingProperty = (JSProperty) obj3;
                         }
                     }
                     if (this.enclosingProperty == null)
                     {
                         id.context.HandleError(JSError.DuplicateName, true);
                     }
                 }
                 if (this.enclosingProperty == null)
                 {
                     this.enclosingProperty = new JSProperty(name);
                     ((JSMemberField) ((ActivationObject) obj2).AddNewField(str3, this.enclosingProperty, attributes | FieldAttributes.Literal)).originalContext = base.context;
                 }
                 else if ((isGetter && (this.enclosingProperty.getter != null)) || (isSetter && (this.enclosingProperty.setter != null)))
                 {
                     id.context.HandleError(JSError.DuplicateName, true);
                 }
                 if (isGetter)
                 {
                     this.enclosingProperty.getter = new JSFieldMethod(this.field, obj2);
                 }
                 else
                 {
                     this.enclosingProperty.setter = new JSFieldMethod(this.field, obj2);
                 }
             }
         }
     }
     else
     {
         this.inFastScope = false;
         this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, MethodAttributes.Public, null, false);
         this.field = ((StackFrame) obj2).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static);
     }
 }
Exemple #31
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));
        }
Exemple #32
0
      internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, 
                                   Block body, FunctionScope own_scope, FieldAttributes attributes, 
                                   bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes)
        : base(context) {
        MethodAttributes methodAttributes = (MethodAttributes)0;
        if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
          methodAttributes = MethodAttributes.Public;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
          methodAttributes = MethodAttributes.Private;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
          methodAttributes = MethodAttributes.Assembly;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
          methodAttributes = MethodAttributes.Family;
        else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
          methodAttributes = MethodAttributes.FamORAssem;
        else
          methodAttributes = MethodAttributes.Public;

        if ((attributes & FieldAttributes.Static) != 0 || !isMethod)
          methodAttributes |= MethodAttributes.Static;
        else
          methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot;
        
        if (isAbstract)
          methodAttributes |= MethodAttributes.Abstract;
        if (isFinal)
          methodAttributes |= MethodAttributes.Final;
        
        this.name = id.ToString();
        this.isMethod = isMethod;
        if (ifaceId != null){
          if (isMethod){
            this.ifaceId = new TypeExpression(ifaceId);
            methodAttributes &= ~MethodAttributes.MemberAccessMask;
            methodAttributes |= MethodAttributes.Private|MethodAttributes.Final;
          }else{
            this.declaringObject = new Member(ifaceId.context, ifaceId, id);
            this.name = this.declaringObject.ToString();
          }
        }
        ScriptObject enclosingScope = Globals.ScopeStack.Peek();
        if (attributes == 0 && !isAbstract && !isFinal){
          if (enclosingScope is ClassScope)
            attributes |= FieldAttributes.Public;
        }else{
          if (!(enclosingScope is ClassScope)){
            this.context.HandleError(JSError.NotInsideClass);
            attributes = (FieldAttributes)0;
            methodAttributes = MethodAttributes.Public;
          }
        }
        if (enclosingScope is ActivationObject){
          this.inFastScope = ((ActivationObject)enclosingScope).fast;
          // if later on originalName != this.name this is a property getter/setter
          String originalName = this.name; 
          // mangle the name 
          if (isGetter){
            methodAttributes |= MethodAttributes.SpecialName;
            this.name = "get_" + this.name;
            if (return_type == null)
              return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
          }else if (isSetter){
            methodAttributes |= MethodAttributes.SpecialName;
            this.name = "set_" + this.name;
            return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
          }
          attributes &= FieldAttributes.FieldAccessMask;
          // create the function object
          this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, 
                                         methodAttributes, customAttributes, this.isMethod);
          if (this.declaringObject != null) return;
          // check whether the function name (possibly mangled) is in use already
          String fieldName = this.name;
          if (this.ifaceId != null) fieldName = ifaceId.ToString()+"."+fieldName;
          JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName];
          if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod)){
            if (originalName != this.name)
              localField.originalContext.HandleError(JSError.ClashWithProperty);
            else{
              id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
              if (localField.value is FunctionObject)
                ((FunctionObject)localField.value).suppressIL = true;
            }
          }
          // create or update the proper field
          if (this.isMethod){
            if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name){
              this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes|FieldAttributes.Literal);
              if (originalName == this.name) // if it is a property do not assign the type
                ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context));
            }else
              this.field = ((JSMemberField)localField).AddOverload(this.func, attributes|FieldAttributes.Literal);
          }else if (enclosingScope is FunctionScope){
            if (this.inFastScope) attributes |= FieldAttributes.Literal;
            this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func);
            if (this.field is JSLocalField){
              JSLocalField locField = (JSLocalField)this.field;
              if (this.inFastScope){
                locField.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                locField.attributeFlags |= FieldAttributes.Literal;
              }
              locField.debugOn = this.context.document.debugOn;
              locField.isDefined = true;
            }
          }else if (this.inFastScope){
            this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Literal);
            ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
            //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not
            //accessible in fast mode
          }else //enclosingScope is GlobalObject
            this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Static);
          ((JSVariableField)this.field).originalContext = context;
          
          // if it is a property create/update the PropertyInfo and assign the getter/setter
          if (originalName != this.name){
            String propertyFieldName = originalName;
            if (this.ifaceId != null) propertyFieldName = ifaceId.ToString()+"."+originalName;
            FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName];
            if (prop != null){
              // check whether a property was defined already
              if (prop.IsLiteral){
                Object val = ((JSVariableField)prop).value;
                if (val is JSProperty)
                  this.enclosingProperty = (JSProperty)val;
              }
              if (this.enclosingProperty == null)
                id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property
            }
            if (this.enclosingProperty == null){
              this.enclosingProperty = new JSProperty(originalName);
              prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes|FieldAttributes.Literal);
              ((JSMemberField)prop).originalContext = this.context;
            }else{
              if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null))
                id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter
            }
            if (isGetter)
              this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope);
            else
              this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope);
          }
        }else{ //Might get here if function declaration is inside of an eval.
          this.inFastScope = false;
          this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false);
          this.field = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes|FieldAttributes.Static);
        }
      }
        internal override AST PartiallyEvaluate()
        {
            this.ctor = this.ctor.PartiallyEvaluateAsCallable();
            ASTList args  = new ASTList(this.args.context);
            ASTList list2 = new ASTList(this.args.context);
            int     num   = 0;
            int     count = this.args.count;

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

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

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

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

Label_04C9:
                num7++;
            }
            if (!this.CheckIfTargetOK(this.type))
            {
                return(null);
            }
            try
            {
                Type type = this.type as Type;
                if ((type != null) && (this.target is AssemblyCustomAttributeList))
                {
                    if (type.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyCultureAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            string str2 = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            if ((base.Engine.PEFileKind != PEFileKinds.Dll) && (str2.Length > 0))
                            {
                                base.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                                return(null);
                            }
                            base.Engine.Globals.assemblyCulture = new CultureInfo(str2);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyDelaySignAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyDelaySign = Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyFlagsAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyFlags = (AssemblyFlags)((uint)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(uint)));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyFileAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyFileName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyFileNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyFileName != null) && (base.Engine.Globals.assemblyKeyFileName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyFileName        = null;
                                base.Engine.Globals.assemblyKeyFileNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyNameAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyName != null) && (base.Engine.Globals.assemblyKeyName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyName        = null;
                                base.Engine.Globals.assemblyKeyNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyVersionAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyVersion = this.ParseVersion(Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.CLSCompliantAttribute")
                    {
                        base.Engine.isCLSCompliant = ((this.args == null) || (this.args.count == 0)) || Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        return(this);
                    }
                }
            }
            catch (ArgumentException)
            {
                base.context.HandleError(JSError.InvalidCall);
            }
            return(this);
        }
Exemple #34
0
        internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type,
                                     Block body, FunctionScope own_scope, FieldAttributes attributes,
                                     bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes)
            : base(context)
        {
            MethodAttributes methodAttributes = (MethodAttributes)0;

            if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
            {
                methodAttributes = MethodAttributes.Public;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private)
            {
                methodAttributes = MethodAttributes.Private;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
            {
                methodAttributes = MethodAttributes.Assembly;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family)
            {
                methodAttributes = MethodAttributes.Family;
            }
            else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem)
            {
                methodAttributes = MethodAttributes.FamORAssem;
            }
            else
            {
                methodAttributes = MethodAttributes.Public;
            }

            if ((attributes & FieldAttributes.Static) != 0 || !isMethod)
            {
                methodAttributes |= MethodAttributes.Static;
            }
            else
            {
                methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot;
            }

            if (isAbstract)
            {
                methodAttributes |= MethodAttributes.Abstract;
            }
            if (isFinal)
            {
                methodAttributes |= MethodAttributes.Final;
            }

            this.name     = id.ToString();
            this.isMethod = isMethod;
            if (ifaceId != null)
            {
                if (isMethod)
                {
                    this.ifaceId      = new TypeExpression(ifaceId);
                    methodAttributes &= ~MethodAttributes.MemberAccessMask;
                    methodAttributes |= MethodAttributes.Private | MethodAttributes.Final;
                }
                else
                {
                    this.declaringObject = new Member(ifaceId.context, ifaceId, id);
                    this.name            = this.declaringObject.ToString();
                }
            }
            ScriptObject enclosingScope = Globals.ScopeStack.Peek();

            if (attributes == 0 && !isAbstract && !isFinal)
            {
                if (enclosingScope is ClassScope)
                {
                    attributes |= FieldAttributes.Public;
                }
            }
            else
            {
                if (!(enclosingScope is ClassScope))
                {
                    this.context.HandleError(JSError.NotInsideClass);
                    attributes       = (FieldAttributes)0;
                    methodAttributes = MethodAttributes.Public;
                }
            }
            if (enclosingScope is ActivationObject)
            {
                this.inFastScope = ((ActivationObject)enclosingScope).fast;
                // if later on originalName != this.name this is a property getter/setter
                String originalName = this.name;
                // mangle the name
                if (isGetter)
                {
                    methodAttributes |= MethodAttributes.SpecialName;
                    this.name         = "get_" + this.name;
                    if (return_type == null)
                    {
                        return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context));
                    }
                }
                else if (isSetter)
                {
                    methodAttributes |= MethodAttributes.SpecialName;
                    this.name         = "set_" + this.name;
                    return_type       = new TypeExpression(new ConstantWrapper(Typeob.Void, context));
                }
                attributes &= FieldAttributes.FieldAccessMask;
                // create the function object
                this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context,
                                               methodAttributes, customAttributes, this.isMethod);
                if (this.declaringObject != null)
                {
                    return;
                }
                // check whether the function name (possibly mangled) is in use already
                String fieldName = this.name;
                if (this.ifaceId != null)
                {
                    fieldName = ifaceId.ToString() + "." + fieldName;
                }
                JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName];
                if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod))
                {
                    if (originalName != this.name)
                    {
                        localField.originalContext.HandleError(JSError.ClashWithProperty);
                    }
                    else
                    {
                        id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod);
                        if (localField.value is FunctionObject)
                        {
                            ((FunctionObject)localField.value).suppressIL = true;
                        }
                    }
                }
                // create or update the proper field
                if (this.isMethod)
                {
                    if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name)
                    {
                        this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes | FieldAttributes.Literal);
                        if (originalName == this.name) // if it is a property do not assign the type
                        {
                            ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context));
                        }
                    }
                    else
                    {
                        this.field = ((JSMemberField)localField).AddOverload(this.func, attributes | FieldAttributes.Literal);
                    }
                }
                else if (enclosingScope is FunctionScope)
                {
                    if (this.inFastScope)
                    {
                        attributes |= FieldAttributes.Literal;
                    }
                    this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func);
                    if (this.field is JSLocalField)
                    {
                        JSLocalField locField = (JSLocalField)this.field;
                        if (this.inFastScope)
                        {
                            locField.type            = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                            locField.attributeFlags |= FieldAttributes.Literal;
                        }
                        locField.debugOn   = this.context.document.debugOn;
                        locField.isDefined = true;
                    }
                }
                else if (this.inFastScope)
                {
                    this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal);
                    ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context));
                    //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not
                    //accessible in fast mode
                }
                else //enclosingScope is GlobalObject
                {
                    this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Static);
                }
                ((JSVariableField)this.field).originalContext = context;

                // if it is a property create/update the PropertyInfo and assign the getter/setter
                if (originalName != this.name)
                {
                    String propertyFieldName = originalName;
                    if (this.ifaceId != null)
                    {
                        propertyFieldName = ifaceId.ToString() + "." + originalName;
                    }
                    FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName];
                    if (prop != null)
                    {
                        // check whether a property was defined already
                        if (prop.IsLiteral)
                        {
                            Object val = ((JSVariableField)prop).value;
                            if (val is JSProperty)
                            {
                                this.enclosingProperty = (JSProperty)val;
                            }
                        }
                        if (this.enclosingProperty == null)
                        {
                            id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property
                        }
                    }
                    if (this.enclosingProperty == null)
                    {
                        this.enclosingProperty = new JSProperty(originalName);
                        prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes | FieldAttributes.Literal);
                        ((JSMemberField)prop).originalContext = this.context;
                    }
                    else
                    {
                        if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null))
                        {
                            id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter
                        }
                    }
                    if (isGetter)
                    {
                        this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope);
                    }
                    else
                    {
                        this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope);
                    }
                }
            }
            else //Might get here if function declaration is inside of an eval.
            {
                this.inFastScope = false;
                this.func        = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false);
                this.field       = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static);
            }
        }