public FunctionInstance(EcmaState state, int length) { this.Put("length", EcmaValue.Number(length)); this.Prototype = state.Function; this.Put("prototype", EcmaValue.Object(new ObjectInstance(state, new EcmaValue[0]))); this.Property["prototype"].DontEnum = true; }
public ScriptWhoIsData(EcmaState state, WhoIsData data) { this.Put("isAway", EcmaValue.Boolean(data.Away)); this.Put("awayMessage", EcmaValue.String(data.AwayMessage)); this.Put("channels", data.Channels == null ? EcmaValue.Object(new ArrayIntstance(state, new EcmaValue[0])) : EcmaValue.Object(EcmaUntil.ToArray(state, new List <object>(data.Channels)))); this.Put("nick", EcmaValue.String(data.Nick)); }
public ArrayIntstance(EcmaState state, EcmaValue[] values) { this.state = state; this.Prototype = state.Array; this.Class = "Array"; if (values.Length == 1 && values[0].IsNumber()) { EcmaProperty p = new EcmaProperty(); p.Value = EcmaValue.Number(values[0].ToNumber(state)); p.DontEnum = true; p.DontDelete = true; this.Property.Add("length", p); } else { EcmaProperty p = new EcmaProperty(); p.Value = EcmaValue.Number(values.Length); p.DontEnum = true; p.DontDelete = true; this.Property.Add("length", p); for (int i = 0; i < values.Length; i++) { this.Put(i.ToString(), values[i]); } } }
public IrcScriptWhoIs(EcmaState state, WhoIsData data) { this.data = data; this.Put("nick", EcmaValue.String(data.Nick)); this.Put("channels", EcmaValue.Object(EcmaUntil.ToArray(state, new List <object>(data.Channels)))); this.Put("isAway", EcmaValue.Boolean(data.Away)); this.Put("awayMessage", EcmaValue.String(data.AwayMessage)); }
private static EcmaValue ConvertToString(EcmaState state, EcmaHeadObject obj) { DateTime time = new DateTime() + TimeSpan.FromMilliseconds(obj.Value.ToInteger(state)); StringBuilder builder = new StringBuilder(); builder.Append(time.Year + "/" + time.Month + "/" + time.Day + " " + time.Hour + ":" + time.Minute + ":" + time.Second + ":" + time.Millisecond); return(EcmaValue.String(builder.ToString())); }
public ArrayConstructor(EcmaState state) { this.State = state; state.Array = new ArrayPrototype(this, state); this.Put("prototype", EcmaValue.Object(state.Array)); this.Put("length", EcmaValue.Number(1)); this.Property["prototype"].DontDelete = true; this.Property["prototype"].ReadOnly = true; this.Property["prototype"].DontEnum = true; }
public ArrayPrototype(ArrayConstructor constructor, EcmaState state) { this.state = state; this.Prototype = state.Object; this.Put("constructor", EcmaValue.Object(constructor)); this.Put("toString", EcmaValue.Object(new NativeFunctionInstance(0, state, EcmaToString))); this.Put("join", EcmaValue.Object(new NativeFunctionInstance(0, state, Join))); this.Put("reverse", EcmaValue.Object(new NativeFunctionInstance(0, state, Reverse))); this.Put("sort", EcmaValue.Object(new NativeFunctionInstance(1, state, Sort))); }
public FunctionConstructor(EcmaState state) { FunctionPrototype prototype = new FunctionPrototype(); this.Put("prototype", EcmaValue.Object(prototype)); this.Property["prototype"].DontDelete = true; this.Property["prototype"].DontEnum = true; this.Property["prototype"].ReadOnly = true; this.State = state; }
public GlobalObject(EcmaState state) { this.State = state; this.Put("Array", EcmaValue.Object(new ArrayConstructor(state))); this.Put("Object", EcmaValue.Object(new ObjectConstructor(state))); this.Put("String", EcmaValue.Object(new StringConstructor(state))); this.Put("Function", EcmaValue.Object(new FunctionConstructor(state))); this.Put("Date", EcmaValue.Object(new DateConstructor(state))); this.Put("parseFloat", EcmaValue.Object(new NativeFunctionInstance(1, state, ParseFloat))); this.Put("parseInt", EcmaValue.Object(new NativeFunctionInstance(1, state, ParseInt))); }
private EcmaValue OpenConnection(EcmaHeadObject self, EcmaValue[] arg) { EcmaState state = this.Client.State; OpenConnection( arg[0].ToString(state), arg[1].ToString(state), arg[2].ToInt32(state), arg[3].ToString(state), EcmaUntil.ToStringArray(state, arg[4].ToObject(state)) ); return(EcmaValue.Undefined()); }
public ObjectConstructor(EcmaState state) { this.State = state; ObjectPrototype proto = new ObjectPrototype(this); Put("length", EcmaValue.Number(0)); Put("prototype", EcmaValue.Object(proto)); Property["prototype"].DontDelete = true; Property["prototype"].DontEnum = true; Property["prototype"].ReadOnly = true; State.Object = proto; }
public StringPrototype(StringConstructor constructor) { this.constructor = constructor; this.State = constructor.State; this.Class = "String"; this.Prototype = constructor.State.Object; Put("constructor", EcmaValue.Object(constructor)); Put("toString", EcmaValue.Object(new NativeFunctionInstance(0, State, EcmaToString))); Put("valueOf", EcmaValue.Object(new NativeFunctionInstance(0, State, ValueOf))); Put("charAt", EcmaValue.Object(new NativeFunctionInstance(1, State, CharAt))); Put("charCodeAt", EcmaValue.Object(new NativeFunctionInstance(1, State, CharCodeAt))); Put("indexOf", EcmaValue.Object(new NativeFunctionInstance(1, State, IndexOf))); }
public StringConstructor(EcmaState state) { this.State = state; state.String = this; this.Prototype = state.Function; this.prototype = new StringPrototype(this); Put("length", EcmaValue.Number(0)); Put("prototype", EcmaValue.Object(this.prototype)); Put("fromCharCode", EcmaValue.Object(new NativeFunctionInstance(0, State, FromCharCode))); Property["prototype"].DontDelete = true; Property["prototype"].DontEnum = true; Property["prototype"].ReadOnly = true; }
private void MakeCache() { EcmaState state = this.Constructor.State; List <string> args = new List <string>(); string[] p = this.P.Split(','); for (int i = 0; i < p.Length; i++) { args.Add(p[i].Trim()); } EcmaTokenizer tokenizer = new EcmaTokenizer(new StringReader(this.Body)); List <EcmaStatment> block = new List <EcmaStatment>(); while (tokenizer.Current().IsNot(TokenType.EOS)) { block.Add(state.GetProgroam(tokenizer)); } EcmaStatment statment = new EcmaStatment(EcmaStatmentType.Block); statment.Statments = block; this.Cached = new FunctionInstance(state, args.ToArray(), statment); }
public NewServer(EcmaHeadObject main, EcmaState state) { this.main = main; this.state = state; InitializeComponent(); }
public MysqlReaderValue(EcmaState state, DataTable reader) { this.Current = 0; this.reader = reader.AsEnumerable().ToArray(); this.Put("fetch", EcmaValue.Object(new NativeFunctionInstance(0, state, Fetch))); }
public MysqlValue(EcmaState state, MySqlConnection connection) { this.state = state; this.connection = connection; this.Put("query", EcmaValue.Object(new NativeFunctionInstance(0, state, Query))); }
public DefaultScript(EcmaScript e) { state = e.State; e.CreateVariable("include", EcmaValue.Object(new NativeFunctionInstance(1, state, Include))); }
public FunctionInstance(EcmaState state, string[] Args, EcmaStatment body) : this(state, Args.Length) { this.State = state; this.body = body; this.arg = Args; }
public ObjectInstance(EcmaState state, EcmaValue[] args) { this.Prototype = state.Object; this.Class = "Object"; }
public DateConstructor(EcmaState state) { this.State = state; this.Put("length", EcmaValue.Number(7)); this.Prototype = state.Function; this.DatePrototype = new DatePrototype(state, this); this.Put("prototype", EcmaValue.Object(this.DatePrototype)); this.Property["prototype"].DontDelete = true; this.Property["prototype"].DontEnum = true; this.Property["prototype"].ReadOnly = true; this.Put("parse", EcmaValue.Object(new NativeFunctionInstance( 1, this.State, (self, arg) => { return(EcmaValue.Object(new DateInstance(this, DatePrototype.Parse(arg[0].ToString(State))))); } ))); this.Put("UTC", EcmaValue.Object(new NativeFunctionInstance( 7, this.State, (self, arg) => { if (arg[0].IsUndefined()) { return(EcmaValue.Number( TimeSpan.FromTicks(DateTime.UtcNow.Ticks).TotalMilliseconds )); } double year = arg[0].ToInteger(State); double month = arg[1].IsUndefined() ? 1 : arg[1].ToInteger(State); double date = arg[2].IsUndefined() ? 1 : arg[2].ToInteger(State); double hours = arg[3].IsUndefined() ? 0 : arg[3].ToInteger(State); double minutes = arg[4].IsUndefined() ? 0 : arg[4].ToInteger(State); double seconds = arg[5].IsUndefined() ? 0 : arg[5].ToInteger(State); double ms = arg[6].IsUndefined() ? 0 : arg[6].ToInteger(State); if (!Double.IsNaN(year) && 0 <= year && year <= 99) { year += 1900; } return(EcmaValue.Number( DateFunc.MakeDate( DateFunc.MakeDay( year, month, date ), DateFunc.MakeTime( hours, minutes, seconds, ms ) ) )); } ))); }
public NativeFunctionInstance(int length, EcmaState state, _C method) : base(state, length) { this._Call = method; }
public EcmaValue DefaultValue(EcmaState state) { return(DefaultValue(state, "Number")); }
public EcmaValue DefaultValue(EcmaState state, string hint) { EcmaValue result; EcmaHeadObject obj; if (hint == "String") { result = this.Get("toString"); if (result.IsObject()) { obj = result.ToObject(state); if (obj is ICallable) { result = (obj as ICallable).Call(this, new EcmaValue[0]); if (result.IsPrimitiv()) { return(result); } } } result = this.Get("valueOf"); if (result.IsObject()) { obj = result.ToObject(state); if (obj is ICallable) { result = (obj as ICallable).Call(this, new EcmaValue[0]); if (result.IsPrimitiv()) { return(result); } } } throw new EcmaRuntimeException("Cant get defualt value 'String' out of " + this.Class + " this class: " + this.GetType().FullName); } result = this.Get("valueOf"); if (result.IsObject()) { obj = result.ToObject(state); if (obj is ICallable) { result = (obj as ICallable).Call(this, new EcmaValue[0]); if (result.IsPrimitiv()) { return(result); } } } result = this.Get("toString"); if (result.IsObject()) { obj = result.ToObject(state); if (obj is ICallable) { result = (obj as ICallable).Call(this, new EcmaValue[0]); if (result.IsPrimitiv()) { return(result); } } } throw new EcmaRuntimeException("Cant convert " + this.Class + " to Number"); }
public DatePrototype(EcmaState state, DateConstructor constructor) { this.Class = "Date"; this.Value = EcmaValue.Number(Double.NaN); this.Prototype = state.Object; this.Put("constructor", EcmaValue.Object(constructor)); this.Put("toString", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { AssetDate(self); return(ConvertToString(state, self)); }))); this.Put("valueOf", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { AssetDate(self); return(ConvertToString(state, self)); }))); this.Put("getTime", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { AssetDate(self); return(self.Value); }))); this.Put("getYear", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double year = self.Value.ToInteger(state); if (Double.IsNaN(year)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.YearFromTime(DateFunc.LocalTime(year)) - 1900)); }))); this.Put("getFullYear", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double year = self.Value.ToInteger(state); if (Double.IsNaN(year)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.YearFromTime(DateFunc.LocalTime(year)))); }))); this.Put("getUTCFullYear", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double year = self.Value.ToInteger(state); if (Double.IsNaN(year)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.YearFromTime(year))); }))); this.Put("getMonth", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double month = self.Value.ToInteger(state); if (Double.IsNaN(month)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.MonthFromTime(DateFunc.LocalTime(month)))); }))); this.Put("getUTCMonth", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double month = self.Value.ToInteger(state); if (Double.IsNaN(month)) { return(EcmaValue.Number(double.NaN)); } return(EcmaValue.Number(DateFunc.MonthFromTime(month))); }))); this.Put("getDate", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.DateFromTime(DateFunc.LocalTime(t)))); }))); this.Put("getUTCDate", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.DateFromTime(t))); }))); this.Put("getDay", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.WeekDay(DateFunc.LocalTime(t)))); }))); this.Put("getUTCDay", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.WeekDay(t))); }))); this.Put("getHours", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.HourFromTime(DateFunc.LocalTime(t)))); }))); this.Put("getUTCHours", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.HourFromTime(t))); }))); this.Put("getMinutes", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.MinFromTime(DateFunc.LocalTime(t)))); }))); this.Put("getUTCMinutes", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.MinFromTime(t))); }))); this.Put("getSeconds", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.SecFromTime(DateFunc.LocalTime(t)))); }))); this.Put("getUTCSeconds", EcmaValue.Object(new NativeFunctionInstance(0, state, (self, arg) => { double t = self.Value.ToInteger(state); if (Double.IsNaN(t)) { return(EcmaValue.Number(Double.NaN)); } return(EcmaValue.Number(DateFunc.SecFromTime(t))); }))); }