private object ImplEval(Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (cx.Version == Context.Versions.JS1_4) { Context.ReportWarningById("msg.cant.call.indirect", "eval"); return(ScriptRuntime.evalSpecial(cx, scope, thisObj, args, string.Empty, 0)); } throw ScriptRuntime.ConstructError("EvalError", ScriptRuntime.GetMessage("msg.cant.call.indirect", "eval")); }
internal static int AssertValidPrecision(int precision) { if (precision < 0 || precision > MAX_PRECISION) { string msg = ScriptRuntime.GetMessage("msg.bad.precision", ScriptConvert.ToString(precision)); throw ScriptRuntime.ConstructError("RangeError", msg); } return(precision); }
public void Load(string assembly) { try { ImportAssembly( this.ParentScope, Assembly.LoadWithPartialName(assembly)); } catch (FileNotFoundException e) { throw ScriptRuntime.ConstructError("EvalError", "Failed to load assembly: " + e.Message); } }
public virtual void Error(string message, string sourceURI, int line, string lineText, int lineOffset) { if (forEval) { throw ScriptRuntime.ConstructError("SyntaxError", message, sourceURI, line, lineText, lineOffset); } if (chainedReporter != null) { chainedReporter.Error(message, sourceURI, line, lineText, lineOffset); } else { throw RuntimeError(message, sourceURI, line, lineText, lineOffset); } }
private static string num_to(double val, object [] args, int zeroArgMode, int oneArgMode, int precisionMin, int precisionOffset) { int precision; if (args.Length == 0) { precision = 0; oneArgMode = zeroArgMode; } else { /* We allow a larger range of precision than * ECMA requires; this is permitted by ECMA. */ precision = ScriptConvert.ToInt32(args [0]); if (precision < precisionMin || precision > MAX_PRECISION) { string msg = ScriptRuntime.GetMessage("msg.bad.precision", ScriptConvert.ToString(args [0])); throw ScriptRuntime.ConstructError("RangeError", msg); } } switch (zeroArgMode) { case DTOSTR_FIXED: return(val.ToString("F" + (precision + precisionOffset), NumberFormatter)); case DTOSTR_STANDARD_EXPONENTIAL: return(val.ToString("e" + (precision + precisionOffset), NumberFormatter)); case DTOSTR_STANDARD: if (oneArgMode == DTOSTR_PRECISION) { return(val.ToString(precision.ToString(), NumberFormatter)); } else { return(val.ToString(NumberFormatter)); } } Context.CodeBug(); return(string.Empty); // Not reached }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable 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) ? ScriptConvert.ToNumber(args [0]) : 0.0; if (thisObj == null) { // new Number(val) creates a new Number object. return(new BuiltinNumber(val)); } // Number(val) converts val to a number value. return(val); } // The rest of Number.prototype methods require thisObj to be Number BuiltinNumber nativeNumber = (thisObj as BuiltinNumber); if (nativeNumber == null) { throw IncompatibleCallError(f); } double value = nativeNumber.doubleValue; int toBase = 0; switch (id) { case Id_toString: toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32(args [0]); return(ScriptConvert.ToString(value, toBase)); case Id_toLocaleString: { // toLocaleString is just an alias for toString for now toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32(args [0]); return(ScriptConvert.ToString(value, toBase)); } case Id_toSource: return("(new Number(" + ScriptConvert.ToString(value) + "))"); case Id_valueOf: return(value); case Id_toFixed: return(num_to(value, args, DTOSTR_FIXED, DTOSTR_FIXED, -20, 0)); case Id_toExponential: return(num_to(value, args, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0, 1)); case Id_toPrecision: { if (args.Length < 0 || args [0] == Undefined.Value) { return(ScriptConvert.ToString(value)); } int precision = ScriptConvert.ToInt32(args [0]); if (precision < 0 || precision > MAX_PRECISION) { throw ScriptRuntime.ConstructError("RangeError", ScriptRuntime.GetMessage("msg.bad.precision", ScriptConvert.ToString(args [0]))); } return(value.ToString(GetFormatString(precision))); } default: throw new ArgumentException(Convert.ToString(id)); } }