public TResult Func <T1, T2, T3, TResult>(T1 p1, T2 p2, T3 p3)
        {
#if THREAD_SAFE
            lock (jsEnv) {
#endif
            jsEnv.CheckLiveness();
            StaticTranslate <T1> .Set(jsEnv.Idx, isolate, NativeValueApi.SetValueToArgument, nativeJsFuncPtr, p1);

            StaticTranslate <T2> .Set(jsEnv.Idx, isolate, NativeValueApi.SetValueToArgument, nativeJsFuncPtr, p2);

            StaticTranslate <T3> .Set(jsEnv.Idx, isolate, NativeValueApi.SetValueToArgument, nativeJsFuncPtr, p3);

            IntPtr resultInfo = PuertsDLL.InvokeJSFunction(nativeJsFuncPtr, true);
            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetFunctionLastExceptionInfo(nativeJsFuncPtr);
                throw new Exception(exceptionInfo);
            }
            TResult result = StaticTranslate <TResult> .Get(jsEnv.Idx, isolate, NativeValueApi.GetValueFromResult, resultInfo, false);

            PuertsDLL.ResetResult(resultInfo);
            return(result);

#if THREAD_SAFE
        }
#endif
        }
Exemplo n.º 2
0
        /**
         * execute the module and get the result
         * when exportee is null, get the module namespace
         * when exportee is not null, get the specified member of the module namespace
         *
         * example: JsEnv.ExecuteModule("main.mjs")
         */
        public T ExecuteModule <T>(string filename, string exportee = "")
        {
            if (exportee == "" && typeof(T) != typeof(JSObject))
            {
                throw new Exception("T must be Puerts.JSObject when getting the module namespace");
            }
            if (loader.FileExists(filename))
            {
#if THREAD_SAFE
                lock (this) {
#endif
                IntPtr resultInfo = PuertsDLL.ExecuteModule(isolate, filename, exportee);
                if (resultInfo == IntPtr.Zero)
                {
                    string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
                    throw new Exception(exceptionInfo);
                }
                T result = StaticTranslate <T> .Get(Idx, isolate, NativeValueApi.GetValueFromResult, resultInfo, false);

                PuertsDLL.ResetResult(resultInfo);

                return(result);

#if THREAD_SAFE
            }
#endif
            }
            else
            {
                throw new InvalidProgramException("can not find " + filename);
            }
        }
Exemplo n.º 3
0
        public void Eval(string chunk, string chunkName = "chunk")
        {
            IntPtr resultInfo = PuertsDLL.Eval(isolate, chunk, chunkName);

            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
                throw new Exception(exceptionInfo);
            }
            PuertsDLL.ResetResult(resultInfo);
        }
Exemplo n.º 4
0
        public TResult Func <TResult>()
        {
            IntPtr resultInfo = PuertsDLL.InvokeJSFunction(nativeJsFuncPtr, true);

            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetFunctionLastExceptionInfo(nativeJsFuncPtr);
                throw new Exception(exceptionInfo);
            }
            TResult result = StaticTranslate <TResult> .Get(jsEnv.Idx, isolate, NativeValueApi.GetValueFromResult, resultInfo, false);

            PuertsDLL.ResetResult(resultInfo);
            return(result);
        }
Exemplo n.º 5
0
        public TResult Eval <TResult>(string chunk, string chunkName = "chunk")
        {
            IntPtr resultInfo = PuertsDLL.Eval(isolate, chunk, chunkName);

            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
                throw new Exception(exceptionInfo);
            }
            TResult result = StaticTranslate <TResult> .Get(Idx, isolate, NativeValueApi.GetValueFromResult, resultInfo, false);

            PuertsDLL.ResetResult(resultInfo);
            return(result);
        }
Exemplo n.º 6
0
        public void Eval(string chunk, string chunkName = "chunk")
        {
#if THREAD_SAFE
            lock (this) {
#endif
            IntPtr resultInfo = PuertsDLL.EvalChecked(isolate, chunk, chunkName);
            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
                throw new Exception(exceptionInfo);
            }
            PuertsDLL.ResetResult(resultInfo);
#if THREAD_SAFE
        }
#endif
        }
Exemplo n.º 7
0
        public void ExecuteModule(string filename)
        {
            if (loader.FileExists(filename))
            {
#if THREAD_SAFE
                lock (this) {
#endif
                IntPtr resultInfo = PuertsDLL.ExecuteModule(isolate, filename, null);
                if (resultInfo == IntPtr.Zero)
                {
                    string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
                    throw new Exception(exceptionInfo);
                }
                PuertsDLL.ResetResult(resultInfo);
#if THREAD_SAFE
            }
#endif
            }
            else
            {
                throw new InvalidProgramException("can not find " + filename);
            }
        }
Exemplo n.º 8
0
        public TResult Func <TResult>()
        {
#if THREAD_SAFE
            lock (jsEnv) {
#endif
            jsEnv.CheckLiveness();
            IntPtr resultInfo = InvokeJSFunction(
                jsEnv, nativeJsFuncPtr, 0, true,
                (IntPtr isolate, int envIdx, IntPtr nativeJsFuncPtr) => {}
                );
            if (resultInfo == IntPtr.Zero)
            {
                string exceptionInfo = PuertsDLL.GetFunctionLastExceptionInfo(nativeJsFuncPtr);
                throw new Exception(exceptionInfo);
            }
            TResult result = StaticTranslate <TResult> .Get(jsEnv.Idx, isolate, NativeValueApi.GetValueFromResult, resultInfo, false);

            PuertsDLL.ResetResult(resultInfo);
            return(result);

#if THREAD_SAFE
        }
#endif
        }
Exemplo n.º 9
0
 public void ExecuteModule(string filename)
 {
     if (loader.FileExists(filename))
     {
         IntPtr resultInfo = PuertsDLL.ExecuteModule(isolate, filename);
         if (resultInfo == IntPtr.Zero)
         {
             string exceptionInfo = PuertsDLL.GetLastExceptionInfo(isolate);
             throw new Exception(exceptionInfo);
         }
         PuertsDLL.ResetResult(resultInfo);
         // string debugPath;
         // var context = loader.ReadFile(filename, out debugPath);
         // if (context == null)
         // {
         //     throw new InvalidProgramException("can not find " + filename);
         // }
         // Eval(context, debugPath);
     }
     else
     {
         throw new InvalidProgramException("can not find " + filename);
     }
 }