public static GlobalScope CreateEngineAndGetGlobalScopeWithTypeAndRootNamespace(bool fast, String[] assemblyNames, RuntimeTypeHandle callingTypeHandle, string rootNamespace){
VsaEngine engine = new VsaEngine(fast);
engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
engine.doPrint = true;
engine.SetEnclosingContext(new WrappedNamespace("", engine));
if (rootNamespace != null)
engine.SetEnclosingContext(new WrappedNamespace(rootNamespace, engine));
foreach (String assemblyName in assemblyNames){
VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
r.AssemblyName = assemblyName;
}
// Put the engine in the CallContext so that calls to CreateEngineWithType will return this engine
Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
Assembly callingAssembly = callingType.Assembly;
System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
// Get and return the global scope
GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
scope.globalObject = engine.Globals.globalObject;
return scope;
}