Esempio n. 1
0
        private static object NewWithInitializer(JsType type, JsObject json)
        {
            var obj = JsCompiler.NewByFunc(type.ctor);

            if (@typeof(json) == "array")
            {
                throw new Exception("not implemented");
            }
            else
            {
                foreach (var p in json)
                {
                    var setter = obj.As <JsObject>()["set_" + p];
                    if (@typeof(setter) == "function")
                    {
                        setter.As <JsFunction>().call(obj, json[p]);
                    }
                    else
                    {
                        obj.As <JsObject>()[p] = json[p];
                    }
                }
            }
            return(obj);
        }
Esempio n. 2
0
        private static object New(string typeName, JsArray args)
        {
            //TODO:
            var type = JsTypeHelper.GetType(typeName, true);

            if (args == null || args.length == 0)
            {
                var obj = JsCompiler.NewByFunc(type.ctor);
                return(obj);
            }
            else
            {
                var obj = JsCompiler.NewByFuncArgs(type.ctor, args);
                return(obj);
            }
        }
Esempio n. 3
0
        public static JsFunction GetDelegate(object obj, JsFunction func)
        {
            var target = obj.As <JsCompilerObject>();

            if (target == null)
            {
                return(func);
            }
            if (JsContext.@typeof(func) == "string")
            {
                func = target.As <JsObject>()[func.As <JsString>()].As <JsFunction>();
            }
            var cache = target.__delegateCache;

            if (cache == null)
            {
                cache = new JsObject <JsDelegateFunction>();
                target.__delegateCache = cache;
            }
            var key = JsCompiler.GetHashKey(func);
            var del = cache[key];

            if (del == null)
            {
                del = new JsNativeFunc <object>(delegate()
                {
                    var del2 = JsContext.arguments.callee.As <JsDelegateFunction>();
                    return(del2.func.apply(del.target, JsContext.arguments.As <object[]>()));
                }).As <JsDelegateFunction>();
                del.func       = func;
                del.target     = target;
                del.isDelegate = true;
                cache[key]     = del;
            }
            return(del);
        }
Esempio n. 4
0
 public static void Compile()
 {
     JsCompiler.Compile_Direct();
 }