internal override void TranslateToILInitializer(ILGenerator il) { int length = this.fields.Length; if (length > 0) { for (int i = 0; i < length; i++) { JSGlobalField field = this.fields[i] as JSGlobalField; if (field != null) { Type fieldType = field.FieldType; if (((field.IsLiteral && (fieldType != Typeob.ScriptFunction)) && (fieldType != Typeob.Type)) || (field.metaData != null)) { if (((fieldType.IsPrimitive || (fieldType == Typeob.String)) || fieldType.IsEnum) && (field.metaData == null)) { base.compilerGlobals.classwriter.DefineField(field.Name, fieldType, field.Attributes).SetConstant(field.value); } } else if (!(field.value is FunctionObject) || !((FunctionObject)field.value).suppressIL) { FieldBuilder builder2 = base.compilerGlobals.classwriter.DefineField(field.Name, fieldType, (field.Attributes & ~(FieldAttributes.Literal | FieldAttributes.InitOnly)) | FieldAttributes.Static); field.metaData = builder2; field.WriteCustomAttribute(base.Engine.doCRS); } } } } this.statement_block.TranslateToILInitializer(il); }
internal override void TranslateToILInitializer(ILGenerator il) { int nf = this.fields.Length; if (nf > 0) { for (int i = 0; i < nf; i++) { JSGlobalField field = this.fields[i] as JSGlobalField; if (field == null) { continue; } Type t = field.FieldType; if ((field.IsLiteral && t != Typeob.ScriptFunction && t != Typeob.Type) || field.metaData != null) { if ((t.IsPrimitive || t == Typeob.String || t.IsEnum) && field.metaData == null) { FieldBuilder b = compilerGlobals.classwriter.DefineField(field.Name, t, field.Attributes); b.SetConstant(field.value); } continue; } if (field.value is FunctionObject && ((FunctionObject)field.value).suppressIL) { continue; } FieldBuilder fb = compilerGlobals.classwriter.DefineField(field.Name, t, field.Attributes & (~(FieldAttributes.Literal | FieldAttributes.InitOnly)) | FieldAttributes.Static); field.metaData = fb; field.WriteCustomAttribute(this.Engine.doCRS); //There is no need to store Closure objects in the fields corresponding to functions, since the initializer code //for functions takes care of it. Likewise for Classes. } } this.statement_block.TranslateToILInitializer(il); }