GetParent() публичный Метод

public GetParent ( ) : ScriptObject
Результат ScriptObject
Пример #1
0
        internal override AST PartiallyEvaluate()
        {
            this.initializer = this.initializer.PartiallyEvaluate();
            ScriptObject current_scope = Globals.ScopeStack.Peek();

            while (current_scope is WithObject)
            {
                current_scope = current_scope.GetParent();
            }
            if (current_scope is FunctionScope)
            {
                FunctionScope scope  = (FunctionScope)current_scope;
                BitArray      before = scope.DefinedFlags;
                this.condition = this.condition.PartiallyEvaluate();
                //Do not need to clear the defined flags because the condition is always completely executed if the body is reached.
                this.body          = this.body.PartiallyEvaluate();
                scope.DefinedFlags = before;
                this.incrementer   = this.incrementer.PartiallyEvaluate();
                scope.DefinedFlags = before;
            }
            else
            {
                this.condition   = this.condition.PartiallyEvaluate();
                this.body        = this.body.PartiallyEvaluate();
                this.incrementer = this.incrementer.PartiallyEvaluate();
            }
            IReflect conditiontype = this.condition.InferType(null);

            if (conditiontype is FunctionPrototype || conditiontype == Typeob.ScriptFunction)
            {
                this.context.HandleError(JSError.SuspectLoopCondition);
            }
            return(this);
        }
Пример #2
0
        internal override AST PartiallyEvaluate()
        {
            this.condition = this.condition.PartiallyEvaluate();

            IReflect conditiontype = this.condition.InferType(null);

            if (conditiontype is FunctionPrototype || conditiontype == Typeob.ScriptFunction)
            {
                this.context.HandleError(JSError.SuspectLoopCondition);
            }

            ScriptObject current_scope = Globals.ScopeStack.Peek();

            while (current_scope is WithObject)
            {
                current_scope = current_scope.GetParent();
            }
            if (current_scope is FunctionScope)
            {
                FunctionScope scope  = (FunctionScope)current_scope;
                BitArray      before = scope.DefinedFlags;
                this.body          = this.body.PartiallyEvaluate();
                scope.DefinedFlags = before;
            }
            else
            {
                this.body = this.body.PartiallyEvaluate();
            }
            return(this);
        }
Пример #3
0
        internal override AST PartiallyEvaluate()
        {
            ScriptObject top = Globals.ScopeStack.Peek();

            while (top is WithObject)
            {
                top = top.GetParent();
            }
            bool isStatic = false;

            if (top is FunctionScope)
            {
                isStatic = ((FunctionScope)top).isStatic && ((FunctionScope)top).isMethod;
            }
            else if (top is StackFrame)
            {
                isStatic = ((StackFrame)top).thisObject is Type;
            }
            if (isStatic)
            {
                this.context.HandleError(JSError.NotAccessible);
                return((new Lookup("this", this.context)).PartiallyEvaluate());
            }
            return(this);
        }
 private void AddNameTo(ScriptObject enclosingScope)
 {
     while (enclosingScope is WithObject)
     {
         enclosingScope = enclosingScope.GetParent();
     }
     if (((IActivationObject) enclosingScope).GetLocalField(this.name) == null)
     {
         FieldInfo info;
         if (enclosingScope is ActivationObject)
         {
             if (enclosingScope is FunctionScope)
             {
                 info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
             }
             else
             {
                 info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Static | FieldAttributes.Public);
             }
         }
         else
         {
             info = ((StackFrame) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
         }
         JSLocalField field = info as JSLocalField;
         if (field != null)
         {
             field.debugOn = base.context.document.debugOn;
             field.isDefined = true;
         }
         this.field = (JSVariableField) info;
     }
 }
Пример #5
0
        internal Call(Context context, AST func, ASTList args, bool inBrackets)
            : base(context)
        {
            this.func              = func;
            this.args              = args == null ? new ASTList(context) : args;
            this.argValues         = null;
            this.outParameterCount = 0;
            for (int i = 0, n = this.args.count; i < n; i++)
            {
                if (this.args[i] is AddressOf)
                {
                    this.outParameterCount++;
                }
            }
            this.isConstructor                        = false;
            this.inBrackets                           = inBrackets;
            this.enclosingFunctionScope               = null;
            this.alreadyPartiallyEvaluated            = false;
            this.isAssignmentToDefaultIndexedProperty = false;
            ScriptObject scope = Globals.ScopeStack.Peek();

            while (!(scope is FunctionScope))
            {
                scope = scope.GetParent();
                if (scope == null)
                {
                    return;
                }
            }
            this.enclosingFunctionScope = (FunctionScope)scope;
        }
Пример #6
0
 protected ScriptFunction(ScriptObject parent, String name)
     : base(parent, typeof(ScriptFunction))
 {
     this.ilength = 0;
     this.name    = name;
     this.proto   = new JSPrototypeObject(parent.GetParent(), this);
 }
