本文整理汇总了C#中Rhino.Context.CompileString方法的典型用法代码示例。如果您正苦于以下问题:C# Context.CompileString方法的具体用法?C# Context.CompileString怎么用?C# Context.CompileString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Context
的用法示例。
在下文中一共展示了Context.CompileString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: EvalSpecial
/// <summary>The eval function property of the global object.</summary>
/// <remarks>
/// The eval function property of the global object.
/// See ECMA 15.1.2.1
/// </remarks>
public static object EvalSpecial(Context cx, Scriptable scope, object thisArg, object[] args, string filename, int lineNumber)
{
if (args.Length < 1)
{
return Undefined.instance;
}
object x = args[0];
if (!(x is CharSequence))
{
if (cx.HasFeature(Context.FEATURE_STRICT_MODE) || cx.HasFeature(Context.FEATURE_STRICT_EVAL))
{
throw Context.ReportRuntimeError0("msg.eval.nonstring.strict");
}
string message = ScriptRuntime.GetMessage0("msg.eval.nonstring");
Context.ReportWarning(message);
return x;
}
if (filename == null)
{
int[] linep = new int[1];
filename = Context.GetSourcePositionFromStack(linep);
if (filename != null)
{
lineNumber = linep[0];
}
else
{
filename = string.Empty;
}
}
string sourceName = ScriptRuntime.MakeUrlForGeneratedScript(true, filename, lineNumber);
ErrorReporter reporter;
reporter = DefaultErrorReporter.ForEval(cx.GetErrorReporter());
Evaluator evaluator = Context.CreateInterpreter();
if (evaluator == null)
{
throw new JavaScriptException("Interpreter not present", filename, lineNumber);
}
// Compile with explicit interpreter instance to force interpreter
// mode.
Script script = cx.CompileString(x.ToString(), evaluator, reporter, sourceName, 1, null);
evaluator.SetEvalScriptFlag(script);
Callable c = (Callable)script;
return c.Call(cx, scope, (Scriptable)thisArg, ScriptRuntime.emptyArgs);
}
示例3: Do_eval
/// <summary>Evaluates script in the given stack frame.</summary>
/// <remarks>Evaluates script in the given stack frame.</remarks>
private static string Do_eval(Context cx, Dim.StackFrame frame, string expr)
{
string resultString;
Rhino.Debug.Debugger saved_debugger = cx.GetDebugger();
object saved_data = cx.GetDebuggerContextData();
int saved_level = cx.GetOptimizationLevel();
cx.SetDebugger(null, null);
cx.SetOptimizationLevel(-1);
cx.SetGeneratingDebug(false);
try
{
Callable script = (Callable)cx.CompileString(expr, string.Empty, 0, null);
object result = script.Call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs);
if (result == Undefined.instance)
{
resultString = string.Empty;
}
else
{
resultString = ScriptRuntime.ToString(result);
}
}
catch (Exception exc)
{
resultString = exc.Message;
}
finally
{
cx.SetGeneratingDebug(true);
cx.SetOptimizationLevel(saved_level);
cx.SetDebugger(saved_debugger, saved_data);
}
if (resultString == null)
{
resultString = "null";
}
return resultString;
}
示例4: Run
public object Run(Context cx)
{
Script script = cx.CompileString(source, "my script", 0, null);
NUnit.Framework.Assert.AreEqual(source, cx.DecompileScript(script, 4).Trim());
return null;
}
示例5: Run
public object Run(Context context)
{
return context.CompileString("var f = 1", scriptName, 1, null);
}
示例6: Compile
private static Script Compile(Context cx, string source)
{
int[] linep = new int[] { 0 };
string filename = Context.GetSourcePositionFromStack(linep);
if (filename == null)
{
filename = "<Script object>";
linep[0] = 1;
}
ErrorReporter reporter;
reporter = DefaultErrorReporter.ForEval(cx.GetErrorReporter());
return cx.CompileString(source, null, reporter, filename, linep[0], null);
}
示例7: Run
public object Run(Context context)
{
Script script = context.CompileString(scriptSourceText, string.Empty, 1, null);
return script.Exec(context, this._enclosing.global);
}