public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
        {
            bool            flag      = (bindingAttr & BindingFlags.Instance) != BindingFlags.Default;
            SimpleHashtable hashtable = flag ? this.instanceMembers : this.staticMembers;
            object          obj2      = hashtable[name];

            if (obj2 == null)
            {
                if ((bindingAttr & BindingFlags.IgnoreCase) != BindingFlags.Default)
                {
                    obj2 = hashtable.IgnoreCaseGet(name);
                }
                if (obj2 == null)
                {
                    if (flag && ((bindingAttr & BindingFlags.Static) != BindingFlags.Default))
                    {
                        return(this.GetMember(name, bindingAttr & ~BindingFlags.Instance));
                    }
                    return(EmptyMembers);
                }
            }
            int index = (int)obj2;

            MemberInfo[] infoArray = this.memberInfos[index];
            if (infoArray == null)
            {
                return(this.GetNewMemberArray(name, index));
            }
            return(infoArray);
        }
 internal FunctionScope(ScriptObject parent, bool isMethod) : base(parent)
 {
     base.isKnownAtCompileTime = true;
     this.isMethod = isMethod;
     this.mustSaveStackLocals = false;
     if ((parent != null) && (parent is ActivationObject))
     {
         base.fast = ((ActivationObject) parent).fast;
     }
     else
     {
         base.fast = false;
     }
     this.returnVar = null;
     this.owner = null;
     this.isStatic = false;
     this.nested_functions = null;
     this.fields_for_nested_functions = null;
     if (parent is FunctionScope)
     {
         this.ProvidesOuterScopeLocals = new SimpleHashtable(0x10);
     }
     else
     {
         this.ProvidesOuterScopeLocals = null;
     }
     this.closuresMightEscape = false;
 }
Beispiel #3
0
 static FieldAccessor(){
   FieldAccessor.accessorFor = new SimpleHashtable(32);
   AssemblyName name = new AssemblyName();
   name.Name = "JScript FieldAccessor Assembly";
   FieldAccessor.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
   FieldAccessor.module = FieldAccessor.assembly.DefineDynamicModule("JScript FieldAccessor Module");
 }
 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
 {
     MemberInfo[] members = null;
     if (!this.recursive)
     {
         this.recursive = true;
         try
         {
             members = this.reflectObj.GetMembers(bindingAttr);
             if (members == null)
             {
                 return(members);
             }
             if (members.Length > 0)
             {
                 SimpleHashtable namedItemWrappedMemberCache = this.namedItemWrappedMemberCache;
                 if (namedItemWrappedMemberCache == null)
                 {
                     namedItemWrappedMemberCache = this.namedItemWrappedMemberCache = new SimpleHashtable(0x10);
                 }
                 return(ScriptObject.WrapMembers(members, this.namedItem, namedItemWrappedMemberCache));
             }
             members = null;
         }
         finally
         {
             this.recursive = false;
         }
     }
     return(members);
 }
Beispiel #5
0
 internal FunctionScope(ScriptObject parent, bool isMethod) : base(parent)
 {
     base.isKnownAtCompileTime = true;
     this.isMethod             = isMethod;
     this.mustSaveStackLocals  = false;
     if ((parent != null) && (parent is ActivationObject))
     {
         base.fast = ((ActivationObject)parent).fast;
     }
     else
     {
         base.fast = false;
     }
     this.returnVar                   = null;
     this.owner                       = null;
     this.isStatic                    = false;
     this.nested_functions            = null;
     this.fields_for_nested_functions = null;
     if (parent is FunctionScope)
     {
         this.ProvidesOuterScopeLocals = new SimpleHashtable(0x10);
     }
     else
     {
         this.ProvidesOuterScopeLocals = null;
     }
     this.closuresMightEscape = false;
 }
Beispiel #6
0
 internal JSObject(ScriptObject parent, bool checkSubType)
     : base(parent)
 {
     this.memberCache = null;
     this.isASubClass = false;
     this.subClassIR  = null;
     if (checkSubType)
     {
         Type subType = this.GetType();
         Debug.Assert(subType != typeof(BuiltinFunction));
         if (subType != Typeob.JSObject)
         {
             this.isASubClass = true;
             this.subClassIR  = TypeReflector.GetTypeReflectorFor(subType);
         }
     }
     else
     {
         Debug.Assert(this.GetType() == Typeob.JSObject);
     }
     this.noExpando            = this.isASubClass;
     this.name_table           = null;
     this.field_table          = null;
     this.outer_class_instance = null;
 }
Beispiel #7
0
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            bool            lookForInstanceMembers = (bindingAttr & BindingFlags.Instance) != 0;
            SimpleHashtable lookupTable            = lookForInstanceMembers ? this.instanceMembers : this.staticMembers;
            Object          ob = lookupTable[name];

            if (ob == null)
            {
                if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
                {
                    ob = lookupTable.IgnoreCaseGet(name);
                }
                if (ob == null)
                {
                    if (lookForInstanceMembers && (bindingAttr & BindingFlags.Static) != 0)
                    {
                        return(this.GetMember(name, bindingAttr & ~BindingFlags.Instance));
                    }
                    else
                    {
                        return(TypeReflector.EmptyMembers);
                    }
                }
            }
            int index = (int)ob;

            MemberInfo[] members = this.memberInfos[index];
            if (members == null)
            {
                return(this.GetNewMemberArray(name, index));
            }
            return(members);
        }
Beispiel #8
0
 static MethodInvoker(){
   MethodInvoker.invokerFor = new SimpleHashtable(64);
   AssemblyName name = new AssemblyName();
   name.Name = "JScript MethodInvoker Assembly";
   MethodInvoker.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
   MethodInvoker.module = MethodInvoker.assembly.DefineDynamicModule("JScript MethodInvoker Module");
 }
Beispiel #9
0
        protected static MemberInfo[] WrapMembers(MemberInfo[] members, Object obj, SimpleHashtable cache)
        {
            if (members == null)
            {
                return(null);
            }
            int n = members.Length;

            if (n == 0)
            {
                return(members);
            }
            MemberInfo[] result = new MemberInfo[n];
            for (int i = 0; i < n; i++)
            {
                MemberInfo wrappedMember = (MemberInfo)cache[members[i]];
                if (null == wrappedMember)
                {
                    wrappedMember     = ScriptObject.WrapMember(members[i], obj);
                    cache[members[i]] = wrappedMember;
                }
                result[i] = wrappedMember;
            }
            return(result);
        }
Beispiel #10
0
        protected static MemberInfo[] WrapMembers(MemberInfo[] members, object obj, SimpleHashtable cache)
        {
            if (members == null)
            {
                return(null);
            }
            int length = members.Length;

            if (length == 0)
            {
                return(members);
            }
            MemberInfo[] infoArray = new MemberInfo[length];
            for (int i = 0; i < length; i++)
            {
                MemberInfo info = (MemberInfo)cache[members[i]];
                if (null == info)
                {
                    info = WrapMember(members[i], obj);
                    cache[members[i]] = info;
                }
                infoArray[i] = info;
            }
            return(infoArray);
        }
