CompileString() private method

private CompileString ( string source, Evaluator compiler, ErrorReporter compilationErrorReporter, string sourceName, int lineno, object securityDomain ) : System.Script
source string
compiler Evaluator
compilationErrorReporter ErrorReporter
sourceName string
lineno int
securityDomain object
return System.Script
Example #1
0
			// 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;
			}
Example #2
0
		/// <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);
		}
Example #3
0
		/// <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;
		}
Example #4
0
			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;
			}
			public object Run(Context context)
			{
				return context.CompileString("var f = 1", scriptName, 1, null);
			}
Example #6
0
		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);
		}
Example #7
0
			public object Run(Context context)
			{
				Script script = context.CompileString(scriptSourceText, string.Empty, 1, null);
				return script.Exec(context, this._enclosing.global);
			}