public JsInstance ParseInt(JsInstance[] arguments)
{
if (arguments.Length < 1 || arguments[0] == JsUndefined.Instance) {
return JsUndefined.Instance;
}
//in case of an enum, just cast it to an integer
if (arguments[0].IsClr && arguments[0].Value.GetType().IsEnum)
return NumberClass.New((int)arguments[0].Value);
string number = arguments[0].ToString().Trim();
int sign = 1;
int radix = 10;
if (number == String.Empty) {
return this["NaN"];
}
if (number.StartsWith("-")) {
number = number.Substring(1);
sign = -1;
}
else if (number.StartsWith("+")) {
number = number.Substring(1);
}
if (arguments.Length >= 2) {
if (arguments[1] != JsUndefined.Instance && !0.Equals(arguments[1])) {
radix = Convert.ToInt32(arguments[1].Value);
}
}
if (radix == 0) {
radix = 10;
}
else if (radix < 2 || radix > 36) {
return this["NaN"];
}
if (number.ToLower().StartsWith("0x")) {
radix = 16;
}
try {
return NumberClass.New(sign * Convert.ToInt32(number, radix));
}
catch {
return this["NaN"];
}
}