Пример #7
0
 internal ScriptFunction(ScriptObject parent, String name, int length)
     : base(parent)
 {
     this.ilength = length;
     this.name    = name;
     this.proto   = new JSPrototypeObject(parent.GetParent(), this);
 }
Пример #8
0
        internal virtual bool HasInstance(Object ob)
        {
            if (!(ob is JSObject))
            {
                return(false);
            }
            Object proto = this.proto;

            if (!(proto is ScriptObject))
            {
                throw new JScriptException(JSError.InvalidPrototype);
            }
            ScriptObject parent = ((JSObject)ob).GetParent();
            ScriptObject prot   = (ScriptObject)proto;

            while (parent != null)
            {
                if (parent == prot)
                {
                    return(true);
                }
                else if (parent is WithObject)
                {
                    Object wob = ((WithObject)parent).contained_object;
                    if (wob == prot && wob is ClassScope)
                    {
                        return(true);
                    }
                }
                parent = parent.GetParent();
            }
            return(false);
        }
Пример #9
0
        internal bool InStaticCode()
        {
            ScriptObject scope = this.Globals.ScopeStack.Peek();

            while (scope is WithObject || scope is BlockScope)
            {
                scope = scope.GetParent();
            }
            FunctionScope fscope = scope as FunctionScope;

            if (fscope != null)
            {
                return(fscope.isStatic);
            }
            StackFrame sframe = scope as StackFrame; //Might be a StackFrame if called from an eval

            if (sframe != null)
            {
                return(sframe.thisObject is Type);
            }
            ClassScope cscope = scope as ClassScope; //Happens when the initializers of variable declarations are partially evaluated

            if (cscope != null)
            {
                return(cscope.inStaticInitializerCode);
            }
            return(true);
        }
Пример #10
0
        internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes)
            : base(context)
        {
            this.attributes       = attributes | FieldAttributes.InitOnly;
            this.customAttributes = customAttributes;
            this.completion       = new Completion();
            this.identifier       = identifier;
            this.name             = identifier.ToString();
            this.value            = value;
            ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek();

            while (current_scope is WithObject) //Can only happen at run time and only if there is an eval
            {
                current_scope = current_scope.GetParent();
            }
            if (current_scope is ClassScope)
            {
                if (this.name == ((ClassScope)current_scope).name)
                {
                    identifier.context.HandleError(JSError.CannotUseNameOfClass);
                    this.name = this.name + " const";
                }
                if (attributes == 0)
                {
                    attributes = FieldAttributes.Public;
                }
            }
            else
            {
                if (attributes != 0)
                {
                    this.context.HandleError(JSError.NotInsideClass);
                }
                attributes = FieldAttributes.Public;
            }
            FieldInfo field = ((IActivationObject)current_scope).GetLocalField(this.name);

            if (field != null)
            {
                identifier.context.HandleError(JSError.DuplicateName, true);
                this.name = this.name + " const";
            }
            if (current_scope is ActivationObject)
            {
                this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), value, attributes);
            }
            else
            {
                this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), value, attributes | FieldAttributes.Static);
            }
            this.field.type             = type;
            this.field.customAttributes = customAttributes;
            this.field.originalContext  = context;
            if (this.field is JSLocalField)
            {
                // emit debug info for the local only if this block of code is in a section that has debug set
                ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
            }
        }
Пример #11
0
        internal TypeBuilder TranslateToILClass(CompilerGlobals compilerGlobals)
        {
            TypeBuilder classwriter = compilerGlobals.classwriter =
                compilerGlobals.module.DefineType("JScript " + (this.Engine.classCounter++).ToString(), TypeAttributes.Public, typeof(GlobalScope), null);

            compilerGlobals.classwriter.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.compilerGlobalScopeAttributeCtor, new Object[0]));

            //Define a constructor that calls the appropriate constructor on GlobalScope
            ConstructorBuilder cons = compilerGlobals.classwriter.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(GlobalScope) });
            ILGenerator        il   = cons.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
            il.Emit(OpCodes.Call, CompilerGlobals.GlobalScopeConstructor);
            il.Emit(OpCodes.Ret);

            //Define a method to contain the global code
            MethodBuilder mw = classwriter.DefineMethod("Global Code", MethodAttributes.Public, Typeob.Object, null);

            il = mw.GetILGenerator();

            if (this.Engine.GenerateDebugInfo)
            {
                ScriptObject ns = this.own_scope.GetParent();
                while (ns != null)
                {
                    if (ns is WrappedNamespace && !((WrappedNamespace)ns).name.Equals(""))
                    {
                        il.UsingNamespace(((WrappedNamespace)ns).name);
                    }
                    ns = ns.GetParent();
                }
            }

            int startLine = this.context.StartLine;
            int startCol  = this.context.StartColumn;
            //this.context.document.EmitLineInfo(il, startLine, startCol, startLine, startCol + 1); // NOTE: make the debugger stop at line 1 in the jscript source instead of in prolog code
            Context firstContext = this.GetFirstExecutableContext();

            if (firstContext != null)
            {
                firstContext.EmitFirstLineInfo(il);
            }

            //Emit code to push the scope onto the stack for use by eval
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, CompilerGlobals.pushScriptObjectMethod);
            this.TranslateToILInitializer(il);
            this.TranslateToIL(il, Typeob.Object);
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod);
            il.Emit(OpCodes.Pop);
            il.Emit(OpCodes.Ret);

            return(classwriter);
        }
