public JsGlobal(ExecutionVisitor visitor, Options options) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; #region Global Classes this["Object"] = ObjectClass = new JsObjectConstructor(this); this["Function"] = FunctionClass = new JsFunctionConstructor(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); this.Prototype = ObjectClass.Prototype; #endregion MathClass.Prototype = ObjectClass.Prototype; foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsInstance.THIS] = this; #endregion #region Global Functions this["eval"] = new JsFunctionWrapper(Eval); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN); this["isFinite"] = new JsFunctionWrapper(isFinite); this["decodeURI"] = new JsFunctionWrapper(DecodeURI); this["encodeURI"] = new JsFunctionWrapper(EncodeURI); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent); #endregion }
public JsInstance ToTimeStringImpl(JsDictionaryObject target, JsInstance[] parameters) { if (double.IsNaN(target.ToNumber())) { return((JsInstance)this.Global.StringClass.New(double.NaN.ToString())); } JsStringConstructor stringClass = this.Global.StringClass; DateTime dateTime = JsDateConstructor.CreateDateTime(target.ToNumber()); dateTime = dateTime.ToLocalTime(); string str = dateTime.ToString(JsDate.TIMEFORMAT, (IFormatProvider)CultureInfo.InvariantCulture); return((JsInstance)stringClass.New(str)); }
public JsInstance ToLocaleDateStringImpl( JsDictionaryObject target, JsInstance[] parameters) { if (double.IsNaN(target.ToNumber())) { return((JsInstance)this.Global.StringClass.New(double.NaN.ToString())); } JsStringConstructor stringClass = this.Global.StringClass; DateTime dateTime = JsDateConstructor.CreateDateTime(target.ToNumber()); dateTime = dateTime.ToLocalTime(); string str = dateTime.ToString(JsDate.DATEFORMAT); return((JsInstance)stringClass.New(str)); }
public JsGlobal(ExecutionVisitor visitor, Options options) : base(JsNull.Instance) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; JsObject objectProrotype = new JsObject(JsNull.Instance); JsFunction functionPrototype = new JsFunctionWrapper( delegate(JsInstance[] arguments) { return(JsUndefined.Instance); }, objectProrotype ); Marshaller = new Marshaller(this); #region Global Classes this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype); this["Object"] = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype); ObjectClass.InitPrototype(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); // 15.1 prototype of the global object varies on the implementation //this.Prototype = ObjectClass.PrototypeProperty; #endregion foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsScope.THIS] = this; #endregion #region Global Functions // every embed function should have a prototype FunctionClass.PrototypeProperty - 15. this["eval"] = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty); this["isFinite"] = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty); this["decodeURI"] = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty); this["encodeURI"] = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty); #endregion Marshaller.InitTypes(); }
public JsGlobal(ExecutionVisitor visitor, Options options) : base(JsNull.Instance) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; JsObject objectProrotype = new JsObject(JsNull.Instance); JsFunction functionPrototype = new JsFunctionWrapper( delegate(JsInstance[] arguments) { return JsUndefined.Instance; }, objectProrotype ); Marshaller = new Marshaller(this); #region Global Classes this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype); this["Object"] = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype); ObjectClass.InitPrototype(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); // 15.1 prototype of the global object varies on the implementation //this.Prototype = ObjectClass.PrototypeProperty; #endregion foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsScope.THIS] = this; #endregion #region Global Functions // every embed function should have a prototype FunctionClass.PrototypeProperty - 15. this["eval"] = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3 this["isNaN"] = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty); this["isFinite"] = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty); this["decodeURI"] = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty); this["encodeURI"] = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty); #endregion Marshaller.InitTypes(); }
public JsInstance ReplaceImpl(JsDictionaryObject target, JsInstance[] parameters) { if (parameters.Length == 0) { return((JsInstance)this.Global.StringClass.New(target.ToString())); } JsInstance parameter = parameters[0]; JsInstance jsInstance = (JsInstance)JsUndefined.Instance; if (parameters.Length > 1) { jsInstance = parameters[1]; } string source = target.ToString(); JsFunction function = jsInstance as JsFunction; if (parameter.Class == "RegExp") { int count = ((JsRegExp)parameters[0]).IsGlobal ? int.MaxValue : 1; JsRegExp regexp = (JsRegExp)parameters[0]; int startat = regexp.IsGlobal ? 0 : Math.Max(0, (int)regexp["lastIndex"].ToNumber() - 1); if (regexp.IsGlobal) { regexp["lastIndex"] = (JsInstance)this.Global.NumberClass.New(0.0); } if (jsInstance is JsFunction) { return((JsInstance)this.Global.StringClass.New(((JsRegExp)parameters[0]).Regex.Replace(source, (MatchEvaluator)(m => { List <JsInstance> jsInstanceList = new List <JsInstance>(); if (!regexp.IsGlobal) { regexp["lastIndex"] = (JsInstance)this.Global.NumberClass.New((double)(m.Index + 1)); } jsInstanceList.Add((JsInstance)this.Global.StringClass.New(m.Value)); for (int index = 1; index < m.Groups.Count; ++index) { if (m.Groups[index].Success) { jsInstanceList.Add((JsInstance)this.Global.StringClass.New(m.Groups[index].Value)); } else { jsInstanceList.Add((JsInstance)JsUndefined.Instance); } } jsInstanceList.Add((JsInstance)this.Global.NumberClass.New((double)m.Index)); jsInstanceList.Add((JsInstance)this.Global.StringClass.New(source)); this.Global.Visitor.ExecuteFunction(function, (JsDictionaryObject)null, jsInstanceList.ToArray()); return this.Global.Visitor.Returned.ToString(); }), count, startat))); } string str = parameters[1].ToString(); return((JsInstance)this.Global.StringClass.New(((JsRegExp)parameters[0]).Regex.Replace(target.ToString(), (MatchEvaluator)(m => { if (!regexp.IsGlobal) { regexp["lastIndex"] = (JsInstance)this.Global.NumberClass.New((double)(m.Index + 1)); } string after = source.Substring(Math.Min(source.Length - 1, m.Index + m.Length)); return JsStringConstructor.EvaluateReplacePattern(m.Value, source.Substring(0, m.Index), after, str, m.Groups); }), count, startat))); } string matched = parameter.ToString(); int length = source.IndexOf(matched); if (length == -1) { return((JsInstance)this.Global.StringClass.New(source)); } if (jsInstance is JsFunction) { this.Global.Visitor.ExecuteFunction(function, (JsDictionaryObject)null, new List <JsInstance>() { (JsInstance)this.Global.StringClass.New(matched), (JsInstance)this.Global.NumberClass.New((double)length), (JsInstance)this.Global.StringClass.New(source) }.ToArray()); JsInstance result = this.Global.Visitor.Result; return((JsInstance)this.Global.StringClass.New(source.Substring(0, length) + result.ToString() + source.Substring(length + matched.Length))); } string before = source.Substring(0, length); string after1 = source.Substring(length + matched.Length); string replacePattern = JsStringConstructor.EvaluateReplacePattern(matched, before, after1, jsInstance.ToString(), (GroupCollection)null); return((JsInstance)this.Global.StringClass.New(before + replacePattern + after1)); }
public JsGlobal(IJintVisitor visitor, Options options) { this.Options = options; this.Visitor = visitor; this["null"] = JsNull.Instance; #region Global Classes this["Object"] = ObjectClass = new JsObjectConstructor(this); this["Function"] = FunctionClass = new JsFunctionConstructor(this); this["Array"] = ArrayClass = new JsArrayConstructor(this); this["Boolean"] = BooleanClass = new JsBooleanConstructor(this); this["Date"] = DateClass = new JsDateConstructor(this); // overriten by 1C function this["Error"] = ErrorClass = new JsErrorConstructor(this, "Error"); this["EvalError"] = EvalErrorClass = new JsErrorConstructor(this, "EvalError"); this["RangeError"] = RangeErrorClass = new JsErrorConstructor(this, "RangeError"); this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError"); this["SyntaxError"] = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError"); this["TypeError"] = TypeErrorClass = new JsErrorConstructor(this, "TypeError"); this["URIError"] = URIErrorClass = new JsErrorConstructor(this, "URIError"); this["Number"] = NumberClass = new JsNumberConstructor(this); this["RegExp"] = RegExpClass = new JsRegExpConstructor(this); this["String"] = StringClass = new JsStringConstructor(this); this["Math"] = MathClass = new JsMathConstructor(this); this.Prototype = ObjectClass.Prototype; #endregion MathClass.Prototype = ObjectClass.Prototype; foreach (JsInstance c in this.GetValues()) { if (c is JsConstructor) { ((JsConstructor)c).InitPrototype(this); } } #region Global Properties this["NaN"] = NumberClass["NaN"]; // 15.1.1.1 this["Infinity"] = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2 this["undefined"] = JsUndefined.Instance; // 15.1.1.3 this[JsInstance.THIS] = this; #endregion #region Global Functions this["eval"] = new JsFunctionWrapper(Eval); // 15.1.2.1 this["parseInt"] = new JsFunctionWrapper(ParseInt); // 15.1.2.2 this["parseFloat"] = new JsFunctionWrapper(ParseFloat); // 15.1.2.3 this["getType"] = new JsFunctionWrapper(GetType); // AVKugushev this["isDefault"] = new JsFunctionWrapper(IsDefault); // AVKugushev this["enumToString"] = new JsFunctionWrapper(EnumToString); // AVKugushev this["enumToInt"] = new JsFunctionWrapper(EnumToInt); // AVKugushev this["validate"] = new JsFunctionWrapper(Validate); // AVKugushev this["isNaN"] = new JsFunctionWrapper(IsNaN); this["isFinite"] = new JsFunctionWrapper(isFinite); this["decodeURI"] = new JsFunctionWrapper(DecodeURI); this["encodeURI"] = new JsFunctionWrapper(EncodeURI); this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent); this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent); // 1C functions // Functions for working with String type values this["StrLen"] = new JsFunctionWrapper(StrLen); this["TrimL"] = new JsFunctionWrapper(TrimL); this["TrimR"] = new JsFunctionWrapper(TrimR); this["TrimAll"] = new JsFunctionWrapper(TrimAll); this["Left"] = new JsFunctionWrapper(Left); this["Right"] = new JsFunctionWrapper(Right); this["Mid"] = new JsFunctionWrapper(Mid); this["Find"] = new JsFunctionWrapper(Find); this["Upper"] = new JsFunctionWrapper(Upper); this["Lower"] = new JsFunctionWrapper(Lower); this["Char"] = new JsFunctionWrapper(Char); this["CharCode"] = new JsFunctionWrapper(CharCode); this["IsBlankString"] = new JsFunctionWrapper(IsBlankString); this["StrReplace"] = new JsFunctionWrapper(StrReplace); this["StrLineCount"] = new JsFunctionWrapper(StrLineCount); this["StrGetLine"] = new JsFunctionWrapper(StrGetLine); this["StrOccurrenceCount"] = new JsFunctionWrapper(StrOccurrenceCount); this["Title"] = new JsFunctionWrapper(Title); // Functions for working with Number type values this["Int"] = new JsFunctionWrapper(Int); this["Round"] = new JsFunctionWrapper(Round); this["Log"] = new JsFunctionWrapper(Log); this["Log10"] = new JsFunctionWrapper(Log10); this["Sin"] = new JsFunctionWrapper(Sin); this["Cos"] = new JsFunctionWrapper(Cos); this["Tan"] = new JsFunctionWrapper(Tan); this["ASin"] = new JsFunctionWrapper(ASin); this["ACos"] = new JsFunctionWrapper(ACos); this["ATan"] = new JsFunctionWrapper(ATan); this["Exp"] = new JsFunctionWrapper(Exp); this["Pow"] = new JsFunctionWrapper(Pow); this["Sqrt"] = new JsFunctionWrapper(Sqrt); // Functions for working with Date type values this["Year"] = new JsFunctionWrapper(Year); this["Month"] = new JsFunctionWrapper(Month); this["Day"] = new JsFunctionWrapper(Day); this["Hour"] = new JsFunctionWrapper(Hour); this["Minute"] = new JsFunctionWrapper(Minute); this["Second"] = new JsFunctionWrapper(Second); this["BegOfYear"] = new JsFunctionWrapper(BegOfYear); this["BegOfQuarter"] = new JsFunctionWrapper(BegOfQuarter); this["BegOfMonth"] = new JsFunctionWrapper(BegOfMonth); this["BegOfWeek"] = new JsFunctionWrapper(BegOfWeek); this["BegOfDay"] = new JsFunctionWrapper(BegOfDay); this["BegOfHour"] = new JsFunctionWrapper(BegOfHour); this["BegOfMinute"] = new JsFunctionWrapper(BegOfMinute); this["EndOfYear"] = new JsFunctionWrapper(EndOfYear); this["EndOfQuarter"] = new JsFunctionWrapper(EndOfQuarter); this["EndOfMonth"] = new JsFunctionWrapper(EndOfMonth); this["EndOfWeek"] = new JsFunctionWrapper(EndOfWeek); this["EndOfDay"] = new JsFunctionWrapper(EndOfDay); this["EndOfHour"] = new JsFunctionWrapper(EndOfHour); this["EndOfMinute"] = new JsFunctionWrapper(EndOfMinute); this["WeekOfYear"] = new JsFunctionWrapper(WeekOfYear); this["DayOfYear"] = new JsFunctionWrapper(DayOfYear); this["WeekDay"] = new JsFunctionWrapper(WeekDay); this["AddMonth"] = new JsFunctionWrapper(AddMonth); this["CurrentDate"] = new JsFunctionWrapper(CurrentDate); // Value conversion functions this["Boolean"] = new JsFunctionWrapper(Boolean); this["Number"] = new JsFunctionWrapper(Number); this["String"] = new JsFunctionWrapper(String); this["Date"] = new JsFunctionWrapper(Date); // Formatting functions this["Format"] = new JsFunctionWrapper(Format); // Others this["Type"] = new JsFunctionWrapper(Type); this["TypeOf"] = new JsFunctionWrapper(TypeOf); this["Min"] = new JsFunctionWrapper(Min); this["Max"] = new JsFunctionWrapper(Max); this["ErrorDescription"] = new JsFunctionWrapper(ErrorDescription); this["Eval"] = new JsFunctionWrapper(Eval1C); this["ErrorInfo"] = new JsFunctionWrapper(ErrorInfo); this["ToString"] = new JsFunctionWrapper(String); #endregion }