public JavaScriptInterpreter() { TheEvaluator = new Evaluator(); }
public JavaScriptInterpreter(JavaScriptInterpreter parent) { TheEvaluator = new Evaluator(parent.TheEvaluator); }
public Evaluator(Evaluator theEvaluator) { ICodeCompiler compiler; compiler = new JScriptCodeProvider().CreateCompiler(); CompilerParameters parameters; parameters = new CompilerParameters(); parameters.GenerateInMemory = true; CompilerResults results; results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource); Assembly assembly = results.CompiledAssembly; _evaluatorType = assembly.GetType("EvaluatorNS.Evaluator"); //_evaluatorCtxType = assembly.GetType("Evaluator.Context"); _evaluator = Activator.CreateInstance(_evaluatorType); // create a new form instance // _scriptableForm = new ScriptableForm(); // create a new set of hosts lock (hosts) { string rootMoniker = string.Format("{0}://{1}", rootHostName, Guid.NewGuid().ToString()); _host = new VsaScriptingHost(VsaScriptingLanguages.JScript, "Evaluator", rootMoniker, _evaluatorType.Namespace, true); Engine = (VsaEngine)(object)_host.Engine; globalScope = Engine.GetGlobalScope(); thisGlobalObj = Microsoft.JScript.Eval.JScriptEvaluate("this;", Engine) as GlobalScope; hosts.Add(_host); _host.AddType(typeof(System.Object)); _host.AddType(typeof(System.String)); AddGlobalItem("$engine", Engine); AddGlobalItem("$superE", theEvaluator); // hosts.AddRange(HostFactory.Create(@"MyScriptingHost", @"Scripting", true, Environment.CurrentDirectory)); } // wire up to the events of each host foreach (VsaScriptingHost host in hosts) { host.AssemblyReferencesNeeded += new ScriptingHostEventHandler(OnAssemblyReferencesNeeded); host.CompilerException += new ScriptingHostCompilerExceptionEventHandler(OnCompilerException); host.GlobalItemsNeeded += new ScriptingHostEventHandler(OnGlobalItemsNeeded); } // execute the hosts foreach (VsaScriptingHost host in hosts) host.Execute(); // show the form //_scriptableForm.ShowDialog(); }