static private GetSetMethod ( |
||
prop | ||
nonPublic | bool | |
return |
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); }
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); }
public override MethodInfo GetSetMethod(bool nonPublic) { MethodInfo meth = JSProperty.GetSetMethod(this.property, nonPublic); if (meth == null) { return(null); } return(new JSWrappedMethod(meth, this.obj)); }
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); } }
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 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); } } } } } }
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 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); }
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); }
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); }
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); }
public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr) { FieldInfo info = (FieldInfo)base.name_table[name]; if (info != null) { return(new MemberInfo[] { info }); } bool flag = false; ScriptObject parent = base.parent; while (parent is FunctionScope) { FunctionScope scope = (FunctionScope)parent; flag = scope.isMethod && !scope.isStatic; JSLocalField field = (JSLocalField)scope.name_table[name]; if (field == null) { parent = parent.GetParent(); } else { if (field.IsLiteral && !(field.value is FunctionObject)) { return(new MemberInfo[] { field }); } JSLocalField field2 = new JSLocalField(field.Name, this, base.field_table.Count, Microsoft.JScript.Missing.Value) { outerField = field, debugOn = field.debugOn }; if ((!field2.debugOn && this.owner.funcContext.document.debugOn) && scope.owner.funcContext.document.debugOn) { field2.debugOn = Array.IndexOf <string>(scope.owner.formal_parameters, field.Name) >= 0; } field2.isDefined = field.isDefined; field2.debuggerName = "outer." + field2.Name; if (field.IsLiteral) { field2.attributeFlags |= FieldAttributes.Literal; field2.value = field.value; } this.AddOuterScopeField(name, field2); if (this.ProvidesOuterScopeLocals[parent] == null) { this.ProvidesOuterScopeLocals[parent] = parent; } ((FunctionScope)parent).mustSaveStackLocals = true; return(new MemberInfo[] { field2 }); } } if ((parent is ClassScope) && flag) { MemberInfo[] member = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly); int length = member.Length; bool flag2 = false; for (int i = 0; i < length; i++) { MethodInfo info3; PropertyInfo info4; MemberInfo info2 = member[i]; MemberTypes memberType = info2.MemberType; if (memberType != MemberTypes.Field) { if (memberType == MemberTypes.Method) { goto Label_029E; } if (memberType == MemberTypes.Property) { goto Label_02C7; } } else { info = (FieldInfo)info2; if (info.IsLiteral) { JSMemberField field3 = info as JSMemberField; if (((field3 != null) && (field3.value is ClassScope)) && !((ClassScope)field3.value).owner.IsStatic) { flag2 = true; } } if (!info.IsStatic && !info.IsLiteral) { member[i] = new JSClosureField(info); flag2 = true; } } continue; Label_029E: info3 = (MethodInfo)info2; if (!info3.IsStatic) { member[i] = new JSClosureMethod(info3); flag2 = true; } continue; Label_02C7: info4 = (PropertyInfo)info2; MethodInfo getMethod = JSProperty.GetGetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default); MethodInfo setMethod = JSProperty.GetSetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default); bool flag3 = false; if ((getMethod != null) && !getMethod.IsStatic) { flag3 = true; getMethod = new JSClosureMethod(getMethod); } if ((setMethod != null) && !setMethod.IsStatic) { flag3 = true; setMethod = new JSClosureMethod(setMethod); } if (flag3) { member[i] = new JSClosureProperty(info4, getMethod, setMethod); flag2 = true; } } if (flag2) { this.GiveOuterFunctionsTheBadNews(); } if (length > 0) { return(member); } } if ((bindingAttr & BindingFlags.DeclaredOnly) != BindingFlags.Default) { return(new MemberInfo[0]); } return(parent.GetMember(name, bindingAttr)); }
public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr) { FieldInfo field = (FieldInfo)(this.name_table[name]); if (field != null) { return new MemberInfo[] { field } } ; bool nestedInInstanceMethod = false; ScriptObject parent = this.parent; //Treat locals of outer functions as if they were locals of this function while (parent is FunctionScope) { FunctionScope fscope = (FunctionScope)parent; nestedInInstanceMethod = fscope.isMethod && !fscope.isStatic; JSLocalField lfield = (JSLocalField)fscope.name_table[name]; if (lfield == null) { parent = parent.GetParent(); continue; } if (lfield.IsLiteral && !(lfield.value is FunctionObject)) { return new MemberInfo[] { lfield } } ; JSLocalField f = new JSLocalField(lfield.Name, this, this.field_table.Count, Missing.Value); f.outerField = lfield; f.debugOn = lfield.debugOn; if (!f.debugOn && this.owner.funcContext.document.debugOn && fscope.owner.funcContext.document.debugOn) { //Check to see it is off because outer field is a parameter f.debugOn = Array.IndexOf(fscope.owner.formal_parameters, lfield.Name) >= 0; } f.isDefined = lfield.isDefined; f.debuggerName = "outer" + "." + f.Name; if (lfield.IsLiteral) { f.attributeFlags |= FieldAttributes.Literal; f.value = lfield.value; } this.AddOuterScopeField(name, f); if (this.ProvidesOuterScopeLocals[parent] == null) { this.ProvidesOuterScopeLocals[parent] = parent; } ((FunctionScope)parent).mustSaveStackLocals = true; return(new MemberInfo[] { f }); } if (parent is ClassScope && nestedInInstanceMethod) { //return class members as if they were local to the function. It is more convenient to wrap up instance members //at this stage than it is to figure out later that a special case is involved. MemberInfo[] members = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly); int n = members.Length; bool giveBadNews = false; for (int i = 0; i < n; i++) { MemberInfo member = members[i]; switch (member.MemberType) { case MemberTypes.Field: field = (FieldInfo)member; if (field.IsLiteral) { JSMemberField mfield = field as JSMemberField; if (mfield != null && mfield.value is ClassScope && !((ClassScope)mfield.value).owner.IsStatic) { giveBadNews = true; } } if (!field.IsStatic && !field.IsLiteral) { members[i] = new JSClosureField(field); giveBadNews = true; } break; case MemberTypes.Method: MethodInfo meth = (MethodInfo)member; if (!meth.IsStatic) { members[i] = new JSClosureMethod(meth); giveBadNews = true; } break; case MemberTypes.Property: PropertyInfo prop = (PropertyInfo)member; MethodInfo getMeth = JSProperty.GetGetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0); MethodInfo setMeth = JSProperty.GetSetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0); bool nonStatic = false; if (getMeth != null && !getMeth.IsStatic) { nonStatic = true; getMeth = new JSClosureMethod(getMeth); } if (setMeth != null && !setMeth.IsStatic) { nonStatic = true; setMeth = new JSClosureMethod(setMeth); } if (nonStatic) { members[i] = new JSClosureProperty(prop, getMeth, setMeth); giveBadNews = true; } break; } } if (giveBadNews) { this.GiveOuterFunctionsTheBadNews(); //They have to create explicit stack frames } if (n > 0) { return(members); } } if ((bindingAttr & BindingFlags.DeclaredOnly) != 0) { return(new MemberInfo[0]); } return(parent.GetMember(name, bindingAttr)); }
internal override AST PartiallyEvaluate() { this.ctor = this.ctor.PartiallyEvaluateAsCallable(); //first weed out assignment expressions and use them as property initializers ASTList positionalArgs = new ASTList(this.args.context); ASTList namedArgs = new ASTList(this.args.context); for (int i = 0, m = this.args.count; i < m; i++) { AST arg = this.args[i]; Assign assign = arg as Assign; if (assign != null) { assign.rhside = assign.rhside.PartiallyEvaluate(); namedArgs.Append(assign); } else { positionalArgs.Append(arg.PartiallyEvaluate()); } } int n = positionalArgs.count; IReflect[] argIRs = new IReflect[n]; for (int i = 0; i < n; i++) { AST arg = positionalArgs[i]; // only accept ConstantWrappers if (arg is ConstantWrapper) { Object argument = arg.Evaluate(); if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null) { this.positionalArgValues.Add(argument); continue; } } else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute()) { argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(arg.Evaluate()); continue; } arg.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); // the custom attribute is not good and it will be ignored } //Get the custom attribute and the appropriate constructor (under the covers) this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target); if (this.type == null) { return(null); } if (Convert.IsPromotableTo((IReflect)this.type, typeof(CodeAccessSecurityAttribute))) { this.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return(null); } //Coerce the positional arguments to the right type and supply default values for optional parameters ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] parameters = c.GetParameters(); int j = 0; int len = this.positionalArgValues.Count; foreach (ParameterInfo p in parameters) { IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType; if (j < len) { Object value = this.positionalArgValues[j]; this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject); j++; } else { Object value; if (p.DefaultValue == System.Convert.DBNull) { value = Convert.Coerce(null, ir); } else { value = p.DefaultValue; } this.positionalArgValues.Add(value); } } //Check validity of property/field initializers for (int i = 0, m = namedArgs.count; i < m; i++) { Assign assign = (Assign)namedArgs[i]; if (assign.lhside is Lookup && (assign.rhside is ConstantWrapper || (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute()))) { Object value = assign.rhside.Evaluate(); IReflect argType = null; if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object)) { String name = ((Lookup)assign.lhside).Name; MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance); if (members == null || members.Length == 0) { assign.context.HandleError(JSError.NoSuchMember); return(null); } if (members.Length == 1) { MemberInfo member = members[0]; if (member is FieldInfo) { FieldInfo fieldInfo = (FieldInfo)member; if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly) { try{ IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgFields.Add(member); this.namedArgFieldValues.Add(value); continue; }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } } } else if (member is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)member; MethodInfo setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false); if (setMethodInfo != null) { ParameterInfo [] paramInfo = setMethodInfo.GetParameters(); if (paramInfo != null && paramInfo.Length == 1) { try{ IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgProperties.Add(member); this.namedArgPropertyValues.Add(value); }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } continue; } } } } } } assign.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); } if (!this.CheckIfTargetOK(this.type)) { return(null); //Ignore attribute } //Consume and discard assembly name attributes try{ Type ty = this.type as Type; if (ty != null && this.target is AssemblyCustomAttributeList) { if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyCultureAttribute") { if (this.positionalArgValues.Count > 0) { String cultureId = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0) { this.context.HandleError(JSError.ExecutablesCannotBeLocalized); return(null); } this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId); } return(null); } if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false); } return(null); } if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0) { this.Engine.Globals.assemblyKeyFileName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0) { this.Engine.Globals.assemblyKeyName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyVersionAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0])); } return(null); } if (ty.FullName == "System.CLSCompliantAttribute") { this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false); return(this); } } }catch (ArgumentException) { this.context.HandleError(JSError.InvalidCall); } return(this); }