EvaluateString() public method

Evaluate a JavaScript source string.
Evaluate a JavaScript source string. The provided source name and line number are used for error messages and for producing debug information.
public EvaluateString ( Scriptable scope, string source, string sourceName, int lineno, object securityDomain ) : object
scope Scriptable the scope to execute in
source string the JavaScript source
sourceName string a string describing the source, such as a filename
lineno int the starting line number
securityDomain object /// an arbitrary object that specifies security /// information about the origin or owner of the script. For /// implementations that don't care about security, this value /// may be null. ///
return object
Ejemplo n.º 1
0
			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;
			}
			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);
			}
Ejemplo n.º 3
0
			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;
			}
Ejemplo n.º 4
0
			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;
			}
Ejemplo n.º 5
0
			public object Run(Context cx)
			{
				ScriptableObject top = cx.InitStandardObjects();
				ScriptableObject.PutProperty(top, "foo", foo);
				cx.EvaluateString(top, script, "script", 0, null);
				return null;
			}
Ejemplo n.º 6
0
			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!");
			}
Ejemplo n.º 7
0
		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");
		}
Ejemplo n.º 8
0
			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);
				}
			}
Ejemplo n.º 9
0
			public object Run(Context context)
			{
				return context.EvaluateString(this._enclosing.global, scriptSourceText, "test source", 1, null);
			}
Ejemplo n.º 10
0
			public object Run(Context _cx)
			{
				ScriptableObject scope = _cx.InitStandardObjects();
				object result = _cx.EvaluateString(scope, script, "test script", 0, null);
				return null;
			}
Ejemplo n.º 11
0
		private object Evaluate(Context cx, string str)
		{
			return cx.EvaluateString(scope, str, "<testsrc>", 0, null);
		}
Ejemplo n.º 12
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;
			}
Ejemplo n.º 13
0
			public object Run(Context context)
			{
				Scriptable scope = context.InitStandardObjects();
				scope.Put("myObj", scope, f);
				return context.EvaluateString(scope, "typeof myObj", "test script", 1, null);
			}
Ejemplo n.º 14
0
			public object Run(Context context)
			{
				Scriptable scope = context.InitStandardObjects();
				return context.EvaluateString(scope, script, "test script", 1, null);
			}
Ejemplo n.º 15
0
			public object Run(Context cx)
			{
				Scriptable scope = cx.InitStandardObjects();
				return cx.EvaluateString(scope, script, "myScript.js", 1, null);
			}
Ejemplo n.º 16
0
		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;
		}
Ejemplo n.º 17
0
		private static object Evaluate(Context cx, ScriptableObject scope, string source)
		{
			return cx.EvaluateString(scope, source, "<eval>", 1, null);
		}