public void SetVariableAutoWrap <T>(string name, T result) where T : class { Type actualType = result.GetType(); JsTypeDefinition jsTypeDef = this.GetJsTypeDefinition(actualType); INativeScriptable proxy = this.CreateWrapper(result, jsTypeDef); this.SetVariable(name, proxy); }
public static void CreateNativePart(JsContext context, INativeScriptable proxyObj) { if (!proxyObj.HasNativeSide) { proxyObj.SetUnmanagedPtr( CreateWrapperForManagedObject( context.Handle.Handle, proxyObj.ManagedIndex, proxyObj.UnmanagedTypeDefinitionPtr)); } }
public void SetResultAutoWrap <T>(T result) where T : class, new() { Type actualType = result.GetType(); JsTypeDefinition jsTypeDef = this.context.GetJsTypeDefinition(actualType); INativeScriptable proxy = this.context.CreateWrapper(result, jsTypeDef); JsValue output = new JsValue(); this.context.Converter.ToJsValue(proxy, ref output); NativeV8JsInterOp.ResultSetValue(metArgsPtr, ref output); }
public JsValue ToJsValue(INativeScriptable jsInstance) { //extension //int keepAliveId = _context.KeepAliveAdd(jsInstance); return(new JsValue { Type = JsValueType.JsTypeWrap, Ptr = jsInstance.UnmanagedPtr, Index = jsInstance.ManagedIndex //Index = keepAliveId jsInstance.ManagedIndex }); }
public void SetResultObj(object result, JsTypeDefinition jsTypeDef) { if (!jsTypeDef.IsRegisterd) { this.context.RegisterTypeDefinition(jsTypeDef); } INativeScriptable proxy = this.context.CreateWrapper(result, jsTypeDef); JsValue output = new JsValue(); this.context.Converter.ToJsValue(proxy, ref output); NativeV8JsInterOp.ResultSetValue(metArgsPtr, ref output); }
private void button1_Click(object sender, EventArgs e) { #if DEBUG JsBridge.dbugTestCallbacks(); #endif JsTypeDefinition jstypedef = new JsTypeDefinition("AA"); jstypedef.AddMember(new JsMethodDefinition("B", args => { args.SetResult(100); })); jstypedef.AddMember(new JsMethodDefinition("C", args => { args.SetResult(true); })); //=============================================================== //create js engine and context using (JsEngine engine = new JsEngine()) using (JsContext ctx = engine.CreateContext()) { if (!jstypedef.IsRegisterd) { ctx.RegisterTypeDefinition(jstypedef); } GC.Collect(); System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch(); stwatch.Start(); TestMe1 t1 = new TestMe1(); //wrap t1 with custom js type definition INativeScriptable proxy = ctx.CreateWrapper(t1, jstypedef); ctx.SetVariableFromAny("x", proxy); for (int i = 2000; i >= 0; --i) { object result = ctx.Execute("(function(){if(x.C()){return x.B();}else{return 0;}})()"); } stwatch.Stop(); Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString()); } }
public void SetVariable(string name, INativeScriptable proxy) { if (name == null) { throw new ArgumentNullException("name"); } CheckDisposed(); JsValue a = _convert.ToJsValue(proxy); JsValue b = jscontext_set_variable(_context, name, a); #if DEBUG_TRACE_API Console.WriteLine("Cleaning up return value from set variable"); #endif jsvalue_dispose(a); jsvalue_dispose(b); // TODO: Check the result of the operation for errors. }
public void SetVariable(string name, INativeScriptable proxy) { if (name == null) { throw new ArgumentNullException("name"); } CheckDisposed(); JsValue a = new JsValue(); JsValue b = new JsValue(); _convert.ToJsValue(proxy, ref a); jscontext_set_variable(_context, name, ref a, ref b); #if DEBUG_TRACE_API Console.WriteLine("Cleaning up return value from set variable"); #endif a.Dispose(); b.Dispose(); }
private void button5_Click(object sender, EventArgs e) { #if DEBUG JsBridge.dbugTestCallbacks(); #endif JsTypeDefinition jstypedef = new JsTypeDefinition("AA"); jstypedef.AddMember(new JsMethodDefinition("B", args => { int argCount = args.ArgCount; var thisArg = args.GetThisArg(); var arg0 = args.GetArgAsObject(0); args.SetResult((bool)arg0); })); jstypedef.AddMember(new JsMethodDefinition("C", args => { args.SetResult(true); })); //----------------------------------------------------- jstypedef.AddMember(new JsPropertyDefinition("D", args => { var ab = new AboutMe(); args.SetResultAutoWrap(ab); }, args => { //setter })); jstypedef.AddMember(new JsPropertyDefinition("E", args => { //getter args.SetResult(250); }, args => { //setter })); //=============================================================== //create js engine and context using (JsEngine engine = new JsEngine()) using (JsContext ctx = engine.CreateContext()) { ctx.RegisterTypeDefinition(jstypedef); GC.Collect(); System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch(); stwatch.Reset(); stwatch.Start(); TestMe1 t1 = new TestMe1(); INativeScriptable proxy = ctx.CreateWrapper(t1, jstypedef); ctx.SetVariable("x", proxy); //string testsrc = "x.B(x.D.IsOK);"; string testsrc = "x.B(x.D.GetOK());"; object result = ctx.Execute(testsrc); stwatch.Stop(); Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString()); } }
public void ToJsValue(INativeScriptable jsInstance, ref JsValue output) { output.Type = JsValueType.JsTypeWrap; output.Ptr = jsInstance.UnmanagedPtr; output.I32 = jsInstance.ManagedIndex; }
public JsValue ToJsValue(INativeScriptable jsInstance) { //extension //int keepAliveId = _context.KeepAliveAdd(jsInstance); return new JsValue { Type = JsValueType.JsTypeWrap, Ptr = jsInstance.UnmanagedPtr, Index = jsInstance.ManagedIndex //Index = keepAliveId jsInstance.ManagedIndex }; }