Пример #12
0
        private void RemoveNamedItemNamespace()
        {
            ScriptObject current = (ScriptObject)this.Scope.GetObject(), parent = current.GetParent();

            while (parent != null)
            {
                if (parent is VsaNamedItemScope)
                {
                    if (((VsaNamedItemScope)parent).namedItem == this.hostObject)
                    {
                        // take this item out of the parent chain
                        current.SetParent(parent.GetParent());
                        break;
                    }
                }
                current = parent;
                parent  = parent.GetParent();
            }
        }
Пример #13
0
        internal override AST PartiallyEvaluate()
        {
            VsaEngine    engine = this.Engine;
            ScriptObject scope  = Globals.ScopeStack.Peek();

            ClassScope cscope = ClassScope.ScopeOfClassMemberInitializer(scope);

            if (null != cscope)
            {
                if (cscope.inStaticInitializerCode)
                {
                    cscope.staticInitializerUsesEval = true;
                }
                else
                {
                    cscope.instanceInitializerUsesEval = true;
                }
            }

            if (engine.doFast)
            {
                engine.PushScriptObject(new BlockScope(scope));
            }
            else
            {
                while (scope is WithObject || scope is BlockScope)
                {
                    if (scope is BlockScope)
                    {
                        ((BlockScope)scope).isKnownAtCompileTime = false;
                    }
                    scope = scope.GetParent();
                }
            }
            try
            {
                this.operand = this.operand.PartiallyEvaluate();
                if (this.unsafeOption != null)
                {
                    this.unsafeOption = this.unsafeOption.PartiallyEvaluate();
                }
                if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner == null)
                {
                    this.context.HandleError(JSError.NotYetImplemented);
                }
                return(this);
            }
            finally
            {
                if (engine.doFast)
                {
                    this.Engine.PopScriptObject();
                }
            }
        }
Пример #14
0
        internal override AST PartiallyEvaluate()
        {
            AST          ast;
            VsaEngine    engine = base.Engine;
            ScriptObject parent = base.Globals.ScopeStack.Peek();
            ClassScope   scope  = ClassScope.ScopeOfClassMemberInitializer(parent);

            if (scope != null)
            {
                if (scope.inStaticInitializerCode)
                {
                    scope.staticInitializerUsesEval = true;
                }
                else
                {
                    scope.instanceInitializerUsesEval = true;
                }
            }
            if (!engine.doFast)
            {
                while ((parent is WithObject) || (parent is BlockScope))
                {
                    if (parent is BlockScope)
                    {
                        ((BlockScope)parent).isKnownAtCompileTime = false;
                    }
                    parent = parent.GetParent();
                }
            }
            else
            {
                engine.PushScriptObject(new BlockScope(parent));
            }
            try
            {
                this.operand = this.operand.PartiallyEvaluate();
                if (this.unsafeOption != null)
                {
                    this.unsafeOption = this.unsafeOption.PartiallyEvaluate();
                }
                if ((this.enclosingFunctionScope != null) && (this.enclosingFunctionScope.owner == null))
                {
                    base.context.HandleError(JSError.NotYetImplemented);
                }
                ast = this;
            }
            finally
            {
                if (engine.doFast)
                {
                    base.Engine.PopScriptObject();
                }
            }
            return(ast);
        }