Beispiel #11
0
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
        {
            MemberInfoList  mems       = new MemberInfoList();
            SimpleHashtable uniqueMems = new SimpleHashtable(32);

            if (!this.noExpando && this.field_table != null) //Add any expando properties
            {
                IEnumerator enu = this.field_table.GetEnumerator();
                while (enu.MoveNext())
                {
                    FieldInfo field = (FieldInfo)enu.Current;
                    mems.Add(field);
                    uniqueMems[field.Name] = field;
                }
            }

            //Add the public members of the built-in objects if they don't already exist
            if (this.isASubClass)
            {
                MemberInfo[] ilMembers = this.GetType().GetMembers(bindingAttr & ~BindingFlags.NonPublic); //Never expose non public members of old style objects
                for (int i = 0, n = ilMembers.Length; i < n; i++)
                {
                    MemberInfo ilMem = ilMembers[i];

                    //Hide any infrastructure stuff in JSObject
                    if (!ilMem.DeclaringType.IsAssignableFrom(Typeob.JSObject) && uniqueMems[ilMem.Name] == null)
                    {
                        MethodInfo method = ilMem as MethodInfo;
                        if (method == null || !method.IsSpecialName)
                        {
                            mems.Add(ilMem);
                            uniqueMems[ilMem.Name] = ilMem;
                        }
                    }
                }
            }

            //Add parent members if they don't already exist
            if (this.parent != null)
            {
                SimpleHashtable cache = this.parent.wrappedMemberCache;
                if (cache == null)
                {
                    cache = this.parent.wrappedMemberCache = new SimpleHashtable(8);
                }
                MemberInfo[] parentMems = ScriptObject.WrapMembers(((IReflect)this.parent).GetMembers(bindingAttr & ~BindingFlags.NonPublic), this.parent, cache);
                for (int i = 0, n = parentMems.Length; i < n; i++)
                {
                    MemberInfo parentMem = parentMems[i];
                    if (uniqueMems[parentMem.Name] == null)
                    {
                        mems.Add(parentMem);
                        //uniqueMems[parentMem.Name] = parentMem; //No need to add to lookup table - no one else will be looking.
                    }
                }
            }

            return(mems.ToArray());
        }
      public VsaEngine engine; //This is only really useful for ScriptFunctions, IActivation objects and prototype objects. It lives here for the sake of simplicity.
      //Prototype objects do not need the scope stack, so in fast mode, all prototype objects can share a common engine.

      internal ScriptObject(ScriptObject parent){
        this.parent = parent;
        this.wrappedMemberCache = null;
        if (this.parent != null)
          this.engine = parent.engine;
        else
          this.engine = null;
      }
 public virtual void Reset()
 {
     this.index = 0;
     foreach (IEnumerator enumerator in this.enumerators)
     {
         enumerator.Reset();
     }
     this.visited_names = new SimpleHashtable(0x10);
 }
Beispiel #14
0
        internal TypeReflector(Type type)
            : base(null)
        {
            this.defaultMembers = null;
            SimpleHashtable staticMembers = new SimpleHashtable(256);

            foreach (MemberInfo member in type.GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy))
            {
                String name = member.Name;
                Object ob   = staticMembers[name];
                if (ob == null)
                {
                    staticMembers[name] = member; //Avoid allocating an array until needed
                }
                else if (ob is MemberInfo)
                {
                    MemberInfoList mems = new MemberInfoList(); //Allocate a flexarray of MemberInfo, and turn it into a fixed array when GetMember is called for this name
                    mems.Add((MemberInfo)ob);
                    mems.Add(member);
                    staticMembers[name] = mems;
                }
                else
                {
                    ((MemberInfoList)ob).Add(member);
                }
            }
            this.staticMembers = staticMembers;
            SimpleHashtable instanceMembers = new SimpleHashtable(256);

            foreach (MemberInfo member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance))
            {
                String name = member.Name;
                Object ob   = instanceMembers[name];
                if (ob == null)
                {
                    instanceMembers[name] = member; //Avoid allocating an array until needed
                }
                else if (ob is MemberInfo)
                {
                    MemberInfoList mems = new MemberInfoList();
                    mems.Add((MemberInfo)ob);
                    mems.Add(member);
                    instanceMembers[name] = mems;
                }
                else
                {
                    ((MemberInfoList)ob).Add(member);
                }
            }
            this.instanceMembers    = instanceMembers;
            this.memberInfos        = new MemberInfo[staticMembers.count + instanceMembers.count][];
            this.count              = 0;
            this.type               = type;
            this.implementsIReflect = null;
            this.hashCode           = (uint)type.GetHashCode();
            this.next               = null;
        }
Beispiel #15
0
        static FieldAccessor()
        {
            FieldAccessor.accessorFor = new SimpleHashtable(32);
            AssemblyName name = new AssemblyName();

            name.Name = "JScript FieldAccessor Assembly";
            FieldAccessor.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
            FieldAccessor.module   = FieldAccessor.assembly.DefineDynamicModule("JScript FieldAccessor Module");
        }
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
        {
            MemberInfoList  list      = new MemberInfoList();
            SimpleHashtable hashtable = new SimpleHashtable(0x20);

            if (!this.noExpando && (this.field_table != null))
            {
                IEnumerator enumerator = this.field_table.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    FieldInfo current = (FieldInfo)enumerator.Current;
                    list.Add(current);
                    hashtable[current.Name] = current;
                }
            }
            if (this.isASubClass)
            {
                MemberInfo[] members = base.GetType().GetMembers(bindingAttr & ~BindingFlags.NonPublic);
                int          index   = 0;
                int          length  = members.Length;
                while (index < length)
                {
                    MemberInfo elem = members[index];
                    if (!elem.DeclaringType.IsAssignableFrom(Typeob.JSObject) && (hashtable[elem.Name] == null))
                    {
                        MethodInfo info3 = elem as MethodInfo;
                        if ((info3 == null) || !info3.IsSpecialName)
                        {
                            list.Add(elem);
                            hashtable[elem.Name] = elem;
                        }
                    }
                    index++;
                }
            }
            if (base.parent != null)
            {
                SimpleHashtable wrappedMemberCache = base.parent.wrappedMemberCache;
                if (wrappedMemberCache == null)
                {
                    wrappedMemberCache = base.parent.wrappedMemberCache = new SimpleHashtable(8);
                }
                MemberInfo[] infoArray2 = ScriptObject.WrapMembers(base.parent.GetMembers(bindingAttr & ~BindingFlags.NonPublic), base.parent, wrappedMemberCache);
                int          num3       = 0;
                int          num4       = infoArray2.Length;
                while (num3 < num4)
                {
                    MemberInfo info4 = infoArray2[num3];
                    if (hashtable[info4.Name] == null)
                    {
                        list.Add(info4);
                    }
                    num3++;
                }
            }
            return(list.ToArray());
        }
Beispiel #17
0
        static MethodInvoker()
        {
            MethodInvoker.invokerFor = new SimpleHashtable(64);
            AssemblyName name = new AssemblyName();

            name.Name = "JScript MethodInvoker Assembly";
            MethodInvoker.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
            MethodInvoker.module   = MethodInvoker.assembly.DefineDynamicModule("JScript MethodInvoker Module");
        }
