Rhino.NativeNumber.ExecIdCall C# (CSharp) Method

ExecIdCall() public method

public ExecIdCall ( IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object args ) : object
f IdFunctionObject
cx Context
scope Scriptable
thisObj Scriptable
args object
return object
		public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			if (!f.HasTag(NUMBER_TAG))
			{
				return base.ExecIdCall(f, cx, scope, thisObj, args);
			}
			int id = f.MethodId();
			if (id == Id_constructor)
			{
				double val = (args.Length >= 1) ? ScriptRuntime.ToNumber(args[0]) : 0.0;
				if (thisObj == null)
				{
					// new Number(val) creates a new Number object.
					return new Rhino.NativeNumber(val);
				}
				// Number(val) converts val to a number value.
				return ScriptRuntime.WrapNumber(val);
			}
			// The rest of Number.prototype methods require thisObj to be Number
			if (!(thisObj is Rhino.NativeNumber))
			{
				throw IncompatibleCallError(f);
			}
			double value = ((Rhino.NativeNumber)thisObj).doubleValue;
			switch (id)
			{
				case Id_toString:
				case Id_toLocaleString:
				{
					// toLocaleString is just an alias for toString for now
					int @base = (args.Length == 0 || args[0] == Undefined.instance) ? 10 : ScriptRuntime.ToInt32(args[0]);
					return ScriptRuntime.NumberToString(value, @base);
				}

				case Id_toSource:
				{
					return "(new Number(" + ScriptRuntime.ToString(value) + "))";
				}

				case Id_valueOf:
				{
					return ScriptRuntime.WrapNumber(value);
				}

				case Id_toFixed:
				{
					return Num_to(value, args, DToA.DTOSTR_FIXED, DToA.DTOSTR_FIXED, -20, 0);
				}

				case Id_toExponential:
				{
					// Handle special values before range check
					if (double.IsNaN(value))
					{
						return "NaN";
					}
					if (System.Double.IsInfinity(value))
					{
						if (value >= 0)
						{
							return "Infinity";
						}
						else
						{
							return "-Infinity";
						}
					}
					// General case
					return Num_to(value, args, DToA.DTOSTR_STANDARD_EXPONENTIAL, DToA.DTOSTR_EXPONENTIAL, 0, 1);
				}

				case Id_toPrecision:
				{
					// Undefined precision, fall back to ToString()
					if (args.Length == 0 || args[0] == Undefined.instance)
					{
						return ScriptRuntime.NumberToString(value, 10);
					}
					// Handle special values before range check
					if (double.IsNaN(value))
					{
						return "NaN";
					}
					if (System.Double.IsInfinity(value))
					{
						if (value >= 0)
						{
							return "Infinity";
						}
						else
						{
							return "-Infinity";
						}
					}
					return Num_to(value, args, DToA.DTOSTR_STANDARD, DToA.DTOSTR_PRECISION, 1, 0);
				}

				default:
				{
					throw new ArgumentException(id.ToString());
				}
			}
		}