Microsoft.JScript.Vsa.VsaEngine.CreateEngineWithType C# (CSharp) Method

CreateEngineWithType() public static method

public static CreateEngineWithType ( RuntimeTypeHandle callingTypeHandle ) : VsaEngine
callingTypeHandle System.RuntimeTypeHandle
return VsaEngine
      public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle){
        Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
        Assembly callingAssembly = callingType.Assembly;
        Object o = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + callingAssembly.FullName);
        if (o != null){
          VsaEngine e = o as VsaEngine;
          if (e != null)
            return e;
        }

        VsaEngine engine = new VsaEngine(callingAssembly);
        engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());

        GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
        scope.globalObject = engine.Globals.globalObject;

        // for every global class generated in this assembly make an instance and call the global code method
        int i = 0;
        Type globalClassType = null;
        do{
          String globalClassName = "JScript " + i.ToString(CultureInfo.InvariantCulture);
          globalClassType = callingAssembly.GetType(globalClassName, false);
          if (globalClassType != null){
            engine.SetEnclosingContext(new WrappedNamespace("", engine));
            ConstructorInfo globalScopeConstructor = globalClassType.GetConstructor(new Type[]{typeof(GlobalScope)});
            MethodInfo globalCode = globalClassType.GetMethod("Global Code");
            try{
              Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
              globalCode.Invoke(globalClassInstance, new Object[0]);
            }catch(SecurityException){
              // [stesty] Due to bug 337909, if a JScript assembly is strongly-named but partially-trusted, it will
              //          not succeed here unless it also has the AllowPartiallyTrustedCallersAttribute.  We do not
              //          want to run this constructor with elevated permissions, so we work around by abandoning
              //          the attempt, thus disabling eval in this scenario.
              break;
            }
          }
          i++;
        }while (globalClassType != null);

        if (o == null)
          System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
        return engine;
      }