Beispiel #18
0
 public virtual void Reset()
 {
     this.index = 0;
     foreach (System.Collections.IEnumerator e in this.enumerators)
     {
         e.Reset();
     }
     this.visited_names = new SimpleHashtable(16);
 }
 internal TypeReflector(Type type)
   : base(null){
   this.defaultMembers = null;
   ArrayList memberLookupTable = new ArrayList(512);
   int count = 0;
   SimpleHashtable staticMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy)){
     String name = member.Name;
     Object ob = staticMembers[name];
     if (ob == null){
       staticMembers[name] = count++; //Avoid allocating an array until needed
       memberLookupTable.Add(member);
     }else{
       int index = (int)ob;
       ob = memberLookupTable[index];
       MemberInfo firstMember = ob as MemberInfo;
       if (firstMember != null){
         MemberInfoList mems = new MemberInfoList(); //Allocate a flexarray of MemberInfo, and turn it into a fixed array when GetMember is called for this name
         mems.Add(firstMember);
         mems.Add(member);
         memberLookupTable[index] = mems;
       }else
         ((MemberInfoList)ob).Add(member);
     }
   }
   this.staticMembers = staticMembers;
   SimpleHashtable instanceMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Instance)){
     String name = member.Name;
     Object ob = instanceMembers[name];
     if (ob == null){
       instanceMembers[name] = count++; //Avoid allocating an array until needed
       memberLookupTable.Add(member);
     }else{
       int index = (int)ob;
       ob = memberLookupTable[index];
       MemberInfo firstMember = ob as MemberInfo;
       if (firstMember != null){
         MemberInfoList mems = new MemberInfoList();
         mems.Add(firstMember);
         mems.Add(member);
         memberLookupTable[index] = mems;
       }else
         ((MemberInfoList)ob).Add(member);
     }
   }
   this.instanceMembers = instanceMembers;
   this.memberLookupTable = memberLookupTable;
   this.memberInfos = new MemberInfo[count][];
   this.type = type;
   this.implementsIReflect = null;
   this.hashCode = (uint)type.GetHashCode();
   this.next = null;
 }
 internal static BuiltinFunction BuiltinFunctionFor(Object obj, MethodInfo meth){
   if (Globals.BuiltinFunctionTable == null)
     Globals.BuiltinFunctionTable = new SimpleHashtable(64);
   BuiltinFunction result = (BuiltinFunction)Globals.BuiltinFunctionTable[meth];
   if (result != null) return result;
   result = new BuiltinFunction(obj, meth);
   lock (Globals.BuiltinFunctionTable){
     Globals.BuiltinFunctionTable[meth] = result;
   }
   return result;
 }
      [ContextStatic] public static VsaEngine contextEngine = null; //This keeps track of the (single) engine running in the current context

      internal Globals(bool fast, VsaEngine engine){
        this.engine = engine;
        this.callContextStack = null;
        this.scopeStack = null;
        this.caller = DBNull.Value;
        this.regExpTable = null;
        if (fast)
          this.globalObject = GlobalObject.commonInstance;
        else
          this.globalObject = new LenientGlobalObject(engine);
      }
        private ISymbolDocumentWriter GetSymDocument(String documentName)
        {
            SimpleHashtable documents = this.compilerGlobals.documents;
            Object          document  = documents[documentName];

            if (null == document)
            {
                document = _compilerGlobals.module.DefineDocument(this.documentName, DocumentContext.language, DocumentContext.vendor, Guid.Empty);
                documents[documentName] = document;
            }
            return((ISymbolDocumentWriter)document);
        }
Beispiel #23
0
        private ISymbolDocumentWriter GetSymDocument(string documentName)
        {
            SimpleHashtable documents = this.compilerGlobals.documents;
            object          obj2      = documents[documentName];

            if (obj2 == null)
            {
                obj2 = this._compilerGlobals.module.DefineDocument(this.documentName, language, vendor, Guid.Empty);
                documents[documentName] = obj2;
            }
            return((ISymbolDocumentWriter)obj2);
        }
 public JSScanner(Context sourceContext)
 {
     this.IsAuthoring = false;
     this.peekModeOn = false;
     this.keywords = s_Keywords;
     this.preProcessorOn = false;
     this.matchIf = 0;
     this.ppTable = null;
     this.SetSource(sourceContext);
     this.currentDocument = null;
     this.globals = sourceContext.document.engine.Globals;
 }
 internal bool HasAlreadySeenErrorFor(String varName)
 {
     if (this.reportedVariables == null)
     {
         this.reportedVariables = new SimpleHashtable(8);
     }
     else if (this.reportedVariables[varName] != null)
     {
         return(true);
     }
     this.reportedVariables[varName] = varName;
     return(false);
 }
 internal DocumentContext(String name, VsaEngine engine){
   this.documentName = name;
   this.documentWriter = null;
   this.startLine = 0;
   this.startCol = 0;
   this.lastLineInSource = 0;
   this.sourceItem = null;
   this.engine = engine;
   this.debugOn = null == engine ? false : engine.GenerateDebugInfo;
   this._compilerGlobals = null;
   this.reportedVariables = null;
   this.checkForFirst = false;
 }
Beispiel #27
0
        public VsaEngine engine; //This is only really useful for ScriptFunctions, IActivation objects and prototype objects. It lives here for the sake of simplicity.
        //Prototype objects do not need the scope stack, so in fast mode, all prototype objects can share a common engine.

        internal ScriptObject(ScriptObject parent)
        {
            this.parent             = parent;
            this.wrappedMemberCache = null;
            if (this.parent != null)
            {
                this.engine = parent.engine;
            }
            else
            {
                this.engine = null;
            }
        }
Beispiel #28
0
 internal JSObject(ScriptObject parent, Type subType)
   : base(parent) {
   this.memberCache = null;
   this.isASubClass = false;
   this.subClassIR = null;
   Debug.Assert(subType == this.GetType() || this.GetType() == typeof(BuiltinFunction));
   if (subType != Typeob.JSObject){
     this.isASubClass = true;
     this.subClassIR = TypeReflector.GetTypeReflectorFor(subType);
   }
   this.noExpando = this.isASubClass;
   this.name_table = null;
   this.field_table = null;
 }
Beispiel #29
0
      //---------------------------------------------------------------------------------------
      // JSParser
      //
      // create a parser with a context. The context is the code that has to be compiled.
      // Typically used by the runtime
      //---------------------------------------------------------------------------------------
      public JSParser(Context context){
        this.sourceContext = context;
        this.currentToken = context.Clone();
        this.scanner = new JSScanner(this.currentToken);
        this.noSkipTokenSet = new NoSkipTokenSet();

        this.errorToken = null;
        this.program = null;
        this.blockType = new ArrayList(16);
        this.labelTable = new SimpleHashtable(16);
        this.finallyEscaped = 0;
        this.Globals = context.document.engine.Globals;
        this.Severity = 5;
      }
 internal DocumentContext(String name, VsaEngine engine)
 {
     this.documentName      = name;
     this.documentWriter    = null;
     this.startLine         = 0;
     this.startCol          = 0;
     this.lastLineInSource  = 0;
     this.sourceItem        = null;
     this.engine            = engine;
     this.debugOn           = null == engine ? false : engine.GenerateDebugInfo;
     this._compilerGlobals  = null;
     this.reportedVariables = null;
     this.checkForFirst     = false;
 }
 internal JSObject(ScriptObject parent, Type subType) : base(parent)
 {
     this.memberCache = null;
     this.isASubClass = false;
     this.subClassIR  = null;
     subType          = Globals.TypeRefs.ToReferenceContext(subType);
     if (subType != Typeob.JSObject)
     {
         this.isASubClass = true;
         this.subClassIR  = TypeReflector.GetTypeReflectorFor(subType);
     }
     this.noExpando   = this.isASubClass;
     this.name_table  = null;
     this.field_table = null;
 }
