本文整理汇总了C#中Rhino.Context.SetErrorReporter方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetErrorReporter方法的具体用法?C# Context.SetErrorReporter怎么用?C# Context.SetErrorReporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Context
的用法示例。
在下文中一共展示了Context.SetErrorReporter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnContextCreated
protected internal override void OnContextCreated(Context cx)
{
cx.SetLanguageVersion(languageVersion);
cx.SetOptimizationLevel(optimizationLevel);
if (errorReporter != null)
{
cx.SetErrorReporter(errorReporter);
}
cx.SetGeneratingDebug(generatingDebug);
base.OnContextCreated(cx);
}
示例2: Run
public object Run(Context cx)
{
status.Running(jsFile);
testState.errors = new ShellTest.ErrorReporterWrapper(cx.GetErrorReporter());
cx.SetErrorReporter(testState.errors);
global.Init(cx);
try
{
ShellTest.RunFileIfExists(cx, global, new FilePath(jsFile.GetParentFile().GetParentFile().GetParentFile(), "shell.js"));
ShellTest.RunFileIfExists(cx, global, new FilePath(jsFile.GetParentFile().GetParentFile(), "shell.js"));
ShellTest.RunFileIfExists(cx, global, new FilePath(jsFile.GetParentFile(), "shell.js"));
ShellTest.RunFileIfExists(cx, global, jsFile);
status.HadErrors(jsFile, Sharpen.Collections.ToArray(testState.errors.errors, new ShellTest.Status.JsError[0]));
}
catch (ThreadDeath)
{
}
catch (Exception t)
{
status.Threw(t);
}
return null;
}
示例3: RunDoctest
public virtual int RunDoctest(Context cx, Scriptable scope, string session, string sourceName, int lineNumber)
{
doctestCanonicalizations = new Dictionary<string, string>();
string[] lines = session.Split("[\n\r]+");
string prompt0 = this.prompts[0].Trim();
string prompt1 = this.prompts[1].Trim();
int testCount = 0;
int i = 0;
while (i < lines.Length && !lines[i].Trim().StartsWith(prompt0))
{
i++;
}
// skip lines that don't look like shell sessions
while (i < lines.Length)
{
string inputString = Sharpen.Runtime.Substring(lines[i].Trim(), prompt0.Length);
inputString += "\n";
i++;
while (i < lines.Length && lines[i].Trim().StartsWith(prompt1))
{
inputString += Sharpen.Runtime.Substring(lines[i].Trim(), prompt1.Length);
inputString += "\n";
i++;
}
string expectedString = string.Empty;
while (i < lines.Length && !lines[i].Trim().StartsWith(prompt0))
{
expectedString += lines[i] + "\n";
i++;
}
TextWriter savedOut = this.GetOut();
TextWriter savedErr = this.GetErr();
MemoryStream @out = new MemoryStream();
MemoryStream err = new MemoryStream();
this.SetOut(new TextWriter(@out));
this.SetErr(new TextWriter(err));
string resultString = string.Empty;
ErrorReporter savedErrorReporter = cx.GetErrorReporter();
cx.SetErrorReporter(new ToolErrorReporter(false, this.GetErr()));
try
{
testCount++;
object result = cx.EvaluateString(scope, inputString, "doctest input", 1, null);
if (result != Context.GetUndefinedValue() && !(result is Function && inputString.Trim().StartsWith("function")))
{
resultString = Context.ToString(result);
}
}
catch (RhinoException e)
{
ToolErrorReporter.ReportException(cx.GetErrorReporter(), e);
}
finally
{
this.SetOut(savedOut);
this.SetErr(savedErr);
cx.SetErrorReporter(savedErrorReporter);
resultString += err.ToString() + @out.ToString();
}
if (!DoctestOutputMatches(expectedString, resultString))
{
string message = "doctest failure running:\n" + inputString + "expected: " + expectedString + "actual: " + resultString + "\n";
if (sourceName != null)
{
throw Context.ReportRuntimeError(message, sourceName, lineNumber + i - 1, null, 0);
}
else
{
throw Context.ReportRuntimeError(message);
}
}
}
return testCount;
}