SetEnclosingContext() private method

private SetEnclosingContext ( ScriptObject ob ) : void
ob Microsoft.JScript.ScriptObject
return void
Ejemplo n.º 1
0
 public static void JScriptImport(String name, VsaEngine engine){
   int dotPos = name.IndexOf('.');
   String rootName = dotPos > 0 ? name.Substring(0, dotPos) : name;
   GlobalScope scope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();
   FieldInfo field = scope.GetLocalField(rootName);
   if (field == null)
     field = scope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Public|FieldAttributes.Literal);
   engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
 }
 public static void JScriptImport(string name, VsaEngine engine)
 {
     int index = name.IndexOf('.');
     string str = (index > 0) ? name.Substring(0, index) : name;
     GlobalScope globalScope = ((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope();
     if (globalScope.GetLocalField(str) == null)
     {
         FieldInfo info = globalScope.AddNewField(str, Namespace.GetNamespace(str, engine), FieldAttributes.Literal | FieldAttributes.Public);
     }
     engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
 }
Ejemplo n.º 3
0
      // This factory method is called by DLL code only
      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();
          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");
            Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
            globalCode.Invoke(globalClassInstance, new Object[0]);
          }
          i++;
        }while (globalClassType != null);

        if (o == null)
          System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
        return engine;
      }
Ejemplo n.º 4
0
 public static GlobalScope CreateEngineAndGetGlobalScopeWithType(bool fast, String[] assemblyNames, RuntimeTypeHandle callingTypeHandle){
   VsaEngine engine = new VsaEngine(fast);
   engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
   engine.doPrint = true;
   engine.SetEnclosingContext(new WrappedNamespace("", 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;
 }
Ejemplo n.º 5
0
 public static GlobalScope CreateEngineAndGetGlobalScope(bool fast, String[] assemblyNames){
   VsaEngine engine = new VsaEngine(fast);
   engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
   engine.doPrint = true;
   engine.SetEnclosingContext(new WrappedNamespace("", engine));
   foreach (String assemblyName in assemblyNames){
     VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
     r.AssemblyName = assemblyName;
   }
   VsaEngine.exeEngine = engine;
   GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
   scope.globalObject = engine.Globals.globalObject;
   return scope;
 }
Ejemplo n.º 6
0
      // This factory method is called by DLL code only
      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;
      }
 public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle)
 {
     Assembly runtimeAssembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
     object data = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + runtimeAssembly.FullName);
     if (data != null)
     {
         VsaEngine engine = data as VsaEngine;
         if (engine != null)
         {
             return engine;
         }
     }
     VsaEngine engine2 = new VsaEngine(runtimeAssembly);
     engine2.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
     GlobalScope scope = (GlobalScope) engine2.GetGlobalScope().GetObject();
     scope.globalObject = engine2.Globals.globalObject;
     int num = 0;
     Type type = null;
     do
     {
         string name = "JScript " + num.ToString(CultureInfo.InvariantCulture);
         type = runtimeAssembly.GetType(name, false);
         if (type != null)
         {
             engine2.SetEnclosingContext(new WrappedNamespace("", engine2));
             ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(GlobalScope) });
             MethodInfo method = type.GetMethod("Global Code");
             try
             {
                 object obj3 = constructor.Invoke(new object[] { scope });
                 method.Invoke(obj3, new object[0]);
             }
             catch (SecurityException)
             {
                 break;
             }
         }
         num++;
     }
     while (type != null);
     if (data == null)
     {
         System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + runtimeAssembly.FullName, engine2);
     }
     return engine2;
 }
 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 str in assemblyNames)
     {
         VsaReference reference = (VsaReference) engine.vsaItems.CreateItem(str, JSVsaItemType.Reference, JSVsaItemFlag.None);
         reference.AssemblyName = str;
     }
     Assembly assembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
     System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + assembly.FullName, engine);
     GlobalScope scope = (GlobalScope) engine.GetGlobalScope().GetObject();
     scope.globalObject = engine.Globals.globalObject;
     return scope;
 }