Beispiel #1
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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
     }
 }