예제 #1
0
        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);
        }
예제 #2
0
 public static void CreateNativePart(JsContext context, INativeScriptable proxyObj)
 {
     if (!proxyObj.HasNativeSide)
     {
         proxyObj.SetUnmanagedPtr(
             CreateWrapperForManagedObject(
                 context.Handle.Handle,
                 proxyObj.ManagedIndex,
                 proxyObj.UnmanagedTypeDefinitionPtr));
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
 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
     });
 }
예제 #5
0
        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);
        }
예제 #6
0
파일: Form1.cs 프로젝트: JohnMasen/Espresso
        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());
                }
        }
예제 #7
0
        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.
        }
예제 #8
0
        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();
        }
예제 #9
0
파일: Form1.cs 프로젝트: JohnMasen/Espresso
        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());
                }
        }
예제 #10
0
 public void ToJsValue(INativeScriptable jsInstance, ref JsValue output)
 {
     output.Type = JsValueType.JsTypeWrap;
     output.Ptr  = jsInstance.UnmanagedPtr;
     output.I32  = jsInstance.ManagedIndex;
 }
예제 #11
0
 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
     };
 }
예제 #12
0
 public static void CreateNativePart(JsContext context, INativeScriptable proxyObj)
 {
     if (!proxyObj.HasNativeSide)
     {
         proxyObj.SetUnmanagedPtr(
             CreateWrapperForManagedObject(
                 context.Handle.Handle,
                 proxyObj.ManagedIndex,
                 proxyObj.UnmanagedTypeDefinitionPtr));
     }
 }