Beispiel #32
0
        [ContextStatic] public static VsaEngine contextEngine = null; //This keeps track of the (single) engine running in the current context

        internal Globals(bool fast, VsaEngine engine)
        {
            this.engine           = engine;
            this.callContextStack = null;
            this.scopeStack       = null;
            this.caller           = DBNull.Value;
            this.regExpTable      = null;
            if (fast)
            {
                this.globalObject = GlobalObject.commonInstance;
            }
            else
            {
                this.globalObject = new LenientGlobalObject(engine);
            }
        }
Beispiel #33
0
 internal JSObject(ScriptObject parent, Type subType)
     : base(parent)
 {
     this.memberCache = null;
     this.isASubClass = false;
     this.subClassIR  = null;
     Debug.Assert(subType == this.GetType() || this.GetType() == typeof(BuiltinFunction));
     if (subType != Typeob.JSObject)
     {
         this.isASubClass = true;
         this.subClassIR  = TypeReflector.GetTypeReflectorFor(subType);
     }
     this.noExpando   = this.isASubClass;
     this.name_table  = null;
     this.field_table = null;
 }
 internal static BuiltinFunction BuiltinFunctionFor(object obj, MethodInfo meth)
 {
     if (BuiltinFunctionTable == null)
     {
         BuiltinFunctionTable = new SimpleHashtable(0x40);
     }
     BuiltinFunction function = (BuiltinFunction) BuiltinFunctionTable[meth];
     if (function == null)
     {
         function = new BuiltinFunction(obj, meth);
         lock (BuiltinFunctionTable)
         {
             BuiltinFunctionTable[meth] = function;
         }
     }
     return function;
 }
        internal static BuiltinFunction BuiltinFunctionFor(object obj, MethodInfo meth)
        {
            if (BuiltinFunctionTable == null)
            {
                BuiltinFunctionTable = new SimpleHashtable(0x40);
            }
            BuiltinFunction function = (BuiltinFunction)BuiltinFunctionTable[meth];

            if (function == null)
            {
                function = new BuiltinFunction(obj, meth);
                lock (BuiltinFunctionTable)
                {
                    BuiltinFunctionTable[meth] = function;
                }
            }
            return(function);
        }
Beispiel #36
0
        internal static BuiltinFunction BuiltinFunctionFor(Object obj, MethodInfo meth)
        {
            if (Globals.BuiltinFunctionTable == null)
            {
                Globals.BuiltinFunctionTable = new SimpleHashtable(64);
            }
            BuiltinFunction result = (BuiltinFunction)Globals.BuiltinFunctionTable[meth];

            if (result != null)
            {
                return(result);
            }
            result = new BuiltinFunction(obj, meth);
            lock (Globals.BuiltinFunctionTable){
                Globals.BuiltinFunctionTable[meth] = result;
            }
            return(result);
        }
Beispiel #37
0
        private MemberInfo[] GetNewMemberArray(String name, Object ob, SimpleHashtable lookupTable)
        {
            MemberInfo[] result = null;
            MemberInfo   member = ob as MemberInfo;

            if (member != null)
            {
                result = new MemberInfo[] { member }
            }
            ;
            else
            {
                result = ((MemberInfoList)ob).ToArray();
            }
            lookupTable[name] = this.count;
            this.memberInfos[this.count++] = result;
            TypeReflector.WrapMembers(result);
            return(result);
        }
 internal JSObject(ScriptObject parent, bool checkSubType) : base(parent)
 {
     this.memberCache = null;
     this.isASubClass = false;
     this.subClassIR  = null;
     if (checkSubType)
     {
         Type type = Globals.TypeRefs.ToReferenceContext(base.GetType());
         if (type != Typeob.JSObject)
         {
             this.isASubClass = true;
             this.subClassIR  = TypeReflector.GetTypeReflectorFor(type);
         }
     }
     this.noExpando            = this.isASubClass;
     this.name_table           = null;
     this.field_table          = null;
     this.outer_class_instance = null;
 }
 public static DynamicFieldInfo[] GetHashTableFields(SimpleHashtable h)
 {
     DynamicFieldInfo[] infoArray = null;
     try
     {
         int count = h.count;
         infoArray = new DynamicFieldInfo[count];
         IDictionaryEnumerator enumerator = h.GetEnumerator();
         for (int i = 0; (i < count) && enumerator.MoveNext(); i++)
         {
             infoArray[i] = new DynamicFieldInfo((string)enumerator.Key, enumerator.Value);
         }
     }
     catch
     {
         infoArray = new DynamicFieldInfo[0];
     }
     return(infoArray);
 }
Beispiel #40
0
 internal JSObject(ScriptObject parent, bool checkSubType)
   : base(parent) {
   this.memberCache = null;
   this.isASubClass = false;
   this.subClassIR = null;
   if (checkSubType){
     Type subType = this.GetType();
     Debug.Assert(subType != typeof(BuiltinFunction));
     if (subType != Typeob.JSObject){
       this.isASubClass = true;
       this.subClassIR = TypeReflector.GetTypeReflectorFor(subType);
     }
   }else
     Debug.Assert(this.GetType() == Typeob.JSObject);
   this.noExpando = this.isASubClass;
   this.name_table = null;
   this.field_table = null;
   this.outer_class_instance = null;
 }
 internal FunctionScope(ScriptObject parent, bool isMethod)
   : base(parent) {
   this.isKnownAtCompileTime = true;
   this.isMethod = isMethod;
   this.mustSaveStackLocals = false;
   if (parent != null && parent is ActivationObject)
     this.fast = ((ActivationObject)parent).fast;
   else
     this.fast = false;
   this.returnVar = null;
   this.owner = null; //Given its real value inside new FunctionObject
   this.isStatic = false; //Given its real value elsewhere
   this.nested_functions = null;
   this.fields_for_nested_functions = null;
   if (parent is FunctionScope)
     this.ProvidesOuterScopeLocals = new SimpleHashtable(16);
   else
     this.ProvidesOuterScopeLocals = null;
   this.closuresMightEscape = false;
 }
Beispiel #42
0
 internal TypeReflector(Type type)
   : base(null){
   this.defaultMembers = null;
   SimpleHashtable staticMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy)){
     String name = member.Name;
     Object ob = staticMembers[name];
     if (ob == null)
       staticMembers[name] = member; //Avoid allocating an array until needed
     else if (ob is MemberInfo){
       MemberInfoList mems = new MemberInfoList(); //Allocate a flexarray of MemberInfo, and turn it into a fixed array when GetMember is called for this name
       mems.Add((MemberInfo)ob);
       mems.Add(member);
       staticMembers[name] = mems;
     }else
       ((MemberInfoList)ob).Add(member);
   }
   this.staticMembers = staticMembers;
   SimpleHashtable instanceMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Instance)){
     String name = member.Name;
     Object ob = instanceMembers[name];
     if (ob == null)
       instanceMembers[name] = member; //Avoid allocating an array until needed
     else if (ob is MemberInfo){
       MemberInfoList mems = new MemberInfoList();
       mems.Add((MemberInfo)ob);
       mems.Add(member);
       instanceMembers[name] = mems;
     }else
       ((MemberInfoList)ob).Add(member);
   }
   this.instanceMembers = instanceMembers;
   this.memberInfos = new MemberInfo[staticMembers.count+instanceMembers.count][];
   this.count = 0;
   this.type = type;
   this.implementsIReflect = null;
   this.hashCode = (uint)type.GetHashCode();
   this.next = null;
 }
 public JSScanner(){
   this.keywords = JSScanner.s_Keywords;
   this.strSourceCode = null;
   this.startPos = 0;
   this.endPos = 0;
   this.currentPos = 0;
   this.currentLine = 1;
   this.startLinePos = 0;
   this.currentToken = null;
   this.escapedString = null;
   this.identifier = new StringBuilder(128);
   this.idLastPosOnBuilder = 0;
   this.gotEndOfLine = false;
   this.IsAuthoring = false;
   this.peekModeOn = false;
   this.preProcessorOn = false;
   this.matchIf = 0;
   this.ppTable = null;
   this.currentDocument = null;
   this.globals = null;
   this.scanForDebugger = false;
 }
      private void SetPreProcessorOn(){
        this.preProcessorOn = true;
        this.ppTable = new SimpleHashtable(16);

        // define constants

        this.ppTable["_debug"] = this.globals.engine.GenerateDebugInfo;
        this.ppTable["_fast"] = ((IActivationObject)this.globals.ScopeStack.Peek()).GetGlobalScope().fast;
        this.ppTable["_jscript"] = true;
        this.ppTable["_jscript_build"]= GlobalObject.ScriptEngineBuildVersion();
        this.ppTable["_jscript_version"] = Convert.ToNumber(GlobalObject.ScriptEngineMajorVersion() + "." + GlobalObject.ScriptEngineMinorVersion());
        this.ppTable["_microsoft"] = true;

        // define command-line symbols
        Hashtable userDefines = (Hashtable)this.globals.engine.GetOption("defines");
        if (userDefines != null)
          foreach (DictionaryEntry def in userDefines)
            this.ppTable[def.Key] = def.Value;
      }
Beispiel #45
0
 protected override void ResetCompiledState(){
   if (this.globalScope != null){
     this.globalScope.Reset();
     this.globalScope = null;
   }
   this.classCounter = 0;
   this.haveCompiledState = false;
   this.failedCompilation = true;
   this.compiledRootNamespace = null;
   this.startupClass = null;
   this.compilerGlobals = null;
   this.globals = null;
   foreach (Object item in this.vsaItems)
     ((VsaItem)item).Reset();
   this.implicitAssemblies = null;
   this.implicitAssemblyCache = null;
   this.cachedTypeLookups = null;
   this.isEngineCompiled = false;
   this.isEngineRunning = false;
   this.isCompilerSet = false;
   this.packages = null;
   this.DeleteCachedCompiledState();
 }
Beispiel #46
0
      public VsaEngine(bool fast) : base("JScript", "7.0.3300.0", true){
        this.alwaysGenerateIL = false;
        this.autoRef = false;
        this.doCRS = false;
        this.doFast = fast;
        this.cachedPEFileName = "";
        this.genDebugInfo = false;
        this.genStartupClass = true;
        this.doPrint = false;
        this.doWarnAsError = false;
        this.nWarningLevel = 4;
        this.isCLSCompliant = false;
        this.versionSafe = false;
        this.PEFileName = null;
        this.PEFileKind = PEFileKinds.Dll;
        this.errorCultureInfo = null;
        this.libpath = null;
        this.libpathList = null;

        this.globalScope = null;
        this.vsaItems = new VsaItems(this);
        this.packages = null;
        this.scopes = null;
        this.classCounter = 0;
        this.implicitAssemblies = null;
        this.implicitAssemblyCache = null;
        this.cachedTypeLookups = null;

        this.isEngineRunning = false;
        this.isEngineCompiled = false;
        this.isCompilerSet = false;
        this.isClosed = false;

        this.runningThread = null;
        this.compilerGlobals = null;
        this.globals = null;
        this.runtimeDirectory = null;
        Globals.contextEngine = this;
        this.runtimeAssembly = null;
        this.typenameTable = null;
      }
Beispiel #47
0
      internal Type GetType(String typeName){
        if (this.cachedTypeLookups == null)
          this.cachedTypeLookups = new SimpleHashtable(1000);
        object cacheResult = this.cachedTypeLookups[typeName];
        if (cacheResult == null){
          // proceed with lookup
          for (int i = 0, n = this.Scopes.Count; i < n; i++){
            GlobalScope scope = (GlobalScope)this.scopes[i];
            Type result = scope.GetType().Module.Assembly.GetType(typeName, false);
            if (result != null){
              this.cachedTypeLookups[typeName] = result;
              return result;
            }
          }

          if (this.runtimeAssembly != null) {
            this.AddReferences();
            this.runtimeAssembly = null;
          }

          for (int i = 0, n = this.vsaItems.Count; i < n; i++){
            object item = this.vsaItems[i];
            if (item is VsaReference){
              Type result = ((VsaReference)item).GetType(typeName);
              if (result != null){
                this.cachedTypeLookups[typeName] = result;
                return result;
              }
            }
          }
          if (this.implicitAssemblies == null){
            this.cachedTypeLookups[typeName] = false;
            return null;
          }
          for (int i = 0, n = this.implicitAssemblies.Count; i < n; i++){
            Assembly assembly = (Assembly)this.implicitAssemblies[i];
            Type result = assembly.GetType(typeName, false);
            if (result != null){
              if (!result.IsPublic || result.IsDefined(typeof(System.Runtime.CompilerServices.RequiredAttributeAttribute), true))
                result = null; //Suppress the type if it is not public or if it is a funky C++ type.
              else{
                this.cachedTypeLookups[typeName] = result;
                return result;
              }
            }
          }
          this.cachedTypeLookups[typeName] = false;
          return null;
        }
        return (cacheResult as Type);
      }
Beispiel #48
0
 private MemberInfo[] GetLocalMember(String name, BindingFlags bindingAttr, bool wrapMembers){
   MemberInfo[] result = null;
   FieldInfo field = this.name_table == null ? null : (FieldInfo)this.name_table[name];
   if (field == null && this.isASubClass){
     if (this.memberCache != null){
       result = (MemberInfo[])this.memberCache[name];
       if (result != null) return result;
     }
     bindingAttr &= ~BindingFlags.NonPublic; //Never expose non public fields of old style objects
     result = this.subClassIR.GetMember(name, bindingAttr);
     if (result.Length == 0)
       result = this.subClassIR.GetMember(name, (bindingAttr&~BindingFlags.Instance)|BindingFlags.Static);
     int n = result.Length;
     if (n > 0){
       //Suppress any members that are declared in JSObject or earlier. But keep the ones in Object.
       int hiddenMembers = 0;
       foreach (MemberInfo mem in result){
         Type mtype = mem.DeclaringType;
         if (mtype == Typeob.JSObject || mtype == Typeob.ScriptObject || mtype == Typeob.ArrayWrapper)
           hiddenMembers++;
       }
       if (hiddenMembers > 0 && !(n == 1 && this is ObjectPrototype && name == "ToString")){
         MemberInfo[] newResult = new MemberInfo[n-hiddenMembers];
         int j = 0;
         foreach (MemberInfo mem in result){
           Type mtype = mem.DeclaringType;
           if (mtype != Typeob.JSObject && mtype != Typeob.ScriptObject && mtype != Typeob.ArrayWrapper)
             newResult[j++] = mem;
         }
         result = newResult;
       }
     }
     if ((result == null || result.Length == 0) && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0){
       BindingFlags flags = (bindingAttr & BindingFlags.IgnoreCase) | BindingFlags.Public | BindingFlags.Instance;
       if (this is StringObject)
         result = TypeReflector.GetTypeReflectorFor(Typeob.String).GetMember(name, flags);
       else if (this is NumberObject)
         result = TypeReflector.GetTypeReflectorFor(((NumberObject)this).baseType).GetMember(name, flags);
       else if (this is BooleanObject)
         result = TypeReflector.GetTypeReflectorFor(Typeob.Boolean).GetMember(name, flags);
       else if (this is StringConstructor)
         result = TypeReflector.GetTypeReflectorFor(Typeob.String).GetMember(name, (flags|BindingFlags.Static)&~BindingFlags.Instance);
       else if (this is BooleanConstructor)
         result = TypeReflector.GetTypeReflectorFor(Typeob.Boolean).GetMember(name, (flags|BindingFlags.Static)&~BindingFlags.Instance);
       else if (this is ArrayWrapper)
         result = TypeReflector.GetTypeReflectorFor(Typeob.Array).GetMember(name, flags);
     }
     if (result != null && result.Length > 0){
       if (wrapMembers)
         result = ScriptObject.WrapMembers(result, this);
       if (this.memberCache == null) this.memberCache = new SimpleHashtable(32);
       this.memberCache[name] = result;
       return result;
     }
   }
   if ((bindingAttr&BindingFlags.IgnoreCase) != 0 && (result == null || result.Length == 0)){
     result = null;
     IDictionaryEnumerator e = this.name_table.GetEnumerator();
     while (e.MoveNext()){
       if (String.Compare(e.Key.ToString(), name, true, CultureInfo.InvariantCulture) == 0){
         field = (FieldInfo)e.Value;
         break;
       }
     }
   }
   if (field != null)
     return new MemberInfo[]{field};
   if (result == null) result = new MemberInfo[0];
   return result;
 }
Beispiel #49
0
 public override MemberInfo[] GetMembers(BindingFlags bindingAttr){
   MemberInfo[] members = null;
   if (!this.recursive){
     this.recursive = true;
     try{
     members = this.reflectObj.GetMembers(bindingAttr);
     if (members != null)
       if (members.Length > 0){
         SimpleHashtable cache = this.namedItemWrappedMemberCache;
         if (cache == null)
           cache = this.namedItemWrappedMemberCache = new SimpleHashtable(16);
         members = ScriptObject.WrapMembers(members, this.namedItem, cache);
       }
       else
         members = null;
     }finally{
       this.recursive = false;
     }
   }
   return members;
 }
Beispiel #50
0
 private void GetStartIndexForEachName(){
   SimpleHashtable firstIndex = new SimpleHashtable(32);
   String lastName = null;
   for (int i = 0, n = this.superMembers.Length; i < n; i++){
     String name = ((MemberInfo)this.superMembers[i]).Name;
     if (name != lastName)
       firstIndex[lastName = name] = i;
   }
   this.firstIndex = firstIndex;
 }
 internal bool HasAlreadySeenErrorFor(String varName){
   if (this.reportedVariables == null)
     this.reportedVariables = new SimpleHashtable(8);
   else if (this.reportedVariables[varName] != null)
     return true;
   this.reportedVariables[varName] = varName;
   return false;
 }
      void CreateEntryPointIL(ILGenerator il, FieldInfo site, TypeBuilder startupClass){
        LocalBuilder globalScope = il.DeclareLocal(Typeob.GlobalScope);

        //Emit code to create an engine. We do this explicitly so that we can control fast mode.
        if (this.doFast)
          il.Emit(OpCodes.Ldc_I4_1);
        else
          il.Emit(OpCodes.Ldc_I4_0);
        //Run through the list of references and emit code to create an array of strings representing them
        //but do not emit duplicates.
        SimpleHashtable uniqueReferences = new SimpleHashtable((uint)this.vsaItems.Count);
        ArrayList references = new ArrayList();
        foreach (Object item in this.vsaItems){
          if (item is VsaReference){
            string assemblyName = ((VsaReference)item).Assembly.GetName().FullName;
            if (uniqueReferences[assemblyName] == null){
              references.Add(assemblyName);
              uniqueReferences[assemblyName] = item;
            }
          }
        }
        if (this.implicitAssemblies != null){
          foreach (Object item in this.implicitAssemblies){
            Assembly a = item as Assembly;
            if (a != null){
              String assemblyName = a.GetName().FullName;
              if (uniqueReferences[assemblyName] == null){
                references.Add(assemblyName);
                uniqueReferences[assemblyName] = item;
              }
            }
          }
        }

        ConstantWrapper.TranslateToILInt(il, references.Count);
        il.Emit(OpCodes.Newarr, Typeob.String);
        int num = 0;
        foreach (string referenceName in references){
          il.Emit(OpCodes.Dup);
          ConstantWrapper.TranslateToILInt(il, num++);
          il.Emit(OpCodes.Ldstr, referenceName);
          il.Emit(OpCodes.Stelem_Ref);
        }
        if (startupClass != null){
          il.Emit(OpCodes.Ldtoken, startupClass);
          if (this.rootNamespace != null) 
            il.Emit(OpCodes.Ldstr, this.rootNamespace);
          else 
            il.Emit(OpCodes.Ldnull);
          MethodInfo createEngineAndGetGlobalScopeWithTypeAndRootNamespace = Typeob.VsaEngine.GetMethod("CreateEngineAndGetGlobalScopeWithTypeAndRootNamespace");
          il.Emit(OpCodes.Call, createEngineAndGetGlobalScopeWithTypeAndRootNamespace);
        }else{
          MethodInfo createEngineAndGetGlobalScope = Typeob.VsaEngine.GetMethod("CreateEngineAndGetGlobalScope");
          il.Emit(OpCodes.Call, createEngineAndGetGlobalScope);
        }
        il.Emit(OpCodes.Stloc, globalScope);

        // get global object instances and event source instances (CreateStartupClass scenario only)
        if (site != null) this.CreateHostCallbackIL(il, site);

        bool setUserEntryPoint = this.genDebugInfo;
       
        // for every generated class make an instance and call the main routine method
        
        // When there are multiple VsaStaticCode items, all members of relevance are lifted to the
        // first one. VsaStaticCode does not munge with the runtime scope chain, and instead
        // relies on the code here to set things up before the global code is called.
        bool codeToSetupGlobalScopeEmitted = false;                           // have we hit the first VsaStaticCode item
        foreach (Object item in this.vsaItems){
          Type compiledType = ((VsaItem)item).GetCompiledType();
          if (null != compiledType){
            ConstructorInfo globalScopeConstructor = compiledType.GetConstructor(new Type[]{Typeob.GlobalScope});
            MethodInfo globalCode = compiledType.GetMethod("Global Code");
            if (setUserEntryPoint){
              //Set the Global Code method of the first code item to be the place where the debugger breaks for the first step into
              this.CompilerGlobals.module.SetUserEntryPoint(globalCode);
              setUserEntryPoint = false; //Do it once only
            }
            
            il.Emit(OpCodes.Ldloc, globalScope);
            il.Emit(OpCodes.Newobj, globalScopeConstructor);
            
            if (!codeToSetupGlobalScopeEmitted && item is VsaStaticCode) {
              // This is the first VsaStaticCode item which holds all the relevant members.
              // Push it onto the runtime scope stack.
              LocalBuilder firstStaticScope = il.DeclareLocal(compiledType); // all members lifted to this object
              il.Emit(OpCodes.Stloc, firstStaticScope); 

              // Call globalScope.engine.PushScriptObject(firstStaticScope)
              il.Emit(OpCodes.Ldloc, globalScope);
              il.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
              il.Emit(OpCodes.Ldloc, firstStaticScope);
              il.Emit(OpCodes.Call, CompilerGlobals.pushScriptObjectMethod);
          
              // Restore stack for the next Call instruction.
              il.Emit(OpCodes.Ldloc, firstStaticScope);
              codeToSetupGlobalScopeEmitted = true;
            }

            il.Emit(OpCodes.Call, globalCode);
            il.Emit(OpCodes.Pop);
          }
        }

        if (codeToSetupGlobalScopeEmitted) {
          // A VsaStaticCode item was encountered and code to setup the runtime
          // stack was emitted. Restore the stack.
          il.Emit(OpCodes.Ldloc, globalScope);
          il.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
          il.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod);
          il.Emit(OpCodes.Pop);
        }

        // a method needs a return opcode
        il.Emit(OpCodes.Ret);
      }
Beispiel #53
0
 public override MemberInfo[] GetMembers(BindingFlags bindingAttr){
   MemberInfoList mems = new MemberInfoList();
   SimpleHashtable uniqueMems = new SimpleHashtable(32);
   
   if (!this.noExpando && this.field_table != null){ //Add any expando properties
     IEnumerator enu = this.field_table.GetEnumerator();
     while (enu.MoveNext()){
       FieldInfo field = (FieldInfo)enu.Current;
       mems.Add(field);
       uniqueMems[field.Name] = field;
     }
   }
   
   //Add the public members of the built-in objects if they don't already exist
   if (this.isASubClass){ 
     MemberInfo[] ilMembers = this.GetType().GetMembers(bindingAttr & ~BindingFlags.NonPublic); //Never expose non public members of old style objects
     for (int i = 0, n = ilMembers.Length; i < n; i++){
       MemberInfo ilMem = ilMembers[i];
       
       //Hide any infrastructure stuff in JSObject
       if (!ilMem.DeclaringType.IsAssignableFrom(Typeob.JSObject) && uniqueMems[ilMem.Name] == null){
         MethodInfo method = ilMem as MethodInfo;
         if (method == null || !method.IsSpecialName){
           mems.Add(ilMem);
           uniqueMems[ilMem.Name] = ilMem;
         }
       }
     }
   }
   
   //Add parent members if they don't already exist
   if (this.parent != null){
     SimpleHashtable cache = this.parent.wrappedMemberCache;
     if (cache == null)
       cache = this.parent.wrappedMemberCache = new SimpleHashtable(8);
     MemberInfo[] parentMems = ScriptObject.WrapMembers(((IReflect)this.parent).GetMembers(bindingAttr & ~BindingFlags.NonPublic), this.parent, cache);
     for(int i = 0, n = parentMems.Length; i < n; i++){
       MemberInfo parentMem = parentMems[i];
       if(uniqueMems[parentMem.Name] == null){
         mems.Add(parentMem);
         //uniqueMems[parentMem.Name] = parentMem; //No need to add to lookup table - no one else will be looking.
       }
     }
   }
   
   return mems.ToArray();
 }
Beispiel #54
0
 protected static MemberInfo[] WrapMembers
     (MemberInfo[] members, Object obj, SimpleHashtable cache)
 {
     // TODO
     return(null);
 }
Beispiel #55
0
 internal ScriptObjectPropertyEnumerator(ScriptObject obj)
 {
     obj.GetPropertyEnumerator(this.enumerators = new ArrayList(), this.objects = new ArrayList());
     this.index         = 0;
     this.visited_names = new SimpleHashtable(16);
 }
Beispiel #56
0
 private void EmitReferences() 
 {
   SimpleHashtable emitted = new SimpleHashtable((uint)this.vsaItems.Count + (this.implicitAssemblies == null ? 0 : (uint)this.implicitAssemblies.Count));
   foreach (Object item in this.vsaItems){
     if (item is VsaReference){
       String referenceName = ((VsaReference)item).Assembly.GetName().FullName;
       // do not write duplicate assemblies
       if (emitted[referenceName] == null){
         CustomAttributeBuilder cab = new CustomAttributeBuilder(CompilerGlobals.referenceAttributeConstructor, new Object[1] {referenceName});
         this.CompilerGlobals.assemblyBuilder.SetCustomAttribute(cab);
         emitted[referenceName] = item;
       }
     }
   }
   if (this.implicitAssemblies != null){
     foreach (Object item in this.implicitAssemblies){
       Assembly a = item as Assembly;
       if (a != null){
         String referenceName = a.GetName().FullName;
         // do not write duplicate assemblies
         if (emitted[referenceName] == null){
           CustomAttributeBuilder cab = new CustomAttributeBuilder(CompilerGlobals.referenceAttributeConstructor, new Object[1] {referenceName});
           this.CompilerGlobals.assemblyBuilder.SetCustomAttribute(cab);
           emitted[referenceName] = item;
         }
       }
     }
   }
 }
Beispiel #57
0
      void CreateEntryPointIL(ILGenerator il, FieldInfo site, TypeBuilder startupClass){
        LocalBuilder globalScope = il.DeclareLocal(typeof(GlobalScope));

        //Emit code to create an engine. We do this explicitly so that we can control fast mode.
        if (this.doFast)
          il.Emit(OpCodes.Ldc_I4_1);
        else
          il.Emit(OpCodes.Ldc_I4_0);
        //Run through the list of references and emit code to create an array of strings representing them
        //but do not emit duplicates.
        SimpleHashtable uniqueReferences = new SimpleHashtable((uint)this.vsaItems.Count);
        ArrayList references = new ArrayList();
        foreach (Object item in this.vsaItems){
          if (item is VsaReference){
            string assemblyName = ((VsaReference)item).Assembly.GetName().FullName;
            if (uniqueReferences[assemblyName] == null){
              references.Add(assemblyName);
              uniqueReferences[assemblyName] = item;
            }
          }
        }
        if (this.implicitAssemblies != null){
          foreach (Object item in this.implicitAssemblies){
            Assembly a = item as Assembly;
            if (a != null){
              String assemblyName = a.GetName().FullName;
              if (uniqueReferences[assemblyName] == null){
                references.Add(assemblyName);
                uniqueReferences[assemblyName] = item;
              }
            }
          }
        }

        ConstantWrapper.TranslateToILInt(il, references.Count);
        il.Emit(OpCodes.Newarr, Typeob.String);
        int num = 0;
        foreach (string referenceName in references){
          il.Emit(OpCodes.Dup);
          ConstantWrapper.TranslateToILInt(il, num++);
          il.Emit(OpCodes.Ldstr, referenceName);
          il.Emit(OpCodes.Stelem_Ref);
        }
        if (startupClass != null){
          MethodInfo createEngineAndGetGlobalScopeWithType = this.GetType().GetMethod("CreateEngineAndGetGlobalScopeWithType");
          il.Emit(OpCodes.Ldtoken, startupClass);
          il.Emit(OpCodes.Call, createEngineAndGetGlobalScopeWithType);
        }else{
          MethodInfo createEngineAndGetGlobalScope = this.GetType().GetMethod("CreateEngineAndGetGlobalScope");
          il.Emit(OpCodes.Call, createEngineAndGetGlobalScope);
        }
        il.Emit(OpCodes.Stloc, globalScope);

        // get global object instances and event source instances (CreateStartupClass scenario only)
        if (site != null) this.CreateHostCallbackIL(il, site);

        bool setUserEntryPoint = this.genDebugInfo;
        // for every generated class make an instance and call the main routine method
        foreach (Object item in this.vsaItems){
          Type compiledType = ((VsaItem)item).GetCompiledType();
          if (null != compiledType){
            ConstructorInfo globalScopeConstructor = compiledType.GetConstructor(new Type[]{typeof(GlobalScope)});
            MethodInfo globalCode = compiledType.GetMethod("Global Code");
            if (setUserEntryPoint){
              //Set the Global Code method of the first code item to be the place where the debugger breaks for the first step into
              this.CompilerGlobals.module.SetUserEntryPoint(globalCode);
              setUserEntryPoint = false; //Do it once only
            }
            il.Emit(OpCodes.Ldloc, globalScope);
            il.Emit(OpCodes.Newobj, globalScopeConstructor);
            il.Emit(OpCodes.Call, globalCode);
            il.Emit(OpCodes.Pop);
          }
        }
        // a method needs a return opcode
        il.Emit(OpCodes.Ret);
      }
Beispiel #58
0
 internal SuperTypeMembersSorter()
 {
     this.members = new SimpleHashtable(64);
     this.names   = new ArrayList();
     this.count   = 0;
 }
Beispiel #59
0
 internal void TryToAddImplicitAssemblyReference(String name){
   if (!this.autoRef) return;
   
   String key;
   SimpleHashtable implictAssemblyCache = this.implicitAssemblyCache;
   if (implicitAssemblyCache == null) {
     //Populate cache with things that should not be autoref'd. Canonical form is lower case without extension.
     implicitAssemblyCache = new SimpleHashtable(50);
     
     //PEFileName always includes an extension and is never NULL.
     implicitAssemblyCache[Path.GetFileNameWithoutExtension(this.PEFileName).ToLower(CultureInfo.InvariantCulture)] = true;
     
     foreach (Object item in this.vsaItems){
       VsaReference assemblyReference = item as VsaReference;
       if (assemblyReference == null || assemblyReference.AssemblyName == null) continue;
       key = Path.GetFileName(assemblyReference.AssemblyName).ToLower(CultureInfo.InvariantCulture);
       if (key.EndsWith(".dll"))
         key = key.Substring(0, key.Length-4);
       implicitAssemblyCache[key] = true;
     }          
     this.implicitAssemblyCache = implicitAssemblyCache;          
   }
   
   key = name.ToLower(CultureInfo.InvariantCulture);
   if (implicitAssemblyCache[key] != null) return;
   implicitAssemblyCache[key] = true;
   
   try{
     VsaReference assemblyReference = new VsaReference(this, name + ".dll");
     if (assemblyReference.Compile(false)){
       ArrayList implicitAssemblies = this.implicitAssemblies;
       if (implicitAssemblies == null) {
          implicitAssemblies = new ArrayList();
          this.implicitAssemblies = implicitAssemblies;
       }
       implicitAssemblies.Add(assemblyReference.Assembly);
     }
   }catch(VsaException){
   }
 }
Beispiel #60
0
 internal Class(Context context, AST id, TypeExpression superTypeExpression, TypeExpression[] interfaces, Block body, 
   FieldAttributes attributes, bool isAbstract, bool isFinal, bool isStatic, bool isInterface, CustomAttributeList customAttributes)
   : base(context) {
   this.name = id.ToString();
   this.superTypeExpression = superTypeExpression;
   this.interfaces = interfaces;
   this.body = body;
   this.enclosingScope = (ScriptObject)Globals.ScopeStack.Peek(1);
   this.attributes = TypeAttributes.Class|TypeAttributes.Serializable;
   this.SetAccessibility(attributes);
   if (isAbstract)
     this.attributes |= TypeAttributes.Abstract;
   this.isAbstract = isAbstract || isInterface;
   this.isAlreadyPartiallyEvaluated = false;
   if (isFinal)
     this.attributes |= TypeAttributes.Sealed;
   if (isInterface)
     this.attributes |= TypeAttributes.Interface | TypeAttributes.Abstract;
   this.isCooked = false;
   this.cookedType = null;
   this.isExpando = false;
   this.isInterface = isInterface;
   this.isStatic = isStatic;
   this.needsEngine = !isInterface;
   this.validOn = (AttributeTargets)0;
   this.allowMultiple = true;
   this.classob = (ClassScope)Globals.ScopeStack.Peek();
   this.classob.name = this.name;
   this.classob.owner = this;
   this.implicitDefaultConstructor = null;
   if (!isInterface && !(this is EnumDeclaration))
     this.SetupConstructors();
   this.EnterNameIntoEnclosingScopeAndGetOwnField(id, isStatic);
   this.fields = this.classob.GetMemberFields();
   this.superClass = null;
   this.superIR = null;
   this.superMembers = null;
   this.firstIndex = null;
   this.fieldInitializer = null;
   this.customAttributes = customAttributes;
   this.clsCompliance = CLSComplianceSpec.NotAttributed;
   this.generateCodeForExpando = false;
   this.expandoItemProp = null;
   this.getHashTableMethod = null;
   this.getItem = null;
   this.setItem = null;
 }