public static IntPtr DoString(String expression, String inAction = "DoString") { if (CreateScope() == (IntPtr)0) { return((IntPtr)0); } try { // 文字列からソース生成 engine.Evaluate(expression); return((IntPtr)1); } catch (ScriptEngineException e) { OutputDebugStream("in " + inAction); OutputDebugStream(e.GetType().Name + ":"); OutputDebugStream(e.ErrorDetails); var stack = engine.GetStackTrace(); OutputDebugStream(stack.ToString()); ScriptEngineException next = e.InnerException as ScriptEngineException; while (next != null) { OutputDebugStream(next.ErrorDetails); next = next.InnerException as ScriptEngineException; } } catch (ScriptInterruptedException e) { OutputDebugStream("in " + inAction); OutputDebugStream(e.GetType().Name + ":"); OutputDebugStream(e.ErrorDetails); var stack = engine.GetStackTrace(); OutputDebugStream(stack.ToString()); ScriptInterruptedException next = e.InnerException as ScriptInterruptedException; while (next != null) { OutputDebugStream(next.ErrorDetails); next = next.InnerException as ScriptInterruptedException; } } catch (Exception e) { OutputDebugStream("in " + inAction); OutputDebugStream(e.GetType().Name + ":"); OutputDebugStream(e.Message); } return((IntPtr)0); }
public async Task <V8ScriptEngine> ExecuteAsync(IEnumerable <IncludeScript> scripts, Action <V8ScriptEngine> configAction, ExecutionOptions options = null) { var scriptList = PrecheckScripts(scripts); if (scriptList == null) { return(null); } if (options == null) { options = new ExecutionOptions(); } IEnumerable <V8Script> compiledScripts = scriptList.Select(x => _scriptCompiler.Compile(x, options.AddToCache, options.CacheExpirationSeconds)); GetEngine(); if (AddConsoleReference) { _scriptEngine.AddHostType("Console", typeof(Console)); } RequireManager.BuildRequirer(_scriptCompiler, _scriptEngine); if (configAction != null) { configAction(_scriptEngine); } if (options.Scripts != null) { foreach (var script in options.Scripts) { var compiledInclude = _scriptCompiler.Compile(script, options.AddToCache); if (compiledInclude != null) { _scriptEngine.Execute(compiledInclude); } } } foreach (var compiledScript in compiledScripts) { //Only create a wrapping task if the script has a timeout. CancellationToken cancellationToken; if (TryCreateCancellationToken(out cancellationToken)) { using (cancellationToken.Register(_scriptEngine.Interrupt)) { try { V8Script script = compiledScript; await Task.Run(() => _scriptEngine.Execute(script), cancellationToken).ConfigureAwait(false); } catch (ScriptInterruptedException ex) { var newEx = new ScriptInterruptedException( "Script interruption occurred, this often indicates a script timeout. Examine the data and inner exception for more information.", ex); newEx.Data.Add("Timeout", _settings.ScriptTimeoutMilliSeconds); newEx.Data.Add("ScriptId", compiledScript.Name); throw newEx; } } } else { _scriptEngine.Execute(compiledScript); } } return(_scriptEngine); }
public static IntPtr DoString(String expression, String inAction = "DoString") { if (CreateScope() == (IntPtr)0) { return((IntPtr)0); } try { // 文字列からソース生成 engine.Evaluate(expression); return((IntPtr)1); } catch (ScriptEngineException e) { OutputDebugStream("in " + inAction); var stack = e.GetScriptStack(); OutputDebugStream(stack.ToString()); /* * var errorLocation = engine.GetErrorLocation(error); * if (!string.IsNullOrWhiteSpace(errorLocation)) * { * message += "\n" + errorLocation; * } * * var stackTrace = WindowsScriptEngine. * if (!string.IsNullOrWhiteSpace(stackTrace)) * { * message += "\n" + stackTrace; * } * * return message; */ ScriptEngineException next = e.InnerException as ScriptEngineException; while (next != null) { /* * OutputDebugStream(next.Data.ToString()); * OutputDebugStream(next.Source.ToString()); */ OutputDebugStream(next.ErrorDetails); next = next.InnerException as ScriptEngineException; } } catch (ScriptInterruptedException e) { OutputDebugStream("in " + inAction); var stack = e.GetScriptStack(); OutputDebugStream(stack.ToString()); ScriptInterruptedException next = e.InnerException as ScriptInterruptedException; while (next != null) { OutputDebugStream(next.Data.ToString()); OutputDebugStream(next.Source.ToString()); OutputDebugStream(next.ErrorDetails); next = next.InnerException as ScriptInterruptedException; } } catch (Exception e) { OutputDebugStream("in " + inAction); OutputDebugStream(e.GetScriptStack()); } return((IntPtr)0); }