Пример #15
0
        internal bool IsAccessibleFrom(ScriptObject scope) //Never call this if the member is public
        {
            while (scope != null && !(scope is ClassScope))
            {
                scope = scope.GetParent();
            }
            ClassScope objType = null;

            if (this.obj is ClassScope)
            {
                objType = (ClassScope)this.obj;
            }
            else
            {
                objType = (ClassScope)((ScriptObject)this.obj).GetParent();
            }
            if (this.IsPrivate)
            {
                if (scope == null)
                {
                    return(false);
                }
                else
                {
                    return(scope == objType || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic));
                }
            }
            else if (this.IsFamily)
            {
                if (scope == null)
                {
                    return(false);
                }
                else
                {
                    return(((ClassScope)scope).IsSameOrDerivedFrom(objType) || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic));
                }
            }
            else //if (this.IsAssembly || this.IsFamilyOrAssembly)
            {
                if (this.IsFamilyOrAssembly && scope != null &&
                    (((ClassScope)scope).IsSameOrDerivedFrom(objType) || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic)))
                {
                    return(true);
                }
                else if (scope == null)                   //Code is not in a class and hence it is in the default package
                {
                    return(objType.GetPackage() == null); //null indicates default package
                }
                else
                {
                    return(objType.GetPackage() == ((ClassScope)scope).GetPackage());
                }
            }
        }
        internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context)
        {
            this.attributes       = attributes | FieldAttributes.InitOnly;
            this.customAttributes = customAttributes;
            this.completion       = new Completion();
            this.identifier       = identifier;
            this.name             = identifier.ToString();
            this.value            = value;
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            if (parent is ClassScope)
            {
                if (this.name == ((ClassScope)parent).name)
                {
                    identifier.context.HandleError(JSError.CannotUseNameOfClass);
                    this.name = this.name + " const";
                }
                if (attributes == FieldAttributes.PrivateScope)
                {
                    attributes = FieldAttributes.Public;
                }
            }
            else
            {
                if (attributes != FieldAttributes.PrivateScope)
                {
                    base.context.HandleError(JSError.NotInsideClass);
                }
                attributes = FieldAttributes.Public;
            }
            if (((IActivationObject)parent).GetLocalField(this.name) != null)
            {
                identifier.context.HandleError(JSError.DuplicateName, true);
                this.name = this.name + " const";
            }
            if (parent is ActivationObject)
            {
                this.field = ((ActivationObject)parent).AddNewField(this.identifier.ToString(), value, attributes);
            }
            else
            {
                this.field = ((StackFrame)parent).AddNewField(this.identifier.ToString(), value, attributes | FieldAttributes.Static);
            }
            this.field.type             = type;
            this.field.customAttributes = customAttributes;
            this.field.originalContext  = context;
            if (this.field is JSLocalField)
            {
                ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
            }
        }
Пример #17
0
 static internal ClassScope ScopeOfClassMemberInitializer(ScriptObject scope) {
   while (scope != null) {
     if (scope is FunctionScope)
       return null;
     ClassScope cscope = scope as ClassScope;
     if (cscope != null)
       return cscope;
     scope = scope.GetParent();
   }
   return null;
 }
Пример #18
0
        protected override Object GetObject()
        {
            Object       result;
            ScriptObject scope = Globals.ScopeStack.Peek();

            if (this.member is JSMemberField)
            {
                while (scope != null)
                {
                    StackFrame sf = scope as StackFrame;
                    if (sf != null)
                    {
                        result = sf.closureInstance; goto finish;
                    }
                    scope = scope.GetParent();
                }
                return(null);
            }
            for (int i = this.evalLexLevel; i > 0; i--)
            {
                scope = scope.GetParent();
            }
            result = scope;
finish:
            if (this.defaultMember != null)
            {
                switch (this.defaultMember.MemberType)
                {
                case MemberTypes.Field: return(((FieldInfo)this.defaultMember).GetValue(result));

                case MemberTypes.Method: return(((MethodInfo)this.defaultMember).Invoke(result, new Object[0]));

                case MemberTypes.Property: return(((PropertyInfo)this.defaultMember).GetValue(result, null));

                case MemberTypes.Event: return(null);

                case MemberTypes.NestedType: return(member);
                }
            }
            return(result);
        }
Пример #19
0
        internal override AST PartiallyEvaluate()
        {
            if (this.type != null)
            {
                this.type.PartiallyEvaluate();
                ((JSVariableField)this.field).type = type;
            }
            else if (this.field is JSLocalField)
            {
                ((JSLocalField)this.field).SetInferredType(Typeob.Object, null); //This should never give an error
            }
            ScriptObject current_scope = Globals.ScopeStack.Peek();

            while (current_scope is WithObject)
            {
                current_scope = current_scope.GetParent();
            }
            FunctionScope scope  = null;
            BitArray      before = null;

            if (current_scope is FunctionScope)
            {
                scope  = (FunctionScope)current_scope;
                before = scope.DefinedFlags;
            }
            this.body = this.body.PartiallyEvaluate();
            if (this.handler != null)
            {
                if (this.handler_scope != null)
                {
                    Globals.ScopeStack.Push(this.handler_scope);
                }
                if (this.field is JSLocalField)
                {
                    ((JSLocalField)this.field).isDefined = true;
                }
                this.handler = this.handler.PartiallyEvaluate();
                if (this.handler_scope != null)
                {
                    Globals.ScopeStack.Pop();
                }
            }
            if (this.finally_block != null)
            {
                this.finally_block = this.finally_block.PartiallyEvaluate();
            }
            if (scope != null)
            {
                scope.DefinedFlags = before;
            }
            return(this);
        }
