Esempio n. 1
0
        internal protected override JSValue GetVariable(string name, bool create)
        {
            _thisBind = _parent._thisBind;
            var res = @object.GetProperty(name, create, PropertyScope.Common);

            if (res._valueType < JSValueType.Undefined)
            {
                res           = _parent.GetVariable(name, create);
                _objectSource = _parent._objectSource;
            }
            else
            {
                _objectSource = @object;
            }
            return(res);
        }
Esempio n. 2
0
        public static JSC.JSValue GetField(JSC.JSValue obj, string path)
        {
            if (obj == null)
            {
                return(JSC.JSValue.NotExists);
            }
            if (string.IsNullOrEmpty(path))
            {
                return(obj);
            }
            var ps = path.Split(SPLITTER_OBJ, StringSplitOptions.RemoveEmptyEntries);

            JSC.JSValue p = obj, c = null;
            for (int i = 0; i < ps.Length; i++)
            {
                if (p.ValueType != JSC.JSValueType.Object || p.Value == null)
                {
                    return(JSC.JSValue.NotExists);
                }
                c = p.GetProperty(ps[i]);
                p = c;
            }
            return(c);
        }
Esempio n. 3
0
        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);
                }
            }
        }