public static object evaluate(string s, string f, int l) { jsexec je = new jsexec(); object result = je.eval(s, f, l); return(result); }
public static void Main(string []args) { jsexec exec = new jsexec(); exec.GLOBAL.jobject.SetItem(exec.GLOBAL, "console", new JSSimpleProperty("console", new JSInstanceWrapper(exec.GLOBAL, new Console(System.Console.Out)))); exec.GLOBAL.jobject.SetItem(exec.GLOBAL, "Assembly", new JSSimpleProperty("Assembly", new JSClassWrapper(exec.GLOBAL, typeof(System.Reflection.Assembly)))); foreach (string arg in args) { using (TextReader tr = File.OpenText(arg)) { string jsfile = tr.ReadToEnd(); exec.eval(jsfile, arg, 1); } } }
public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { if (!a.HasProperty(GLOBAL, "length")) { return(JSUndefined.Undefined); } int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL)); if (alen < 1) { return(JSUndefined.Undefined); } object s = a.GetItem(GLOBAL, "0").GetValue(GLOBAL); if (!(s is string)) { return(s); } //string str = (string)s; ExecutionContext x2 = new ExecutionContext(CodeType.EVAL_CODE); x2.thisOb = x.thisOb; x2.caller = x.caller; x2.callee = x.callee; x2.scope = x.scope; GLOBAL.currentContext = x2; try { jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL); JSExec.execute(jsparse.parse(GLOBAL, s.ToString(), null, 0), x2); } catch (ThrownException) { x.result = x2.result; throw; } finally { GLOBAL.currentContext = x; } return(x2.result); }
public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { ExecutionContext x2 = new ExecutionContext(CodeType.FUNCTION_CODE); x2.thisOb = (JSObjectBase)(JSObject.ToBool(GLOBAL, t) ? t : GLOBAL.jobject); x2.caller = x; x2.callee = this; a.SetItem(GLOBAL, "callee", new JSSimpleProperty("callee", this, false, false, true)); Node f = this.node; x2.scope = new ExecutionContext(); x2.scope.parent = this.scope; x2.scope.jobject = new Activation(GLOBAL, f, a); GLOBAL.currentContext = x2; try { jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL); JSExec.execute(f.body == null ? f : f.body, x2); } catch (ReturnException) { return(x2.result); } catch (ThrownException) { x.result = x2.result; throw; } finally { GLOBAL.currentContext = x; } return(JSUndefined.Undefined); }
public static object evaluate(string s, string f, int l) { jsexec je = new jsexec(); object result = je.eval(s, f, l); return result; }