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); }
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); } }
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); }
public static void Compile() { JsCompiler.Compile_Direct(); }
/// <summary> /// Starts the js runtime, binding all currently included js modules / assemblies (.js files), /// this function can be called from javascript using this code: /// <code>JsRuntime.Start();</code> /// </summary> public static void Start() { JsCompiler.Compile(); }