示例#1
0
        public static RT FuncCall <T1, RT>(ScriptDelegate fn, T1 a1)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var argv = stackalloc JSValue[1];

            argv[0] = ReflectBindValueOp.js_push_tvar <T1>(ctx, a1);
            if (argv[0].IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            var rval = fn.Invoke(ctx, 1, argv);

            if (rval.IsException())
            {
                JSApi.JS_FreeValue(ctx, argv[0]);
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            JSApi.JS_FreeValue(ctx, argv[0]);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }
示例#2
0
        public static RT FuncCall <RT>(ScriptDelegate fn)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var rval = fn.Invoke(ctx);

            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }