public static DoubleToInt64 ( double val ) : System.Int64 | ||
val | double | |
Результат | System.Int64 |
internal object exec(string input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int startat = (int)Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(this.lastIndexInt)); if (startat <= 0) { match = this.regex.Match(input); } else if (startat <= input.Length) { match = this.regex.Match(input, startat); } } if ((match == null) || !match.Success) { this.lastIndexInt = 0; return(DBNull.Value); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(new RegExpMatch(this.regExpConst.arrayPrototype, this.regex, match, input)); }
public int Compare(Object x, Object y) { if (x == null || x is Missing) { if (y == null || y is Missing) { return(0); } else { return(1); } } else if (y == null || y is Missing) { return(-1); } if (this.compareFn != null) { double result = Convert.ToNumber(this.compareFn.Call(new Object[] { x, y }, null)); if (result != result) { throw new JScriptException(JSError.NumberExpected); } return((int)Runtime.DoubleToInt64(result)); } else { return(String.CompareOrdinal(Convert.ToString(x), Convert.ToString(y))); } }
internal bool test(string input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int startat = (int)Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(this.lastIndexInt)); if (startat <= 0) { match = this.regex.Match(input); } else if (startat <= input.Length) { match = this.regex.Match(input, startat); } } if ((match == null) || !match.Success) { this.lastIndexInt = 0; return(false); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(true); }
internal bool test(String input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int lastIndex = (int)Runtime.DoubleToInt64(Convert.ToInteger(this.lastIndexInt)); if (lastIndex <= 0) { match = this.regex.Match(input); } else if (lastIndex <= input.Length) { match = this.regex.Match(input, lastIndex); } } if (match == null || !match.Success) { this.lastIndexInt = 0; return(false); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(true); }
internal Object exec(String input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int lastIndex = (int)Runtime.DoubleToInt64(Convert.ToInteger(this.lastIndexInt)); if (lastIndex <= 0) { match = this.regex.Match(input); } else if (lastIndex <= input.Length) { match = this.regex.Match(input, lastIndex); } } if (match == null || !match.Success) { this.lastIndexInt = 0; return(DBNull.Value); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(new RegExpMatch(this.regExpConst.arrayPrototype, this.regex, match, input)); }
public static object DoOp(object v1, object v2) { IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(v1); IConvertible ic = Microsoft.JScript.Convert.GetIConvertible(v2); v1 = Microsoft.JScript.Convert.ToPrimitive(v1, PreferredType.Either, ref iConvertible); v2 = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Either, ref ic); TypeCode typeCode = Microsoft.JScript.Convert.GetTypeCode(v1, iConvertible); TypeCode tc = Microsoft.JScript.Convert.GetTypeCode(v2, ic); if (typeCode == TypeCode.String) { if (v1 is ConcatString) { return(new ConcatString((ConcatString)v1, Microsoft.JScript.Convert.ToString(v2, ic))); } return(new ConcatString(iConvertible.ToString(null), Microsoft.JScript.Convert.ToString(v2, ic))); } if (tc == TypeCode.String) { return(Microsoft.JScript.Convert.ToString(v1, iConvertible) + ic.ToString(null)); } if ((typeCode == TypeCode.Char) && (tc == TypeCode.Char)) { return(iConvertible.ToString(null) + ic.ToString(null)); } if (((typeCode != TypeCode.Char) || (!Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(tc) && (tc != TypeCode.Boolean))) && ((tc != TypeCode.Char) || (!Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(typeCode) && (typeCode != TypeCode.Boolean)))) { return(Microsoft.JScript.Convert.ToNumber(v1, iConvertible) + Microsoft.JScript.Convert.ToNumber(v2, ic)); } return((char)((int)Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToNumber(v1, iConvertible) + Microsoft.JScript.Convert.ToNumber(v2, ic)))); }
private int Compare(object x, object y) { if ((x == null) || (x is Missing)) { if ((y != null) && !(y is Missing)) { return(1); } return(0); } if ((y == null) || (y is Missing)) { return(-1); } if (this.compareFn == null) { return(string.CompareOrdinal(Microsoft.JScript.Convert.ToString(x), Microsoft.JScript.Convert.ToString(y))); } double val = Microsoft.JScript.Convert.ToNumber(this.compareFn.Call(new object[] { x, y }, null)); if (val != val) { throw new JScriptException(JSError.NumberExpected); } return((int)Runtime.DoubleToInt64(val)); }
public static ArrayObject slice(Object thisob, VsaEngine engine, double start, Object end) { ArrayObject array = engine.GetOriginalArrayConstructor().Construct(); uint length = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); // compute the start index long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start)); if (startIndex < 0) { startIndex = length + startIndex; if (startIndex < 0) { startIndex = 0; } } else if (startIndex > length) { startIndex = length; } // compute the end index long endIndex = length; if (end != null && !(end is Missing)) { endIndex = Runtime.DoubleToInt64(Convert.ToInteger(end)); if (endIndex < 0) { endIndex = length + endIndex; if (endIndex < 0) { endIndex = 0; } } else if (endIndex > length) { endIndex = length; } } // slice if (endIndex > startIndex) { array.length = endIndex - startIndex; for (ulong i = (ulong)startIndex, j = 0; i < (ulong)endIndex; i++, j++) { Object val = LateBinding.GetValueAtIndex(thisob, i); if (!(val is Missing)) { LateBinding.SetValueAtIndex(array, j, val); } } } return(array); }
public static ArrayObject slice(object thisob, VsaEngine engine, double start, object end) { ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); long num2 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start)); if (num2 < 0L) { num2 = num + num2; if (num2 < 0L) { num2 = 0L; } } else if (num2 > num) { num2 = num; } long num3 = num; if ((end != null) && !(end is Missing)) { num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(end)); if (num3 < 0L) { num3 = num + num3; if (num3 < 0L) { num3 = 0L; } } else if (num3 > num) { num3 = num; } } if (num3 > num2) { obj2.length = num3 - num2; ulong index = (ulong)num2; for (ulong i = 0L; index < num3; i += (ulong)1L) { object valueAtIndex = LateBinding.GetValueAtIndex(thisob, index); if (!(valueAtIndex is Missing)) { LateBinding.SetValueAtIndex(obj2, i, valueAtIndex); } index += (ulong)1L; } } return(obj2); }
public new DateObject CreateInstance(params Object[] args) { if (args.Length == 0) { return(new DateObject(this.originalPrototype, DateTime.Now.ToUniversalTime().Ticks / DatePrototype.ticksPerMillisecond - DatePrototype.msTo1970)); } if (args.Length == 1) { Object arg0 = args[0]; IConvertible ic = Convert.GetIConvertible(arg0); TypeCode tcode = Convert.GetTypeCode(arg0, ic); if (tcode == TypeCode.DateTime) { return(new DateObject(this.originalPrototype, ic.ToDateTime(null).ToUniversalTime().Ticks / DatePrototype.ticksPerMillisecond - DatePrototype.msTo1970)); } Object yv = Convert.ToPrimitive(arg0, PreferredType.Either, ref ic); if (Convert.GetTypeCode(yv, ic) == TypeCode.String) { return(new DateObject(this.originalPrototype, parse(ic.ToString(null)))); } double d = Convert.ToNumber(yv, ic); if (DatePrototype.minDate <= d && d <= DatePrototype.maxDate) { return(new DateObject(this.originalPrototype, d)); } return(new DateObject(this.originalPrototype, Double.NaN)); } double dyear = Convert.ToNumber(args[0]); double dmonth = Convert.ToNumber(args[1]); double ddate = (args.Length > 2) ? Convert.ToNumber(args[2]) : 1; double dhours = (args.Length > 3) ? Convert.ToNumber(args[3]) : 0; double dminutes = (args.Length > 4) ? Convert.ToNumber(args[4]) : 0; double dseconds = (args.Length > 5) ? Convert.ToNumber(args[5]) : 0; double dms = (args.Length > 6) ? Convert.ToNumber(args[6]) : 0; int y = (int)Runtime.DoubleToInt64(dyear); if (!Double.IsNaN(dyear) && 0 <= y && y <= 99) { dyear = y + 1900; } double day = DatePrototype.MakeDay(dyear, dmonth, ddate); double time = DatePrototype.MakeTime(dhours, dminutes, dseconds, dms); return(new DateObject(this.originalPrototype, DatePrototype.TimeClip(DatePrototype.UTC(DatePrototype.MakeDate(day, time))))); }
public DateObject CreateInstance(params object[] args) { if (args.Length == 0) { return(new DateObject(this.originalPrototype, (((double)DateTime.Now.ToUniversalTime().Ticks) / 10000.0) - 62135596800000)); } if (args.Length == 1) { object ob = args[0]; IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob); if (Microsoft.JScript.Convert.GetTypeCode(ob, iConvertible) == TypeCode.DateTime) { return(new DateObject(this.originalPrototype, (((double)iConvertible.ToDateTime(null).ToUniversalTime().Ticks) / 10000.0) - 62135596800000)); } object obj3 = Microsoft.JScript.Convert.ToPrimitive(ob, PreferredType.Either, ref iConvertible); if (Microsoft.JScript.Convert.GetTypeCode(obj3, iConvertible) == TypeCode.String) { return(new DateObject(this.originalPrototype, parse(iConvertible.ToString(null)))); } double num = Microsoft.JScript.Convert.ToNumber(obj3, iConvertible); if ((-8.64E+15 <= num) && (num <= 8.64E+15)) { return(new DateObject(this.originalPrototype, num)); } return(new DateObject(this.originalPrototype, double.NaN)); } double val = Microsoft.JScript.Convert.ToNumber(args[0]); double month = Microsoft.JScript.Convert.ToNumber(args[1]); double date = (args.Length > 2) ? Microsoft.JScript.Convert.ToNumber(args[2]) : 1.0; double hour = (args.Length > 3) ? Microsoft.JScript.Convert.ToNumber(args[3]) : 0.0; double min = (args.Length > 4) ? Microsoft.JScript.Convert.ToNumber(args[4]) : 0.0; double sec = (args.Length > 5) ? Microsoft.JScript.Convert.ToNumber(args[5]) : 0.0; double ms = (args.Length > 6) ? Microsoft.JScript.Convert.ToNumber(args[6]) : 0.0; int num9 = (int)Runtime.DoubleToInt64(val); if ((!double.IsNaN(val) && (0 <= num9)) && (num9 <= 0x63)) { val = num9 + 0x76c; } double day = DatePrototype.MakeDay(val, month, date); double time = DatePrototype.MakeTime(hour, min, sec, ms); return(new DateObject(this.originalPrototype, DatePrototype.TimeClip(DatePrototype.UTC(DatePrototype.MakeDate(day, time))))); }
public static Object DoOp(Object v1, Object v2) { IConvertible ic1 = Convert.GetIConvertible(v1); IConvertible ic2 = Convert.GetIConvertible(v2); v1 = Convert.ToPrimitive(v1, PreferredType.Either, ref ic1); v2 = Convert.ToPrimitive(v2, PreferredType.Either, ref ic2); TypeCode t1 = Convert.GetTypeCode(v1, ic1); TypeCode t2 = Convert.GetTypeCode(v2, ic2); if (t1 == TypeCode.String) { if (v1 is ConcatString) { return(new ConcatString((ConcatString)v1, Convert.ToString(v2, ic2))); } else { return(new ConcatString(ic1.ToString(null), Convert.ToString(v2, ic2))); } } else if (t2 == TypeCode.String) { return(Convert.ToString(v1, ic1) + ic2.ToString(null)); } else if (t1 == TypeCode.Char && t2 == TypeCode.Char) { return(ic1.ToString(null) + ic2.ToString(null)); } else if ((t1 == TypeCode.Char && (Convert.IsPrimitiveNumericTypeCode(t2) || t2 == TypeCode.Boolean)) || (t2 == TypeCode.Char && (Convert.IsPrimitiveNumericTypeCode(t1) || t1 == TypeCode.Boolean))) { return((char)(int)Runtime.DoubleToInt64(Convert.ToNumber(v1, ic1) + Convert.ToNumber(v2, ic2))); } else { return(Convert.ToNumber(v1, ic1) + Convert.ToNumber(v2, ic2)); } }
public static String substr(Object thisob, double start, Object count) { String thisStr = thisob as String; if (thisStr == null) { thisStr = Convert.ToString(thisob); } int length = thisStr.Length; double startIndex = Convert.ToInteger(start); if (startIndex < 0) { startIndex += length; } if (startIndex < 0) { startIndex = 0; } else if (startIndex > length) { startIndex = length; } int nChars = count is int?(int)count: ((count == null || count is Missing) ? length - (int)Runtime.DoubleToInt64(startIndex) : (int)Runtime.DoubleToInt64(Convert.ToInteger(count))); if (startIndex + nChars > length) { nChars = length - (int)startIndex; } if (nChars <= 0) { return(""); } else { return(thisStr.Substring((int)startIndex, nChars)); } }
public static double UTC(object year, object month, object date, object hours, object minutes, object seconds, object ms) { if (year is Missing) { return((((double)DateTime.Now.ToUniversalTime().Ticks) / 10000.0) - 62135596800000); } double val = Microsoft.JScript.Convert.ToNumber(year); double num2 = (month is Missing) ? 0.0 : Microsoft.JScript.Convert.ToNumber(month); double num3 = (date is Missing) ? 1.0 : Microsoft.JScript.Convert.ToNumber(date); double hour = (hours is Missing) ? 0.0 : Microsoft.JScript.Convert.ToNumber(hours); double min = (minutes is Missing) ? 0.0 : Microsoft.JScript.Convert.ToNumber(minutes); double sec = (seconds is Missing) ? 0.0 : Microsoft.JScript.Convert.ToNumber(seconds); double num7 = (ms is Missing) ? 0.0 : Microsoft.JScript.Convert.ToNumber(ms); int num8 = (int)Runtime.DoubleToInt64(val); if ((!double.IsNaN(val) && (0 <= num8)) && (num8 <= 0x63)) { val = num8 + 0x76c; } double day = DatePrototype.MakeDay(val, num2, num3); double time = DatePrototype.MakeTime(hour, min, sec, num7); return(DatePrototype.TimeClip(DatePrototype.MakeDate(day, time))); }
public static double UTC(Object year, Object month, Object date, Object hours, Object minutes, Object seconds, Object ms) { if (year is Missing) { return(DateTime.Now.ToUniversalTime().Ticks / DatePrototype.ticksPerMillisecond - DatePrototype.msTo1970); } double dyear = Convert.ToNumber(year); double dmonth = month is Missing ? 0 : Convert.ToNumber(month); double ddate = date is Missing ? 1 : Convert.ToNumber(date); double dhours = hours is Missing ? 0 : Convert.ToNumber(hours); double dminutes = minutes is Missing ? 0 : Convert.ToNumber(minutes); double dseconds = seconds is Missing ? 0 : Convert.ToNumber(seconds); double dms = ms is Missing ? 0 : Convert.ToNumber(ms); int y = (int)Runtime.DoubleToInt64(dyear); if (!Double.IsNaN(dyear) && 0 <= y && y <= 99) { dyear = y + 1900; } double day = DatePrototype.MakeDay(dyear, dmonth, ddate); double time = DatePrototype.MakeTime(dhours, dminutes, dseconds, dms); return(DatePrototype.TimeClip(DatePrototype.MakeDate(day, time))); }
private object EvaluateBitwiseBinary(object v1, object v2, JSToken operatorTok) { int num; IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(v1); IConvertible ic = Microsoft.JScript.Convert.GetIConvertible(v2); TypeCode typeCode = Microsoft.JScript.Convert.GetTypeCode(v1, iConvertible); TypeCode code2 = Microsoft.JScript.Convert.GetTypeCode(v2, ic); switch (typeCode) { case TypeCode.Empty: case TypeCode.DBNull: return(this.EvaluateBitwiseBinary(0, v2, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: num = iConvertible.ToInt32(null); switch (code2) { case TypeCode.Empty: case TypeCode.DBNull: return(DoOp(num, 0, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(DoOp(num, ic.ToInt32(null), operatorTok)); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: return(DoOp(num, (int)Runtime.DoubleToInt64(ic.ToDouble(null)), operatorTok)); } break; case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: num = (int)Runtime.DoubleToInt64(iConvertible.ToDouble(null)); switch (code2) { case TypeCode.Empty: case TypeCode.DBNull: return(DoOp(num, 0, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(DoOp(num, ic.ToInt32(null), operatorTok)); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: return(DoOp(num, (int)Runtime.DoubleToInt64(ic.ToDouble(null)), operatorTok)); } break; } if (v2 == null) { return(DoOp(Microsoft.JScript.Convert.ToInt32(v1), 0, base.operatorTok)); } MethodInfo @operator = base.GetOperator(v1.GetType(), v2.GetType()); if (@operator != null) { return(@operator.Invoke(null, BindingFlags.Default, JSBinder.ob, new object[] { v1, v2 }, null)); } return(DoOp(Microsoft.JScript.Convert.ToInt32(v1), Microsoft.JScript.Convert.ToInt32(v2), base.operatorTok)); }
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, Typeob.Null.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, rtype); } else { Convert.Emit(this, il, Globals.TypeRefs.ToReferenceContext(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, 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, 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, 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)Runtime.DoubleToInt64(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)Runtime.DoubleToInt64(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(Globals.TypeRefs.ToReferenceContext(val.GetType())), CultureInfo.InvariantCulture), rtype); } else { Type et = Globals.TypeRefs.ToReferenceContext(val.GetType()); Type ut = Enum.GetUnderlyingType(et); this.TranslateToIL(il, System.Convert.ChangeType(val, ut, CultureInfo.InvariantCulture), 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; Type ut = Globals.TypeRefs.ToReferenceContext(((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, Typeob.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, Typeob.IntPtr, rtype); } else if (val is UIntPtr) { il.Emit(OpCodes.Ldc_I8, (long)(UIntPtr)val); il.Emit(OpCodes.Conv_U); Convert.Emit(this, il, Typeob.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 } }
public object EvaluateUnary(object v) { IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(v); switch (Microsoft.JScript.Convert.GetTypeCode(v, iConvertible)) { case TypeCode.Empty: return(this.EvaluateUnary((double)1.0 / (double)0.0)); case TypeCode.DBNull: return(this.EvaluateUnary(0)); case TypeCode.Boolean: return(this.EvaluateUnary(iConvertible.ToBoolean(null) ? 1 : 0)); case TypeCode.Char: return(this.EvaluateUnary((int)iConvertible.ToChar(null))); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: { int num = iConvertible.ToInt32(null); switch (this.operatorTok) { case JSToken.FirstOp: return(num == 0); case JSToken.BitwiseNot: return(~num); case JSToken.FirstBinaryOp: return(num); case JSToken.Minus: switch (num) { case 0: return(-((double)num)); case -2147483648: return((ulong)-((double)num)); } return(-num); } throw new JScriptException(JSError.InternalError, base.context); } case TypeCode.UInt32: { uint num2 = iConvertible.ToUInt32(null); switch (this.operatorTok) { case JSToken.FirstOp: return(num2 == 0); case JSToken.BitwiseNot: return(~num2); case JSToken.FirstBinaryOp: return(num2); case JSToken.Minus: if ((num2 != 0) && (num2 <= 0x7fffffff)) { return((int)-num2); } return(-((double)num2)); } throw new JScriptException(JSError.InternalError, base.context); } case TypeCode.Int64: { long num3 = iConvertible.ToInt64(null); switch (this.operatorTok) { case JSToken.FirstOp: return(num3 == 0L); case JSToken.BitwiseNot: return(~num3); case JSToken.FirstBinaryOp: return(num3); case JSToken.Minus: if ((num3 != 0L) && (num3 != -9223372036854775808L)) { return(-num3); } return(-((double)num3)); } throw new JScriptException(JSError.InternalError, base.context); } case TypeCode.UInt64: { ulong num4 = iConvertible.ToUInt64(null); switch (this.operatorTok) { case JSToken.FirstOp: return(num4 == 0L); case JSToken.BitwiseNot: return(~num4); case JSToken.FirstBinaryOp: return(num4); case JSToken.Minus: if ((num4 != 0L) && (num4 <= 0x7fffffffffffffffL)) { return((long)-num4); } return(-((double)num4)); } throw new JScriptException(JSError.InternalError, base.context); } case TypeCode.Single: case TypeCode.Double: { double d = iConvertible.ToDouble(null); switch (this.operatorTok) { case JSToken.FirstOp: return(!Microsoft.JScript.Convert.ToBoolean(d)); case JSToken.BitwiseNot: return(~((int)Runtime.DoubleToInt64(d))); case JSToken.FirstBinaryOp: return(d); case JSToken.Minus: return(-d); } throw new JScriptException(JSError.InternalError, base.context); } case TypeCode.String: break; default: { MethodInfo @operator = this.GetOperator(v.GetType()); if (@operator != null) { return(@operator.Invoke(null, BindingFlags.Default, JSBinder.ob, new object[] { v }, null)); } break; } } switch (this.operatorTok) { case JSToken.FirstOp: return(!Microsoft.JScript.Convert.ToBoolean(v, iConvertible)); case JSToken.BitwiseNot: return(~Microsoft.JScript.Convert.ToInt32(v, iConvertible)); case JSToken.FirstBinaryOp: return(Microsoft.JScript.Convert.ToNumber(v, iConvertible)); case JSToken.Minus: return(-Microsoft.JScript.Convert.ToNumber(v, iConvertible)); } throw new JScriptException(JSError.InternalError, base.context); }
public static ArrayObject splice(Object thisob, VsaEngine engine, double start, double deleteCnt, params Object[] args) { uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); // compute the start index long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start)); if (startIndex < 0) { startIndex = oldLength + startIndex; if (startIndex < 0) { startIndex = 0; } } else if (startIndex > oldLength) { startIndex = oldLength; } // compute the number of items to delete long deleteCount = Runtime.DoubleToInt64(Convert.ToInteger(deleteCnt)); if (deleteCount < 0) { deleteCount = 0; } else if (deleteCount > oldLength - startIndex) { deleteCount = oldLength - startIndex; } long newLength = oldLength + args.Length - deleteCount; // create an array for the result ArrayObject result = engine.GetOriginalArrayConstructor().Construct(); result.length = deleteCount; // special case array objects (nice speedup if dense) if (thisob is ArrayObject) { ((ArrayObject)thisob).Splice((uint)startIndex, (uint)deleteCount, args, result, (uint)oldLength, (uint)newLength); return(result); } // copy the deleted items to the result array for (ulong i = 0; i < (ulong)deleteCount; i++) { result.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + (ulong)startIndex)); } // shift the remaining elements left or right long n = oldLength - startIndex - deleteCount; if (newLength < oldLength) { for (long i = 0; i < n; i++) { LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount))); } LateBinding.SetMemberValue(thisob, "length", newLength); } else { LateBinding.SetMemberValue(thisob, "length", newLength); for (long i = n - 1; i >= 0; i--) { LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount))); } } // splice in the arguments int m = args == null ? 0 : args.Length; for (uint i = 0; i < m; i++) { LateBinding.SetValueAtIndex(thisob, i + (ulong)startIndex, args[i]); } return(result); }
private Object EvaluateBitwiseBinary(Object v1, Object v2, JSToken operatorTok) { IConvertible ic1 = Convert.GetIConvertible(v1); IConvertible ic2 = Convert.GetIConvertible(v2); TypeCode t1 = Convert.GetTypeCode(v1, ic1); TypeCode t2 = Convert.GetTypeCode(v2, ic2); switch (t1) { case TypeCode.Empty: case TypeCode.DBNull: return(EvaluateBitwiseBinary(0, v2, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: int i = ic1.ToInt32(null); switch (t2) { case TypeCode.Empty: case TypeCode.DBNull: return(DoOp(i, 0, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(DoOp(i, ic2.ToInt32(null), operatorTok)); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: return(DoOp(i, (int)Runtime.DoubleToInt64(ic2.ToDouble(null)), operatorTok)); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: case TypeCode.String: break; } break; case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: i = (int)Runtime.DoubleToInt64(ic1.ToDouble(null)); switch (t2) { case TypeCode.Empty: case TypeCode.DBNull: return(DoOp(i, 0, operatorTok)); case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: return(DoOp(i, ic2.ToInt32(null), operatorTok)); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: return(DoOp(i, (int)Runtime.DoubleToInt64(ic2.ToDouble(null)), operatorTok)); case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: case TypeCode.String: break; } break; case TypeCode.Object: case TypeCode.Decimal: case TypeCode.DateTime: case TypeCode.String: break; } if (v2 == null) { return(DoOp(Convert.ToInt32(v1), 0, this.operatorTok)); } MethodInfo oper = this.GetOperator(v1.GetType(), v2.GetType()); if (oper != null) { return(oper.Invoke(null, (BindingFlags)0, JSBinder.ob, new Object[] { v1, v2 }, null)); } else { return(DoOp(Convert.ToInt32(v1), Convert.ToInt32(v2), this.operatorTok)); } }
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); } } }
public Object EvaluateUnary(Object v) { IConvertible ic = Convert.GetIConvertible(v); switch (Convert.GetTypeCode(v, ic)) { case TypeCode.Empty: return(this.EvaluateUnary(Double.NaN)); case TypeCode.DBNull: return(this.EvaluateUnary(0)); case TypeCode.Boolean: return(this.EvaluateUnary(ic.ToBoolean(null) ? 1 : 0)); case TypeCode.Char: return(this.EvaluateUnary((int)ic.ToChar(null))); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: int i = ic.ToInt32(null); switch (this.operatorTok) { case JSToken.BitwiseNot: return(~i); case JSToken.LogicalNot: return(i == 0); case JSToken.Minus: if (i == 0) { return(-(double)i); } if (i == Int32.MinValue) { return((ulong)-(double)i); } return(-i); case JSToken.Plus: return(i); default: throw new JScriptException(JSError.InternalError, this.context); } case TypeCode.UInt32: uint ui = ic.ToUInt32(null); switch (this.operatorTok) { case JSToken.BitwiseNot: return(~ui); case JSToken.LogicalNot: return(ui == 0); case JSToken.Minus: if (ui != 0 && ui <= Int32.MaxValue) { return(-(int)ui); } else { return(-(double)ui); } case JSToken.Plus: return(ui); default: throw new JScriptException(JSError.InternalError, this.context); } case TypeCode.Int64: long l = ic.ToInt64(null); switch (this.operatorTok) { case JSToken.BitwiseNot: return(~l); case JSToken.LogicalNot: return(l == 0); case JSToken.Minus: if (l == 0 || l == Int64.MinValue) { return(-(double)l); } return(-l); case JSToken.Plus: return(l); default: throw new JScriptException(JSError.InternalError, this.context); } case TypeCode.UInt64: ulong ul = ic.ToUInt64(null); switch (this.operatorTok) { case JSToken.BitwiseNot: return(~ul); case JSToken.LogicalNot: return(ul == 0); case JSToken.Minus: if (ul != 0 && ul <= Int64.MaxValue) { return(-(long)ul); } else { return(-(double)ul); } case JSToken.Plus: return(ul); default: throw new JScriptException(JSError.InternalError, this.context); } case TypeCode.Single: case TypeCode.Double: double d = ic.ToDouble(null); switch (this.operatorTok) { case JSToken.BitwiseNot: return(~(int)Runtime.DoubleToInt64(d)); case JSToken.LogicalNot: return(!Convert.ToBoolean(d)); case JSToken.Minus: return(-d); case JSToken.Plus: return(d); default: throw new JScriptException(JSError.InternalError, this.context); } case TypeCode.String: goto no_overload_case; } MethodInfo oper = this.GetOperator(v.GetType()); if (oper != null) { return(oper.Invoke(null, (BindingFlags)0, JSBinder.ob, new Object[] { v }, null)); } no_overload_case: switch (this.operatorTok) { case JSToken.BitwiseNot: return(~Convert.ToInt32(v, ic)); case JSToken.LogicalNot: return(!Convert.ToBoolean(v, ic)); case JSToken.Minus: return(-Convert.ToNumber(v, ic)); case JSToken.Plus: return(Convert.ToNumber(v, ic)); default: throw new JScriptException(JSError.InternalError, this.context); } }
public static ArrayObject splice(object thisob, VsaEngine engine, double start, double deleteCnt, params object[] args) { uint oldLength = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); long num2 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start)); if (num2 < 0L) { num2 = oldLength + num2; if (num2 < 0L) { num2 = 0L; } } else if (num2 > oldLength) { num2 = oldLength; } long num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(deleteCnt)); if (num3 < 0L) { num3 = 0L; } else if (num3 > (oldLength - num2)) { num3 = oldLength - num2; } long num4 = (oldLength + args.Length) - num3; ArrayObject outArray = engine.GetOriginalArrayConstructor().Construct(); outArray.length = num3; if (thisob is ArrayObject) { ((ArrayObject)thisob).Splice((uint)num2, (uint)num3, args, outArray, oldLength, (uint)num4); return(outArray); } for (ulong i = 0L; i < num3; i += (ulong)1L) { outArray.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + ((ulong)num2))); } long num6 = (oldLength - num2) - num3; if (num4 < oldLength) { for (long k = 0L; k < num6; k += 1L) { LateBinding.SetValueAtIndex(thisob, (ulong)((k + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((k + num2) + num3))); } LateBinding.SetMemberValue(thisob, "length", num4); } else { LateBinding.SetMemberValue(thisob, "length", num4); for (long m = num6 - 1L; m >= 0L; m -= 1L) { LateBinding.SetValueAtIndex(thisob, (ulong)((m + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((m + num2) + num3))); } } int num9 = (args == null) ? 0 : args.Length; for (uint j = 0; j < num9; j++) { LateBinding.SetValueAtIndex(thisob, (ulong)(j + num2), args[j]); } return(outArray); }
public static string substr(object thisob, double start, object count) { string str = thisob as string; if (str == null) { str = Microsoft.JScript.Convert.ToString(thisob); } int length = str.Length; double val = Microsoft.JScript.Convert.ToInteger(start); if (val < 0.0) { val += length; } if (val < 0.0) { val = 0.0; } else if (val > length) { val = length; } int num3 = (count is int) ? ((int)count) : (((count == null) || (count is Missing)) ? (length - ((int)Runtime.DoubleToInt64(val))) : ((int)Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(count)))); if ((val + num3) > length) { num3 = length - ((int)val); } if (num3 <= 0) { return(""); } return(str.Substring((int)val, num3)); }