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 |
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); }
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; }
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; }
public object Run(Context cx) { ScriptableObject top = cx.InitStandardObjects(); ScriptableObject.PutProperty(top, "foo", foo); cx.EvaluateString(top, script, "script", 0, null); return null; }
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!"); }
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"); }
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); } }
public object Run(Context context) { return context.EvaluateString(this._enclosing.global, scriptSourceText, "test source", 1, null); }
public object Run(Context _cx) { ScriptableObject scope = _cx.InitStandardObjects(); object result = _cx.EvaluateString(scope, script, "test script", 0, null); return null; }
private object Evaluate(Context cx, string str) { return cx.EvaluateString(scope, str, "<testsrc>", 0, null); }
// 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; }
public object Run(Context context) { Scriptable scope = context.InitStandardObjects(); scope.Put("myObj", scope, f); return context.EvaluateString(scope, "typeof myObj", "test script", 1, null); }
public object Run(Context context) { Scriptable scope = context.InitStandardObjects(); return context.EvaluateString(scope, script, "test script", 1, null); }
public object Run(Context cx) { Scriptable scope = cx.InitStandardObjects(); return cx.EvaluateString(scope, script, "myScript.js", 1, null); }
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; }
private static object Evaluate(Context cx, ScriptableObject scope, string source) { return cx.EvaluateString(scope, source, "<eval>", 1, null); }