本文整理汇总了C#中Rhino.Context.EvaluateString方法的典型用法代码示例。如果您正苦于以下问题:C# Context.EvaluateString方法的具体用法?C# Context.EvaluateString怎么用?C# Context.EvaluateString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Context
的用法示例。
在下文中一共展示了Context.EvaluateString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public object Run(Context cx)
{
cx.GetWrapFactory().SetJavaPrimitiveWrap(false);
NUnit.Framework.Assert.AreEqual("string[]", cx.EvaluateString(cx.InitStandardObjects(), "new org.mozilla.javascript.tests.Bug496585Test().method('one', 'two', 'three')", "<test>", 1, null));
NUnit.Framework.Assert.AreEqual("string+function", cx.EvaluateString(cx.InitStandardObjects(), "new org.mozilla.javascript.tests.Bug496585Test().method('one', function() {})", "<test>", 1, null));
return null;
}
示例2: Run
public object Run(Context cx)
{
Scriptable scope1 = cx.InitStandardObjects(new PrimitiveTypeScopeResolutionTest.MySimpleScriptableObject("scope1"));
Scriptable scope2 = cx.InitStandardObjects(new PrimitiveTypeScopeResolutionTest.MySimpleScriptableObject("scope2"));
cx.EvaluateString(scope2, scriptScope2, "source2", 1, null);
scope1.Put("scope2", scope1, scope2);
return cx.EvaluateString(scope1, scriptScope1, "source1", 1, null);
}
示例3: Run
public object Run(Context cx)
{
Scriptable scope = cx.InitStandardObjects();
object rep = cx.EvaluateString(scope, source, "test.js", 0, null);
NUnit.Framework.Assert.AreEqual(expected, rep);
return null;
}
示例4: Run
public object Run(Context _cx)
{
ScriptableObject scope = _cx.InitStandardObjects();
object result = _cx.EvaluateString(scope, script, "test script", 0, null);
NUnit.Framework.Assert.AreEqual("b1,b2,a0,a1,,a3", Context.ToString(result));
return null;
}
示例5: Run
public object Run(Context cx)
{
ScriptableObject top = cx.InitStandardObjects();
ScriptableObject.PutProperty(top, "foo", foo);
cx.EvaluateString(top, script, "script", 0, null);
return null;
}
示例6: Run
public object Run(Context cx)
{
Scriptable scope = cx.InitStandardObjects();
try
{
cx.EvaluateString(scope, _source, "test.js", 0, null);
}
catch (JavaScriptException e)
{
NUnit.Framework.Assert.AreEqual(_expectedStackTrace, e.GetScriptStackTrace());
return null;
}
throw new Exception("Exception expected!");
}
示例7: RunJsTest
public virtual void RunJsTest(Context cx, Scriptable shared, string name, string source)
{
// create a lightweight top-level scope
Scriptable scope = cx.NewObject(shared);
scope.SetPrototype(shared);
System.Console.Out.Write(name + ": ");
object result;
try
{
result = cx.EvaluateString(scope, source, "jstest input", 1, null);
}
catch (Exception e)
{
System.Console.Out.WriteLine("FAILED");
throw;
}
NUnit.Framework.Assert.IsTrue(result != null);
NUnit.Framework.Assert.IsTrue("success".Equals(result));
System.Console.Out.WriteLine("passed");
}
示例8: Run
public object Run(Context cx)
{
try
{
ScriptableObject scope = cx.InitStandardObjects();
object o = cx.EvaluateString(scope, script, "myScript.js", 1, null);
NUnit.Framework.Assert.AreEqual(expected, o);
return o;
}
catch (Exception e)
{
throw;
}
catch (Exception e)
{
throw new Exception(e);
}
}
示例9: Run
public object Run(Context context)
{
return context.EvaluateString(this._enclosing.global, scriptSourceText, "test source", 1, null);
}
示例10: Run
public object Run(Context _cx)
{
ScriptableObject scope = _cx.InitStandardObjects();
object result = _cx.EvaluateString(scope, script, "test script", 0, null);
return null;
}
示例11: Evaluate
private object Evaluate(Context cx, string str)
{
return cx.EvaluateString(scope, str, "<testsrc>", 0, null);
}
示例12: Run
// ContextAction
/// <summary>
/// Performs the action given by
/// <see cref="type">type</see>
/// .
/// </summary>
public virtual object Run(Context cx)
{
switch (type)
{
case IPROXY_COMPILE_SCRIPT:
{
cx.CompileString(text, url, 1, null);
break;
}
case IPROXY_EVAL_SCRIPT:
{
Scriptable scope = null;
if (dim.scopeProvider != null)
{
scope = dim.scopeProvider.GetScope();
}
if (scope == null)
{
scope = new ImporterTopLevel(cx);
}
cx.EvaluateString(scope, text, url, 1, null);
break;
}
case IPROXY_STRING_IS_COMPILABLE:
{
booleanResult = cx.StringIsCompilableUnit(text);
break;
}
case IPROXY_OBJECT_TO_STRING:
{
if (@object == Undefined.instance)
{
stringResult = "undefined";
}
else
{
if (@object == null)
{
stringResult = "null";
}
else
{
if (@object is NativeCall)
{
stringResult = "[object Call]";
}
else
{
stringResult = Context.ToString(@object);
}
}
}
break;
}
case IPROXY_OBJECT_PROPERTY:
{
objectResult = dim.GetObjectPropertyImpl(cx, @object, id);
break;
}
case IPROXY_OBJECT_IDS:
{
objectArrayResult = dim.GetObjectIdsImpl(cx, @object);
break;
}
default:
{
throw Kit.CodeBug();
}
}
return null;
}
示例13: Run
public object Run(Context context)
{
Scriptable scope = context.InitStandardObjects();
scope.Put("myObj", scope, f);
return context.EvaluateString(scope, "typeof myObj", "test script", 1, null);
}
示例14: Run
public object Run(Context cx)
{
Scriptable scope = cx.InitStandardObjects();
return cx.EvaluateString(scope, script, "myScript.js", 1, null);
}
示例15: 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;
}