internal protected override JSValue EvaluateForWrite(NiL.JS.Core.Context context) { if (value == JSValue.undefined) { return(value); } return(base.EvaluateForWrite(context)); }
public void Tick1() { if (_owner.disposed && !Disposed) { Disposed = true; foreach (var p in _pins.Where(z => z.Owner.parent != _owner)) { p.DeleteLink(this); } _pins.Clear(); if (_ctx != null) { JsExtLib.ClearTimeout(_ctx); } _ctx = null; _self = null; _calcFunc = null; return; } var ln = 0; foreach (var p in _pins.Where(z => z.Source != this && z.Layer > 0)) { if (ln < p.Layer) { ln = p.Layer; } } ln++; if (_layer != ln) { List <ILoItem> route = new List <ILoItem>(); foreach (var p in _pins.Where(z => z.Source != this && z.Layer > 0)) { if (p.Route != null) { route.AddRange(p.Route); } } route.Add(this); Route = route.ToArray(); _layer = ln; foreach (var p in _pins.Where(z => z.Source == this)) { _pl.EnqueueIn(p); } //Log.Debug(this.ToString()); } }
public static JSC.JSValue SetTimer(JSC.JSValue func, int to, int interval, JSC.Context ctx) { JSL.Function f; double idx = -1; if (((f = func as JSL.Function) != null || (f = func.Value as JSL.Function) != null) && to > 0) { idx = Interlocked.Increment(ref _timerCnt); Interlocked.CompareExchange(ref _timerCnt, 1, ((long)1 << 52) - 1); AddTimer(new TimerContainer { func = f, to = DateTime.Now.AddMilliseconds(to), interval = interval, ctx = ctx, idx = idx }); } return(new JSL.Number(idx)); }
public static JSC.JSValue SetTimer(JSC.JSValue func, DateTime time, JSC.Context ctx) { JSL.Function f; double idx = -1; if (((f = func as JSL.Function) != null || (f = func.Value as JSL.Function) != null)) { idx = Interlocked.Increment(ref _timerCnt); Interlocked.CompareExchange(ref _timerCnt, 1, ((long)1 << 52) - 1); var now = DateTime.Now; if ((time.TimeOfDay - now.TimeOfDay).TotalMilliseconds < 1) { now = now.AddDays(1); } AddTimer(new TimerContainer { func = f, to = now.Date.Add(time.TimeOfDay), interval = int.MinValue, ctx = ctx, idx = idx }); } return(new JSL.Number(idx)); }
public static void ClearTimeout(JSC.Context ctx) { TimerContainer t = _timer, tp = null; while (t != null) { if (t.ctx == ctx) { if (tp == null) { _timer = t.next; } else { tp.next = t.next; } } else { tp = t; } t = t.next; } }
public override JSValue Evaluate(NiL.JS.Core.Context context) { throw new InvalidOperationException(); }
public TwiDevice(Topic owner, TWI twi) { this.owner = owner; this._twi = twi; JSC.JSValue jSrc; var jType = owner.GetField("type"); Topic tt; if (jType.ValueType == JSC.JSValueType.String && jType.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(jType.Value as string, out tt) && (jSrc = JsLib.GetField(tt.GetState(), "src")).ValueType == JSC.JSValueType.String) { } else { jSrc = null; } if (jSrc != null) { try { _ctx = new JSC.Context(JsExtLib.Context); _ctx.DefineVariable("setTimeout").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetTimeout))); _ctx.DefineVariable("setInterval").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetInterval))); _ctx.DefineVariable("setAlarm").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, JSC.JSValue, JSC.JSValue>(SetAlarm))); var f = _ctx.Eval(jSrc.Value as string) as JSL.Function; if (f != null) { if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly) { this._self = JSC.JSObject.create(new JSC.Arguments { f.prototype }); } else { this._self = JSC.JSObject.CreateObject(); } _self["GetState"] = JSC.JSValue.Marshal(new Func <string, JSC.JSValue>(GetState)); _self["SetState"] = JSC.JSValue.Marshal(new Action <string, JSC.JSValue>(SetState)); _self["GetField"] = JSC.JSValue.Marshal(new Func <string, string, JSC.JSValue>(GetField)); _self["TwiReq"] = JSC.JSValue.Marshal(new Func <int[], Task <JSC.JSValue> >(_twi.TwiReq)); if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly) { _self = f.Construct(_self, new JSC.Arguments()); } else { f.Call(_self, new JSC.Arguments()); // Call constructor } } } catch (Exception ex) { Log.Warning("{0}.ctor() - {1}", owner.path, ex.Message); } } else { Log.Warning("{0} constructor is not defined", owner.path); } }
public void ManifestChanged() { JSC.JSValue jSrc; var jType = _owner.GetField("type"); Topic tt; if (jType.ValueType == JSC.JSValueType.String && jType.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(jType.Value as string, out tt) && _typeT != tt && (jSrc = JsLib.GetField(tt.GetState(), "src")).ValueType == JSC.JSValueType.String) { _typeT = tt; } else { jSrc = null; } if (jSrc != null) { try { _ctx = new JSC.Context(JsExtLib.Context); _ctx.DefineVariable("setTimeout").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetTimeout))); _ctx.DefineVariable("setInterval").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetInterval))); _ctx.DefineVariable("setAlarm").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, JSC.JSValue, JSC.JSValue>(SetAlarm))); var f = _ctx.Eval(jSrc.Value as string) as JSL.Function; if (f != null) { if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly) { this._self = JSC.JSObject.create(new JSC.Arguments { f.prototype }); } else { this._self = JSC.JSObject.CreateObject(); } var cf = _self.GetProperty("Calculate"); _calcFunc = (cf as JSL.Function) ?? (cf.Value as JSL.Function); _self["GetState"] = JSC.JSValue.Marshal(new Func <string, JSC.JSValue>(GetState)); _self["SetState"] = JSC.JSValue.Marshal(new Action <string, JSC.JSValue>(SetState)); _self["GetField"] = JSC.JSValue.Marshal(new Func <string, string, JSC.JSValue>(GetField)); if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly) { _self = f.Construct(_self, new JSC.Arguments()); } else { f.Call(_self, new JSC.Arguments()); // Call constructor } } } catch (Exception ex) { Log.Warning("{0}.ctor() - {1}", _owner.path, ex.Message); } } else { if (!_owner.disposed) { Log.Warning("{0} constructor is not defined", _owner.path); } } }