当前位置: 首页>>代码示例>>C#>>正文


C# Context.CompileString方法代码示例

本文整理汇总了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;
			}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:83,代码来源:Dim.cs

示例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);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:50,代码来源:ScriptRuntime.cs

示例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;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:40,代码来源:Dim.cs

示例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;
			}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:6,代码来源:DecompileTest.cs

示例5: Run

			public object Run(Context context)
			{
				return context.CompileString("var f = 1", scriptName, 1, null);
			}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:4,代码来源:GeneratedClassNameTest.cs

示例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);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:13,代码来源:NativeScript.cs

示例7: Run

			public object Run(Context context)
			{
				Script script = context.CompileString(scriptSourceText, string.Empty, 1, null);
				return script.Exec(context, this._enclosing.global);
			}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:5,代码来源:JavaAcessibilityTest.cs


注:本文中的Rhino.Context.CompileString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。