Пример #20
0
        internal override AST PartiallyEvaluate()
        {
            if (this.type != null)
            {
                this.type.PartiallyEvaluate();
                ((JSVariableField)this.field).type = this.type;
            }
            else if (this.field is JSLocalField)
            {
                ((JSLocalField)this.field).SetInferredType(Typeob.Object, null);
            }
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            FunctionScope scope        = null;
            BitArray      definedFlags = null;

            if (parent is FunctionScope)
            {
                scope        = (FunctionScope)parent;
                definedFlags = scope.DefinedFlags;
            }
            this.body = this.body.PartiallyEvaluate();
            if (this.handler != null)
            {
                if (this.handler_scope != null)
                {
                    base.Globals.ScopeStack.Push(this.handler_scope);
                }
                if (this.field is JSLocalField)
                {
                    ((JSLocalField)this.field).isDefined = true;
                }
                this.handler = this.handler.PartiallyEvaluate();
                if (this.handler_scope != null)
                {
                    base.Globals.ScopeStack.Pop();
                }
            }
            if (this.finally_block != null)
            {
                this.finally_block = this.finally_block.PartiallyEvaluate();
            }
            if (scope != null)
            {
                scope.DefinedFlags = definedFlags;
            }
            return(this);
        }
Пример #21
0
        internal override AST PartiallyEvaluate()
        {
            if (!(this.classob.GetParent() is GlobalScope))
            {
                return(this); //The class has already been partially evaluated
            }
            this.baseType.PartiallyEvaluate();
            IReflect ir = this.baseType.ToIReflect();
            Type     bt = null;

            if (!(ir is Type) || !Convert.IsPrimitiveIntegerType(bt = (Type)ir))
            {
                this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
                this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
                bt            = Typeob.Int32;
            }

            if (this.customAttributes != null)
            {
                this.customAttributes.PartiallyEvaluate();
            }

            if (this.NeedsToBeCheckedForCLSCompliance())
            {
                if (!TypeExpression.TypeIsCLSCompliant(ir))
                {
                    this.baseType.context.HandleError(JSError.NonCLSCompliantType);
                }
                this.CheckMemberNamesForCLSCompliance();
            }

            ScriptObject scope = this.enclosingScope;

            while (!(scope is GlobalScope) && !(scope is PackageScope))
            {
                scope = scope.GetParent();
            }
            this.classob.SetParent(new WithObject(scope, typeof(Enum), true));

            Globals.ScopeStack.Push(this.classob);
            try{
                foreach (FieldInfo f in this.fields)
                {
                    JSMemberField field = (JSMemberField)f;
                    ((EnumWrapper)field.value).CoerceToBaseType(bt, field.originalContext);
                }
            }finally{
                Globals.ScopeStack.Pop();
            }
            return(this);
        }
Пример #22
0
        internal bool IsAccessibleFrom(ScriptObject scope)
        {
            while ((scope != null) && !(scope is ClassScope))
            {
                scope = scope.GetParent();
            }
            ClassScope other = null;

            if (base.obj is ClassScope)
            {
                other = (ClassScope)base.obj;
            }
            else
            {
                other = (ClassScope)base.obj.GetParent();
            }
            if (base.IsPrivate)
            {
                if (scope == null)
                {
                    return(false);
                }
                if (scope != other)
                {
                    return(((ClassScope)scope).IsNestedIn(other, base.IsStatic));
                }
                return(true);
            }
            if (base.IsFamily)
            {
                if (scope == null)
                {
                    return(false);
                }
                if (!((ClassScope)scope).IsSameOrDerivedFrom(other))
                {
                    return(((ClassScope)scope).IsNestedIn(other, base.IsStatic));
                }
                return(true);
            }
            if ((base.IsFamilyOrAssembly && (scope != null)) && (((ClassScope)scope).IsSameOrDerivedFrom(other) || ((ClassScope)scope).IsNestedIn(other, base.IsStatic)))
            {
                return(true);
            }
            if (scope == null)
            {
                return(other.GetPackage() == null);
            }
            return(other.GetPackage() == ((ClassScope)scope).GetPackage());
        }
