public static object JScriptExceptionValue(object e, VsaEngine engine) { if (engine == null) { engine = new VsaEngine(true); engine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite()); } ErrorConstructor originalError = engine.Globals.globalObject.originalError; if (e is JScriptException) { object obj2 = ((JScriptException)e).value; if ((!(obj2 is Exception) && !(obj2 is Microsoft.JScript.Missing)) && ((((JScriptException)e).Number & 0xffff) == 0x139e)) { return(obj2); } return(originalError.Construct((Exception)e)); } if (e is StackOverflowException) { return(originalError.Construct(new JScriptException(JSError.OutOfStack))); } if (e is OutOfMemoryException) { return(originalError.Construct(new JScriptException(JSError.OutOfMemory))); } return(originalError.Construct(e)); }
public static Object JScriptExceptionValue(Object e, VsaEngine engine) { if (engine == null) { engine = new VsaEngine(true); engine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite()); } ErrorConstructor originalError = engine.Globals.globalObject.originalError; if (e is JScriptException) { Object value = ((JScriptException)e).value; if (value is Exception || value is Missing || (((JScriptException)e).Number & 0xFFFF) != (int)JSError.UncaughtException) { return(originalError.Construct((Exception)e)); } return(value); //The exception wraps a non-exception value } else if (e is StackOverflowException) { return(originalError.Construct(new JScriptException(JSError.OutOfStack))); } else if (e is OutOfMemoryException) { return(originalError.Construct(new JScriptException(JSError.OutOfMemory))); } return(originalError.Construct(e)); }
internal ErrorConstructor(String subtypeName, ErrorType type, ErrorConstructor error, GlobalObject globalObject) : base(error.parent, subtypeName, 2){ this.originalPrototype = new LenientErrorPrototype((LenientFunctionPrototype)error.parent, error.originalPrototype, subtypeName); this.noExpando = false; this.originalPrototype._constructor = this; this.proto = this.originalPrototype; this.type = type; this.globalObject = globalObject; this.noExpando = false; }
internal ErrorConstructor(string subtypeName, ErrorType type, ErrorConstructor error, GlobalObject globalObject) : base(error.parent, subtypeName, 2) { this.originalPrototype = new LenientErrorPrototype((LenientFunctionPrototype)error.parent, error.originalPrototype, subtypeName); base.noExpando = false; this.originalPrototype._constructor = this; base.proto = this.originalPrototype; this.type = type; this.globalObject = globalObject; base.noExpando = false; }
internal GlobalObject(){ this.originalActiveXObjectField = null; this.originalArrayField = null; this.originalBooleanField = null; this.originalDateField = null; this.originalEnumeratorField = null; this.originalEvalErrorField = null; this.originalErrorField = null; this.originalFunctionField = null; this.originalNumberField = null; this.originalObjectField = null; this.originalObjectPrototypeField = null; this.originalRangeErrorField = null; this.originalReferenceErrorField = null; this.originalRegExpField = null; this.originalStringField = null; this.originalSyntaxErrorField = null; this.originalTypeErrorField = null; this.originalVBArrayField = null; this.originalURIErrorField = null; }
internal GlobalObject() { this.originalActiveXObjectField = null; this.originalArrayField = null; this.originalBooleanField = null; this.originalDateField = null; this.originalEnumeratorField = null; this.originalEvalErrorField = null; this.originalErrorField = null; this.originalFunctionField = null; this.originalNumberField = null; this.originalObjectField = null; this.originalObjectPrototypeField = null; this.originalRangeErrorField = null; this.originalReferenceErrorField = null; this.originalRegExpField = null; this.originalStringField = null; this.originalSyntaxErrorField = null; this.originalTypeErrorField = null; this.originalVBArrayField = null; this.originalURIErrorField = null; }
private void TranslateToIL(ILGenerator il, Object val, Type rtype) { IConvertible ic = Convert.GetIConvertible(val); switch (Convert.GetTypeCode(val, ic)) { case TypeCode.Empty: il.Emit(OpCodes.Ldnull); if (rtype.IsValueType) { Convert.Emit(this, il, Typeob.Object, rtype); } return; case TypeCode.Object: break; case TypeCode.DBNull: il.Emit(OpCodes.Ldsfld, typeof(DBNull).GetField("Value")); Convert.Emit(this, il, Typeob.Null, rtype); return; case TypeCode.Boolean: ConstantWrapper.TranslateToILInt(il, ic.ToInt32(null)); Convert.Emit(this, il, Typeob.Boolean, rtype); return; case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: ConstantWrapper.TranslateToILInt(il, ic.ToInt32(null)); if (rtype.IsEnum) { return; } if (val is EnumWrapper) { Convert.Emit(this, il, ((EnumWrapper)val).type.GetTypeBuilderOrEnumBuilder(), rtype); } else { Convert.Emit(this, il, val.GetType(), rtype); } return; case TypeCode.UInt32: ConstantWrapper.TranslateToILInt(il, (int)ic.ToUInt32(null)); if (rtype.IsEnum) { return; } if (val is EnumWrapper) { Convert.Emit(this, il, ((EnumWrapper)val).type.GetTypeBuilderOrEnumBuilder(), rtype); } else { Convert.Emit(this, il, Typeob.UInt32, rtype); } return; case TypeCode.Int64: long l = ic.ToInt64(null); if (Int32.MinValue <= l && l <= Int32.MaxValue) { ConstantWrapper.TranslateToILInt(il, (int)l); il.Emit(OpCodes.Conv_I8); } else { il.Emit(OpCodes.Ldc_I8, l); } if (rtype.IsEnum) { return; } if (val is EnumWrapper) { Convert.Emit(this, il, ((EnumWrapper)val).type.GetTypeBuilderOrEnumBuilder(), rtype); } else { Convert.Emit(this, il, Typeob.Int64, rtype); } return; case TypeCode.UInt64: ulong ul = ic.ToUInt64(null); if (ul <= Int32.MaxValue) { ConstantWrapper.TranslateToILInt(il, (int)ul); il.Emit(OpCodes.Conv_I8); } else { il.Emit(OpCodes.Ldc_I8, (long)ul); } if (rtype.IsEnum) { return; } if (val is EnumWrapper) { Convert.Emit(this, il, ((EnumWrapper)val).type.GetTypeBuilderOrEnumBuilder(), rtype); } else { Convert.Emit(this, il, Typeob.UInt64, rtype); } return; case TypeCode.Single: float f = ic.ToSingle(null); if (f == f && (f != 0 || !Single.IsNegativeInfinity(1 / f))) { int i = (int)f; if (-128 <= i && i <= 127 && f == (float)i) { ConstantWrapper.TranslateToILInt(il, i); il.Emit(OpCodes.Conv_R4); } else { il.Emit(OpCodes.Ldc_R4, f); } } else { il.Emit(OpCodes.Ldc_R4, f); } Convert.Emit(this, il, Typeob.Single, rtype); return; case TypeCode.Double: double d = ic.ToDouble(null); if (d == d && (d != 0 || !Double.IsNegativeInfinity(1 / d))) { int i = (int)d; if (-128 <= i && i <= 127 && d == (double)i) { ConstantWrapper.TranslateToILInt(il, i); il.Emit(OpCodes.Conv_R8); } else { il.Emit(OpCodes.Ldc_R8, d); } } else { il.Emit(OpCodes.Ldc_R8, d); } Convert.Emit(this, il, Typeob.Double, rtype); return; case TypeCode.Decimal: int[] bits = Decimal.GetBits(ic.ToDecimal(null)); ConstantWrapper.TranslateToILInt(il, bits[0]); ConstantWrapper.TranslateToILInt(il, bits[1]); ConstantWrapper.TranslateToILInt(il, bits[2]); il.Emit(bits[3] < 0 ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); //bool isNegative ConstantWrapper.TranslateToILInt(il, (bits[3] & 0x7FFFFFFF) >> 16); il.Emit(OpCodes.Newobj, CompilerGlobals.decimalConstructor); Convert.Emit(this, il, Typeob.Decimal, rtype); return; case TypeCode.DateTime: l = ic.ToDateTime(null).Ticks; il.Emit(OpCodes.Ldc_I8, l); Convert.Emit(this, il, Typeob.Int64, rtype); return; case TypeCode.String: String str = ic.ToString(null); if (rtype == Typeob.Char && str.Length == 1) { ConstantWrapper.TranslateToILInt(il, (int)str[0]); return; } il.Emit(OpCodes.Ldstr, str); Convert.Emit(this, il, Typeob.String, rtype); return; } if (val is Enum) { if (rtype == Typeob.String) { this.TranslateToIL(il, val.ToString(), rtype); } else if (rtype.IsPrimitive) { this.TranslateToIL(il, System.Convert.ChangeType(val, Enum.GetUnderlyingType(val.GetType())), rtype); } else { Type et = val.GetType(); Type ut = Enum.GetUnderlyingType(et); this.TranslateToIL(il, System.Convert.ChangeType(val, ut), ut); il.Emit(OpCodes.Box, et); Convert.Emit(this, il, Typeob.Object, rtype); } return; } if (val is EnumWrapper) { if (rtype == Typeob.String) { this.TranslateToIL(il, val.ToString(), rtype); } else if (rtype.IsPrimitive) { this.TranslateToIL(il, ((EnumWrapper)val).ToNumericValue(), rtype); } else { Type et = ((EnumWrapper)val).type.owner.GetTypeBuilderOrEnumBuilder(); Type ut = ((EnumWrapper)val).value.GetType(); this.TranslateToIL(il, ((EnumWrapper)val).value, ut); il.Emit(OpCodes.Box, et); Convert.Emit(this, il, Typeob.Object, rtype); } return; } if (val is Type) { il.Emit(OpCodes.Ldtoken, (Type)val); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is Namespace) { il.Emit(OpCodes.Ldstr, ((Namespace)val).Name); this.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.getNamespaceMethod); Convert.Emit(this, il, typeof(Namespace), rtype); } else if (val is ClassScope) { il.Emit(OpCodes.Ldtoken, ((ClassScope)val).GetTypeBuilderOrEnumBuilder()); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is TypedArray) { il.Emit(OpCodes.Ldtoken, Convert.ToType((TypedArray)val)); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is NumberObject) { this.TranslateToIL(il, ((NumberObject)val).value, Typeob.Object); this.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Convert.Emit(this, il, Typeob.NumberObject, rtype); } else if (val is StringObject) { il.Emit(OpCodes.Ldstr, ((StringObject)val).value); this.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Convert.Emit(this, il, Typeob.StringObject, rtype); } else if (val is BooleanObject) { il.Emit(((BooleanObject)val).value ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); il.Emit(OpCodes.Box, Typeob.Boolean); this.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Convert.Emit(this, il, Typeob.BooleanObject, rtype); } else if (val is ActiveXObjectConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("ActiveXObject").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ArrayConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Array").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is BooleanConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Boolean").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is DateConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Date").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is EnumeratorConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Enumerator").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ErrorConstructor) { ErrorConstructor error = (ErrorConstructor)val; if (error == ErrorConstructor.evalOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("EvalError").GetGetMethod()); } else if (error == ErrorConstructor.rangeOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("RangeError").GetGetMethod()); } else if (error == ErrorConstructor.referenceOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("ReferenceError").GetGetMethod()); } else if (error == ErrorConstructor.syntaxOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("SyntaxError").GetGetMethod()); } else if (error == ErrorConstructor.typeOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("TypeError").GetGetMethod()); } else if (error == ErrorConstructor.uriOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("URIError").GetGetMethod()); } else { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Error").GetGetMethod()); } Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is FunctionConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Function").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is MathObject) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Math").GetGetMethod()); Convert.Emit(this, il, Typeob.JSObject, rtype); } else if (val is NumberConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Number").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ObjectConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Object").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is RegExpConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("RegExp").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is StringConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("String").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is VBArrayConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("VBArray").GetGetMethod()); Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is IntPtr) { il.Emit(OpCodes.Ldc_I8, (long)(IntPtr)val); il.Emit(OpCodes.Conv_I); Convert.Emit(this, il, typeof(IntPtr), rtype); } else if (val is UIntPtr) { il.Emit(OpCodes.Ldc_I8, (long)(UIntPtr)val); il.Emit(OpCodes.Conv_U); Convert.Emit(this, il, typeof(UIntPtr), rtype); } else if (val is Missing) { il.Emit(OpCodes.Ldsfld, CompilerGlobals.missingField); Convert.Emit(this, il, Typeob.Object, rtype); } else if (val is System.Reflection.Missing) { if (rtype.IsPrimitive) { this.TranslateToIL(il, Double.NaN, rtype); } else if (rtype != Typeob.Object && !rtype.IsValueType) { il.Emit(OpCodes.Ldnull); } else { il.Emit(OpCodes.Ldsfld, CompilerGlobals.systemReflectionMissingField); Convert.Emit(this, il, Typeob.Object, rtype); } } else if (val != this.value) //Value was coerced to some type we have no compile time knowlegde of { this.TranslateToIL(il, this.value, rtype); } else { throw new JScriptException(JSError.InternalError, this.context); //It should not be possible to wrap any other kind of object } }
private void TranslateToIL(ILGenerator il, object val, Type rtype) { long ticks; IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(val); switch (Microsoft.JScript.Convert.GetTypeCode(val, iConvertible)) { case TypeCode.Empty: il.Emit(OpCodes.Ldnull); if (rtype.IsValueType) { Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype); } return; case TypeCode.DBNull: il.Emit(OpCodes.Ldsfld, Typeob.Null.GetField("Value")); Microsoft.JScript.Convert.Emit(this, il, Typeob.Null, rtype); return; case TypeCode.Boolean: TranslateToILInt(il, iConvertible.ToInt32(null)); Microsoft.JScript.Convert.Emit(this, il, Typeob.Boolean, rtype); return; case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: TranslateToILInt(il, iConvertible.ToInt32(null)); if (!rtype.IsEnum) { if (val is EnumWrapper) { Microsoft.JScript.Convert.Emit(this, il, ((EnumWrapper)val).type, rtype); return; } Microsoft.JScript.Convert.Emit(this, il, Globals.TypeRefs.ToReferenceContext(val.GetType()), rtype); return; } return; case TypeCode.UInt32: TranslateToILInt(il, (int)iConvertible.ToUInt32(null)); if (!rtype.IsEnum) { if (val is EnumWrapper) { Microsoft.JScript.Convert.Emit(this, il, ((EnumWrapper)val).type, rtype); return; } Microsoft.JScript.Convert.Emit(this, il, Typeob.UInt32, rtype); return; } return; case TypeCode.Int64: ticks = iConvertible.ToInt64(null); if ((-2147483648L > ticks) || (ticks > 0x7fffffffL)) { il.Emit(OpCodes.Ldc_I8, ticks); break; } TranslateToILInt(il, (int)ticks); il.Emit(OpCodes.Conv_I8); break; case TypeCode.UInt64: { ulong num2 = iConvertible.ToUInt64(null); if (num2 > 0x7fffffffL) { il.Emit(OpCodes.Ldc_I8, (long)num2); } else { TranslateToILInt(il, (int)num2); il.Emit(OpCodes.Conv_I8); } if (!rtype.IsEnum) { if (val is EnumWrapper) { Microsoft.JScript.Convert.Emit(this, il, ((EnumWrapper)val).type, rtype); return; } Microsoft.JScript.Convert.Emit(this, il, Typeob.UInt64, rtype); } return; } case TypeCode.Single: { float arg = iConvertible.ToSingle(null); if ((arg != arg) || ((arg == 0f) && float.IsNegativeInfinity(1f / arg))) { il.Emit(OpCodes.Ldc_R4, arg); } else { int i = (int)Runtime.DoubleToInt64((double)arg); if (((-128 > i) || (i > 0x7f)) || (arg != i)) { il.Emit(OpCodes.Ldc_R4, arg); } else { TranslateToILInt(il, i); il.Emit(OpCodes.Conv_R4); } } Microsoft.JScript.Convert.Emit(this, il, Typeob.Single, rtype); return; } case TypeCode.Double: { double num5 = iConvertible.ToDouble(null); if ((num5 != num5) || ((num5 == 0.0) && double.IsNegativeInfinity(1.0 / num5))) { il.Emit(OpCodes.Ldc_R8, num5); } else { int num6 = (int)Runtime.DoubleToInt64(num5); if (((-128 > num6) || (num6 > 0x7f)) || (num5 != num6)) { il.Emit(OpCodes.Ldc_R8, num5); } else { TranslateToILInt(il, num6); il.Emit(OpCodes.Conv_R8); } } Microsoft.JScript.Convert.Emit(this, il, Typeob.Double, rtype); return; } case TypeCode.Decimal: { int[] bits = decimal.GetBits(iConvertible.ToDecimal(null)); TranslateToILInt(il, bits[0]); TranslateToILInt(il, bits[1]); TranslateToILInt(il, bits[2]); il.Emit((bits[3] < 0) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); TranslateToILInt(il, (bits[3] & 0x7fffffff) >> 0x10); il.Emit(OpCodes.Newobj, CompilerGlobals.decimalConstructor); Microsoft.JScript.Convert.Emit(this, il, Typeob.Decimal, rtype); return; } case TypeCode.DateTime: ticks = iConvertible.ToDateTime(null).Ticks; il.Emit(OpCodes.Ldc_I8, ticks); Microsoft.JScript.Convert.Emit(this, il, Typeob.Int64, rtype); return; case TypeCode.String: { string str = iConvertible.ToString(null); if (!(rtype == Typeob.Char) || (str.Length != 1)) { il.Emit(OpCodes.Ldstr, str); Microsoft.JScript.Convert.Emit(this, il, Typeob.String, rtype); return; } TranslateToILInt(il, str[0]); return; } default: if (val is Enum) { if (rtype == Typeob.String) { this.TranslateToIL(il, val.ToString(), rtype); return; } if (rtype.IsPrimitive) { this.TranslateToIL(il, System.Convert.ChangeType(val, Enum.GetUnderlyingType(Globals.TypeRefs.ToReferenceContext(val.GetType())), CultureInfo.InvariantCulture), rtype); return; } Type enumType = Globals.TypeRefs.ToReferenceContext(val.GetType()); Type underlyingType = Enum.GetUnderlyingType(enumType); this.TranslateToIL(il, System.Convert.ChangeType(val, underlyingType, CultureInfo.InvariantCulture), underlyingType); il.Emit(OpCodes.Box, enumType); Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype); } else if (val is EnumWrapper) { if (rtype == Typeob.String) { this.TranslateToIL(il, val.ToString(), rtype); return; } if (rtype.IsPrimitive) { this.TranslateToIL(il, ((EnumWrapper)val).ToNumericValue(), rtype); } else { Type type = ((EnumWrapper)val).type; Type type4 = Globals.TypeRefs.ToReferenceContext(((EnumWrapper)val).value.GetType()); this.TranslateToIL(il, ((EnumWrapper)val).value, type4); il.Emit(OpCodes.Box, type); Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype); } } else if (val is Type) { il.Emit(OpCodes.Ldtoken, (Type)val); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is Namespace) { il.Emit(OpCodes.Ldstr, ((Namespace)val).Name); base.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.getNamespaceMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.Namespace, rtype); } else if (val is ClassScope) { il.Emit(OpCodes.Ldtoken, ((ClassScope)val).GetTypeBuilderOrEnumBuilder()); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is TypedArray) { il.Emit(OpCodes.Ldtoken, Microsoft.JScript.Convert.ToType((TypedArray)val)); il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.Type, rtype); } else if (val is NumberObject) { this.TranslateToIL(il, ((NumberObject)val).value, Typeob.Object); base.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.NumberObject, rtype); } else if (val is StringObject) { il.Emit(OpCodes.Ldstr, ((StringObject)val).value); base.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.StringObject, rtype); } else if (val is BooleanObject) { il.Emit(((BooleanObject)val).value ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); il.Emit(OpCodes.Box, Typeob.Boolean); base.EmitILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.toObjectMethod); Microsoft.JScript.Convert.Emit(this, il, Typeob.BooleanObject, rtype); } else if (val is ActiveXObjectConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("ActiveXObject").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ArrayConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Array").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is BooleanConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Boolean").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is DateConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Date").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is EnumeratorConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Enumerator").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ErrorConstructor) { ErrorConstructor constructor = (ErrorConstructor)val; if (constructor == ErrorConstructor.evalOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("EvalError").GetGetMethod()); } else if (constructor == ErrorConstructor.rangeOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("RangeError").GetGetMethod()); } else if (constructor == ErrorConstructor.referenceOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("ReferenceError").GetGetMethod()); } else if (constructor == ErrorConstructor.syntaxOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("SyntaxError").GetGetMethod()); } else if (constructor == ErrorConstructor.typeOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("TypeError").GetGetMethod()); } else if (constructor == ErrorConstructor.uriOb) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("URIError").GetGetMethod()); } else { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Error").GetGetMethod()); } Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is FunctionConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Function").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is MathObject) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Math").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.JSObject, rtype); } else if (val is NumberConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Number").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is ObjectConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("Object").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is RegExpConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("RegExp").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is StringConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("String").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is VBArrayConstructor) { il.Emit(OpCodes.Call, Typeob.GlobalObject.GetProperty("VBArray").GetGetMethod()); Microsoft.JScript.Convert.Emit(this, il, Typeob.ScriptFunction, rtype); } else if (val is IntPtr) { il.Emit(OpCodes.Ldc_I8, (long)((IntPtr)val)); il.Emit(OpCodes.Conv_I); Microsoft.JScript.Convert.Emit(this, il, Typeob.IntPtr, rtype); } else if (val is UIntPtr) { il.Emit(OpCodes.Ldc_I8, (long)((ulong)((UIntPtr)val))); il.Emit(OpCodes.Conv_U); Microsoft.JScript.Convert.Emit(this, il, Typeob.UIntPtr, rtype); } else if (val is Microsoft.JScript.Missing) { il.Emit(OpCodes.Ldsfld, CompilerGlobals.missingField); Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype); } else if (val is System.Reflection.Missing) { if (rtype.IsPrimitive) { this.TranslateToIL(il, (double)1.0 / (double)0.0, rtype); } else if ((rtype != Typeob.Object) && !rtype.IsValueType) { il.Emit(OpCodes.Ldnull); } else { il.Emit(OpCodes.Ldsfld, CompilerGlobals.systemReflectionMissingField); Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype); } } else { if (val == this.value) { throw new JScriptException(JSError.InternalError, base.context); } this.TranslateToIL(il, this.value, rtype); } return; } if (!rtype.IsEnum) { if (val is EnumWrapper) { Microsoft.JScript.Convert.Emit(this, il, ((EnumWrapper)val).type, rtype); } else { Microsoft.JScript.Convert.Emit(this, il, Typeob.Int64, rtype); } } }