Пример #23
0
        private void RemoveNamedItemNamespace()
        {
            ScriptObject obj2 = (ScriptObject)this.Scope.GetObject();

            for (ScriptObject obj3 = obj2.GetParent(); obj3 != null; obj3 = obj3.GetParent())
            {
                if ((obj3 is VsaNamedItemScope) && (((VsaNamedItemScope)obj3).namedItem == this.hostObject))
                {
                    obj2.SetParent(obj3.GetParent());
                    return;
                }
                obj2 = obj3;
            }
        }
        internal override object Evaluate()
        {
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while ((parent is WithObject) || (parent is BlockScope))
            {
                parent = parent.GetParent();
            }
            if (parent is StackFrame)
            {
                return(((StackFrame)parent).thisObject);
            }
            return(((GlobalScope)parent).thisObject);
        }
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            ScriptObject parent = base.Engine.ScriptObjectStackTop();

            while ((parent != null) && ((parent is WithObject) || (parent is BlockScope)))
            {
                parent = parent.GetParent();
            }
            if (parent is FunctionScope)
            {
                base.EmitILToLoadEngine(il);
                il.Emit(OpCodes.Pop);
            }
            il.Emit(OpCodes.Ldsfld, (FieldInfo)this.regExpVar.GetMetaData());
            Label label = il.DefineLabel();

            il.Emit(OpCodes.Brtrue_S, label);
            base.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.getOriginalRegExpConstructorMethod);
            il.Emit(OpCodes.Ldstr, this.source);
            if (this.ignoreCase)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (this.global)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (this.multiline)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            il.Emit(OpCodes.Call, CompilerGlobals.regExpConstructMethod);
            il.Emit(OpCodes.Castclass, Typeob.RegExpObject);
            il.Emit(OpCodes.Stsfld, (FieldInfo)this.regExpVar.GetMetaData());
            il.MarkLabel(label);
        }
 internal override AST PartiallyEvaluate()
 {
     if (base.classob.GetParent() is GlobalScope)
     {
         this.baseType.PartiallyEvaluate();
         IReflect reflect = this.baseType.ToIReflect();
         Type     bt      = null;
         if (!(reflect is Type) || !Microsoft.JScript.Convert.IsPrimitiveIntegerType(bt = (Type)reflect))
         {
             this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum);
             this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null));
             bt            = Typeob.Int32;
         }
         if (base.customAttributes != null)
         {
             base.customAttributes.PartiallyEvaluate();
         }
         if (base.NeedsToBeCheckedForCLSCompliance())
         {
             if (!TypeExpression.TypeIsCLSCompliant(reflect))
             {
                 this.baseType.context.HandleError(JSError.NonCLSCompliantType);
             }
             base.CheckMemberNamesForCLSCompliance();
         }
         ScriptObject enclosingScope = base.enclosingScope;
         while (!(enclosingScope is GlobalScope) && !(enclosingScope is PackageScope))
         {
             enclosingScope = enclosingScope.GetParent();
         }
         base.classob.SetParent(new WithObject(enclosingScope, Typeob.Enum, true));
         base.Globals.ScopeStack.Push(base.classob);
         try
         {
             JSMemberField[] fields = base.fields;
             for (int i = 0; i < fields.Length; i++)
             {
                 FieldInfo     info  = fields[i];
                 JSMemberField field = (JSMemberField)info;
                 ((DeclaredEnumValue)field.value).CoerceToBaseType(bt, field.originalContext);
             }
         }
         finally
         {
             base.Globals.ScopeStack.Pop();
         }
     }
     return(this);
 }
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            ScriptObject scope = this.Engine.ScriptObjectStackTop();

            while (scope != null && (scope is WithObject || scope is BlockScope))
            {
                scope = scope.GetParent();
            }
            if (scope is FunctionScope)
            {
                this.EmitILToLoadEngine(il); //Make sure engine gets initialized every time function is entered
                il.Emit(OpCodes.Pop);
            }
            il.Emit(OpCodes.Ldsfld, (FieldInfo)this.regExpVar.GetMetaData());
            Label exit = il.DefineLabel();

            il.Emit(OpCodes.Brtrue_S, exit);
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.getOriginalRegExpConstructorMethod);
            il.Emit(OpCodes.Ldstr, this.source);
            if (this.ignoreCase)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (this.global)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (this.multiline)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            il.Emit(OpCodes.Call, CompilerGlobals.regExpConstructMethod);
            il.Emit(OpCodes.Castclass, Typeob.RegExpObject);
            il.Emit(OpCodes.Stsfld, (FieldInfo)this.regExpVar.GetMetaData());
            il.MarkLabel(exit);
        }
Пример #28
0
 internal ScriptFunction(ScriptObject parent, String name, int numParams)
     : base(parent)
 {
     this.name        = name;
     this.lengthValue = numParams;
     if (parent != null)
     {
         this.prototypeValue =
             new JSPrototypeObject(parent.GetParent(), this);
     }
     else
     {
         this.prototypeValue = Missing.Value;
     }
 }
        internal override Object Evaluate()
        {
            ScriptObject scope = Globals.ScopeStack.Peek();
            Object       value = null;

            if (this.initializer != null)
            {
                value = this.initializer.Evaluate();
            }
            if (this.type != null)
            {
                value = Convert.Coerce(value, this.type);
            }
            else
            {
                while (scope is BlockScope)
                {
                    scope = scope.GetParent();
                }
                if (scope is WithObject)
                {
                    this.identifier.SetWithValue((WithObject)scope, value);
                }
                while (scope is WithObject || scope is BlockScope)
                {
                    scope = scope.GetParent();
                }
                if (this.initializer == null && !(this.field.value is Missing))
                {
                    this.completion.value = this.field.value;
                    return(this.completion);
                }
            }
            this.field.SetValue(scope, this.completion.value = value);
            return(this.completion);
        }
        internal override object Evaluate()
        {
            ScriptObject parent = base.Globals.ScopeStack.Peek();
            object       obj3   = null;

            if (this.initializer != null)
            {
                obj3 = this.initializer.Evaluate();
            }
            if (this.type == null)
            {
                while (parent is BlockScope)
                {
                    parent = parent.GetParent();
                }
                if (parent is WithObject)
                {
                    this.identifier.SetWithValue((WithObject)parent, obj3);
                }
                while ((parent is WithObject) || (parent is BlockScope))
                {
                    parent = parent.GetParent();
                }
                if ((this.initializer == null) && !(this.field.value is Microsoft.JScript.Missing))
                {
                    this.completion.value = this.field.value;
                    return(this.completion);
                }
            }
            else
            {
                obj3 = Microsoft.JScript.Convert.Coerce(obj3, this.type);
            }
            this.field.SetValue(parent, this.completion.value = obj3);
            return(this.completion);
        }
	internal ScriptFunction(ScriptObject parent, String name, int numParams)
			: base(parent)
			{
				this.name = name;
				this.lengthValue = numParams;
				if(parent != null)
				{
					this.prototypeValue =
						new JSPrototypeObject(parent.GetParent(), this);
				}
				else
				{
					this.prototypeValue = Missing.Value;
				}
			}
	// Constructors.
	protected ScriptFunction(ScriptObject parent, String name)
			: base(parent)
			{
				this.name = name;
				this.lengthValue = length;
				if(parent != null)
				{
					this.prototypeValue =
						new JSPrototypeObject(parent.GetParent(), this);
				}
				else
				{
					this.prototypeValue = Missing.Value;
				}
			}
Пример #33
0
 // Constructors.
 protected ScriptFunction(ScriptObject parent, String name)
     : base(parent)
 {
     this.name        = name;
     this.lengthValue = length;
     if (parent != null)
     {
         this.prototypeValue =
             new JSPrototypeObject(parent.GetParent(), this);
     }
     else
     {
         this.prototypeValue = Missing.Value;
     }
 }
Пример #34
0
        //Run up the scope chain until a FunctionScope or GlobalScope/StackFrame is encountered.
        //For a FunctionScope, defer to the owner.
        //For a ClassScope, get the engine from a CRS static, or make a new engine
        //For the GlobalScope, load the corresponding field of the this object.

        internal void EmitILToLoadEngine(ILGenerator il)
        {
            ScriptObject scope = this.Engine.ScriptObjectStackTop();

            while (scope != null && (scope is WithObject || scope is BlockScope))
            {
                scope = scope.GetParent();
            }
            if (scope is FunctionScope)
            {
                ((FunctionScope)scope).owner.TranslateToILToLoadEngine(il);
            }

            /*
             * else //inside a static initializer
             * if (this.Engine.doCRS)
             *  il.Emit(OpCodes.Ldsfld, CompilerGlobals.contextEngineField);
             * else
             *  il.Emit(OpCodes.Call, CompilerGlobals.createVsaEngine);*/
            else if (scope is ClassScope) //Inside a static initializer routine
            {
                if (this.Engine.doCRS)
                {
                    il.Emit(OpCodes.Ldsfld, CompilerGlobals.contextEngineField);
                }
                else
                {
                    if (this.context.document.engine.PEFileKind == PEFileKinds.Dll)
                    {
                        il.Emit(OpCodes.Ldtoken, ((ClassScope)scope).GetTypeBuilder());
                        il.Emit(OpCodes.Call, CompilerGlobals.createVsaEngineWithType);
                    }
                    else
                    {
                        il.Emit(OpCodes.Call, CompilerGlobals.createVsaEngine);
                    }
                }
            }
            else
            {
                //NOTE: a StackFrame is ecountered at compile time only when there is an eval.
                //Eval does not translate to IL so we should only get here if the scope is a GlobalScope
                Debug.Assert(scope is GlobalScope);
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
            }
        }
 void AddNameTo(ScriptObject enclosingScope){
   while (enclosingScope is WithObject) //Can only happen at run time and only if there is an eval
     enclosingScope = enclosingScope.GetParent();
   FieldInfo field = ((IActivationObject)enclosingScope).GetLocalField(this.name);
   if (field != null) return;
   if (enclosingScope is ActivationObject)
     if (enclosingScope is FunctionScope)
       field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
     else
       field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public|FieldAttributes.Static);
   else
     field = ((StackFrame)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
   JSLocalField lfield = field as JSLocalField;
   if (lfield != null){
     // emit debug info for the local only if this block of code is in a section that has debug set
     lfield.debugOn = this.context.document.debugOn;
     lfield.isDefined = true;
   }
   this.field = (JSVariableField)field;
 }
 internal bool IsAccessibleFrom(ScriptObject scope)
 {
     while ((scope != null) && !(scope is ClassScope))
     {
         scope = scope.GetParent();
     }
     ClassScope other = (ClassScope) this.cons.enclosing_scope;
     if (base.IsPrivate)
     {
         if (scope == null)
         {
             return false;
         }
         if (scope != other)
         {
             return ((ClassScope) scope).IsNestedIn(other, false);
         }
         return true;
     }
     if (base.IsFamily)
     {
         if (scope == null)
         {
             return false;
         }
         if (!((ClassScope) scope).IsSameOrDerivedFrom(other))
         {
             return ((ClassScope) scope).IsNestedIn(other, false);
         }
         return true;
     }
     if ((base.IsFamilyOrAssembly && (scope != null)) && (((ClassScope) scope).IsSameOrDerivedFrom(other) || ((ClassScope) scope).IsNestedIn(other, false)))
     {
         return true;
     }
     if (scope == null)
     {
         return (other.GetPackage() == null);
     }
     return (other.GetPackage() == ((ClassScope) scope).GetPackage());
 }
 internal static ClassScope ScopeOfClassMemberInitializer(ScriptObject scope)
 {
     while (scope != null)
     {
         if (scope is FunctionScope)
         {
             return null;
         }
         ClassScope scope2 = scope as ClassScope;
         if (scope2 != null)
         {
             return scope2;
         }
         scope = scope.GetParent();
     }
     return null;
 }
Пример #38
0
 protected ScriptFunction(ScriptObject parent, String name)
   : base(parent, Typeob.ScriptFunction) {
   this.ilength = length;
   this.name = name;
   this.proto = new JSPrototypeObject(parent.GetParent(), this);
 }
Пример #39
0
 private static bool InsideClassThatExtends(ScriptObject scope, Type type){
   while (scope is WithObject || scope is BlockScope)
     scope = scope.GetParent();
   if (scope is ClassScope)
     return type.IsAssignableFrom(((ClassScope)scope).GetBakedSuperType());
   if (scope is FunctionScope)
     return Binding.InsideClassThatExtends(((FunctionScope)scope).owner.enclosing_scope, type);
   //Eval does not see non public members, so don't worry about StackFrame
   return false;
 }
 internal ScriptFunction(ScriptObject parent, string name, int length) : base(parent)
 {
     this.ilength = length;
     this.name = name;
     this.proto = new JSPrototypeObject(parent.GetParent(), this);
 }
 protected ScriptFunction(ScriptObject parent, string name) : base(parent, typeof(ScriptFunction))
 {
     this.ilength = 0;
     this.name = name;
     this.proto = new JSPrototypeObject(parent.GetParent(), this);
 }
Пример #42
0
 internal bool IsAccessibleFrom(ScriptObject scope){ //Never call this if the member is public
   while (scope != null && !(scope is ClassScope))
     scope = scope.GetParent();
   ClassScope objType = null;
   if (this.obj is ClassScope)
     objType = (ClassScope)this.obj;
   else
     objType = (ClassScope)((ScriptObject)this.obj).GetParent();
   if (this.IsPrivate)
     if (scope == null)
       return false;
     else
       return scope == objType || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic);
   else if (this.IsFamily)
     if (scope == null)
       return false;
     else
       return ((ClassScope)scope).IsSameOrDerivedFrom(objType) || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic);
   else //if (this.IsAssembly)
     if (scope == null) //Code is not in a class and hence it is in the default package
       return objType.GetPackage() == null; //null indicates default package
     else
       return objType.GetPackage() == ((ClassScope)scope).GetPackage();
 }
	// Initialize the prototype value from a subclass.
	internal void InitPrototype(ScriptObject parent)
			{
				this.prototypeValue =
					new JSPrototypeObject(parent.GetParent(), this);
			}
 internal bool IsAccessibleFrom(ScriptObject scope){ //Never call this if the member is public
   while (scope != null && !(scope is ClassScope))
     scope = scope.GetParent();
   ClassScope thisScope = (ClassScope)this.cons.enclosing_scope;
   if (this.IsPrivate)
     if (scope == null)
       return false;
     else
       return scope == thisScope || ((ClassScope)scope).IsNestedIn(thisScope, false);
   else if (this.IsFamily)
     if (scope == null)
       return false;
     else
       return ((ClassScope)scope).IsSameOrDerivedFrom(thisScope) || ((ClassScope)scope).IsNestedIn(thisScope, false);
   else { // if (this.IsAssembly || this.isFamilyOrAssembly)
     if (this.IsFamilyOrAssembly && scope != null &&
         (((ClassScope)scope).IsSameOrDerivedFrom(thisScope) || ((ClassScope)scope).IsNestedIn(thisScope, false)))
       return true;
     else if (scope == null) //Code is not in a class and hence it is in the default package
       return thisScope.GetPackage() == null; //null indicates default package
     else
       return thisScope.GetPackage() == ((ClassScope)scope).GetPackage();
   }
 }