Example #1
0
        internal virtual void TranslateToILPreSetPlusGet(ILGenerator il, ASTList args, bool inBrackets)
        {
            il.Emit(OpCodes.Ldnull); //Put a dummy this obj on the stack for CallValue's sake
            this.TranslateToIL(il, Typeob.Object);
            il.Emit(OpCodes.Dup);
            LocalBuilder savedOb = il.DeclareLocal(Typeob.Object);

            il.Emit(OpCodes.Stloc, savedOb);
            args.TranslateToIL(il, typeof(Object[]));
            il.Emit(OpCodes.Dup);
            LocalBuilder savedArgs = il.DeclareLocal(typeof(Object[]));

            il.Emit(OpCodes.Stloc, savedArgs);
            il.Emit(OpCodes.Ldc_I4_0);
            if (inBrackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
            LocalBuilder savedResult = il.DeclareLocal(Typeob.Object);

            il.Emit(OpCodes.Stloc, savedResult);
            il.Emit(OpCodes.Ldloc, savedOb);
            il.Emit(OpCodes.Ldloc, savedArgs);
            il.Emit(OpCodes.Ldloc, savedResult);
        }
Example #2
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;
            int num   = 0;
            int count = this.args.count;

            while (num < count)
            {
                if (this.args[num] is AddressOf)
                {
                    this.outParameterCount++;
                }
                num++;
            }
            this.isConstructor                        = false;
            this.inBrackets                           = inBrackets;
            this.enclosingFunctionScope               = null;
            this.alreadyPartiallyEvaluated            = false;
            this.isAssignmentToDefaultIndexedProperty = false;
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (!(parent is FunctionScope))
            {
                parent = parent.GetParent();
                if (parent == null)
                {
                    return;
                }
            }
            this.enclosingFunctionScope = (FunctionScope)parent;
        }
Example #3
0
 internal override Object ResolveCustomAttribute(ASTList args, IReflect[] argIRs, AST target)
 {
     if (this.name == "expando")
     {
         this.members = Typeob.Expando.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
     }
     else if (this.name == "override")
     {
         this.members = Typeob.Override.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
     }
     else if (this.name == "hide")
     {
         this.members = Typeob.Hide.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
     }
     else if (this.name == "...")
     {
         this.members = Typeob.ParamArrayAttribute.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
     }
     else
     {
         this.name = this.name + "Attribute";
         this.BindName();
         if (this.members == null || this.members.Length == 0)
         {
             this.name = this.name.Substring(0, this.name.Length - 9);
             this.BindName();
         }
     }
     return(base.ResolveCustomAttribute(args, argIRs, target));
 }
Example #4
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;
        }
Example #5
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            MethodInfo meth = this.method;

            if (meth != null)
            {
                Type t = meth.ReflectedType;
                if (!meth.IsStatic)
                {
                    this.method = null;
                    this.TranslateToIL(il, t);
                    this.method = meth;
                }
                ParameterInfo[] pars = meth.GetParameters();
                Binding.PlaceArgumentsOnStack(il, pars, argList, 0, 0, Binding.ReflectionMissingCW);
                if (meth.IsVirtual && !meth.IsFinal && !t.IsSealed)
                {
                    il.Emit(OpCodes.Callvirt, meth);
                }
                else
                {
                    il.Emit(OpCodes.Call, meth);
                }
                Convert.Emit(this, il, meth.ReturnType, rtype);
            }
            else
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
            }
        }
        internal virtual void TranslateToILPreSetPlusGet(ILGenerator il, ASTList args, bool inBrackets)
        {
            il.Emit(OpCodes.Ldnull);
            this.TranslateToIL(il, Typeob.Object);
            il.Emit(OpCodes.Dup);
            LocalBuilder local = il.DeclareLocal(Typeob.Object);

            il.Emit(OpCodes.Stloc, local);
            args.TranslateToIL(il, Typeob.ArrayOfObject);
            il.Emit(OpCodes.Dup);
            LocalBuilder builder2 = il.DeclareLocal(Typeob.ArrayOfObject);

            il.Emit(OpCodes.Stloc, builder2);
            il.Emit(OpCodes.Ldc_I4_0);
            if (inBrackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
            LocalBuilder builder3 = il.DeclareLocal(Typeob.Object);

            il.Emit(OpCodes.Stloc, builder3);
            il.Emit(OpCodes.Ldloc, local);
            il.Emit(OpCodes.Ldloc, builder2);
            il.Emit(OpCodes.Ldloc, builder3);
        }
Example #7
0
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets){
   if (this.defaultMember != null && construct && brackets){
     base.TranslateToILCall(il, rtype, argList, construct, brackets);
     return;
   }
   JSGlobalField gf = this.member as JSGlobalField;
   if (gf != null && gf.IsLiteral && argList.count == 1){
     Type t = Convert.ToType((IReflect)gf.value);
     argList[0].TranslateToIL(il, t);
     Convert.Emit(this, il, t, rtype);
     return;
   }
   this.TranslateToILWithDupOfThisOb(il);
   argList.TranslateToIL(il, typeof(Object[]));
   if (construct)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   if (brackets)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   this.EmitILToLoadEngine(il);
   il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
   Convert.Emit(this, il, Typeob.Object, rtype);
 }
 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;
     int num = 0;
     int count = this.args.count;
     while (num < count)
     {
         if (this.args[num] is AddressOf)
         {
             this.outParameterCount++;
         }
         num++;
     }
     this.isConstructor = false;
     this.inBrackets = inBrackets;
     this.enclosingFunctionScope = null;
     this.alreadyPartiallyEvaluated = false;
     this.isAssignmentToDefaultIndexedProperty = false;
     ScriptObject parent = base.Globals.ScopeStack.Peek();
     while (!(parent is FunctionScope))
     {
         parent = parent.GetParent();
         if (parent == null)
         {
             return;
         }
     }
     this.enclosingFunctionScope = (FunctionScope) parent;
 }
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            MethodInfo method = this.method;

            if (method != null)
            {
                Type reflectedType = method.ReflectedType;
                if (!method.IsStatic)
                {
                    this.method = null;
                    this.TranslateToIL(il, reflectedType);
                    this.method = method;
                }
                ParameterInfo[] parameters = method.GetParameters();
                Binding.PlaceArgumentsOnStack(il, parameters, argList, 0, 0, Binding.ReflectionMissingCW);
                if ((method.IsVirtual && !method.IsFinal) && (!reflectedType.IsSealed || !reflectedType.IsValueType))
                {
                    il.Emit(OpCodes.Callvirt, method);
                }
                else
                {
                    il.Emit(OpCodes.Call, method);
                }
                Microsoft.JScript.Convert.Emit(this, il, method.ReturnType, rtype);
            }
            else
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
            }
        }
Example #10
0
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            ASTList astList = this.operand;

            for (int i = 0; i < astList.count; i++)
            {
                astList[i].TranslateToILInitializer(il);
            }
        }
Example #11
0
        internal override void TranslateToILInitializer(ILGenerator il)
        {
            ASTList operand = this.operand;

            for (int i = 0; i < operand.count; i++)
            {
                operand[i].TranslateToILInitializer(il);
            }
        }
 internal ConstructorCall(Context context, ASTList arguments, bool isSuperConstructorCall)
   : base(context) {
   this.isOK = false;
   this.isSuperConstructorCall = isSuperConstructorCall;
   if (arguments == null)
     this.arguments = new ASTList(context);
   else
     this.arguments = arguments;
 }
 internal ObjectLiteral(Context context, ASTList propertyList)
   : base(context) {
   int n = propertyList.count;
   this.keys = new AST[n];
   this.values = new AST[n];
   for (int i = 0; i < n; i++){
     ASTList pair = (ASTList)propertyList[i];
     this.keys[i] = pair[0];
     this.values[i] = pair[1];
   }
 }
 internal override Object ResolveCustomAttribute(ASTList args, IReflect[] argIRs, AST target)
 {
     this.name = this.name + "Attribute";
     this.BindName(null);
     if (this.members == null || this.members.Length == 0)
     {
         this.name = this.name.Substring(0, this.name.Length - 9);
         this.BindName(null);
     }
     return(base.ResolveCustomAttribute(args, argIRs, target));
 }
 internal ObjectLiteral(Context context, ASTList propertyList) : base(context)
 {
     int count = propertyList.count;
     this.keys = new AST[count];
     this.values = new AST[count];
     for (int i = 0; i < count; i++)
     {
         ASTList list = (ASTList) propertyList[i];
         this.keys[i] = list[0];
         this.values[i] = list[1];
     }
 }
        internal ObjectLiteral(Context context, ASTList propertyList) : base(context)
        {
            int count = propertyList.count;

            this.keys   = new AST[count];
            this.values = new AST[count];
            for (int i = 0; i < count; i++)
            {
                ASTList list = (ASTList)propertyList[i];
                this.keys[i]   = list[0];
                this.values[i] = list[1];
            }
        }
 internal CustomAttribute(Context context, AST func, ASTList args)
   : base(context) {
   this.ctor = func;
   this.args = args;
   this.target = null;
   this.type = null;
   this.positionalArgValues = new ArrayList();
   this.namedArgFields = new ArrayList();
   this.namedArgFieldValues = new ArrayList();
   this.namedArgProperties = new ArrayList();
   this.namedArgPropertyValues = new ArrayList();
   this.raiseToPropertyLevel = false;
 }
Example #18
0
 internal ConstructorCall(Context context, ASTList arguments, bool isSuperConstructorCall) : base(context)
 {
     this.isOK = false;
     this.isSuperConstructorCall = isSuperConstructorCall;
     if (arguments == null)
     {
         this.arguments = new ASTList(context);
     }
     else
     {
         this.arguments = arguments;
     }
 }
Example #19
0
 internal Switch(Context context, AST expression, ASTList cases)
   : base(context) {
   this.expression = expression;
   this.cases = cases;
   this.default_case = -1;
   for (int i = 0, n = this.cases.count; i < n; i++){
     if (((SwitchCase)(this.cases[i])).IsDefault()){
       this.default_case = i;
       break;
     }
   }
   this.completion = new Completion();
 }
 internal CustomAttribute(Context context, AST func, ASTList args) : base(context)
 {
     this.ctor   = func;
     this.args   = args;
     this.target = null;
     this.type   = null;
     this.positionalArgValues    = new ArrayList();
     this.namedArgFields         = new ArrayList();
     this.namedArgFieldValues    = new ArrayList();
     this.namedArgProperties     = new ArrayList();
     this.namedArgPropertyValues = new ArrayList();
     this.raiseToPropertyLevel   = false;
 }
Example #21
0
        internal ObjectLiteral(Context context, ASTList propertyList)
            : base(context)
        {
            int n = propertyList.count;

            this.keys   = new AST[n];
            this.values = new AST[n];
            for (int i = 0; i < n; i++)
            {
                ASTList pair = (ASTList)propertyList[i];
                this.keys[i]   = pair[0];
                this.values[i] = pair[1];
            }
        }
 internal Switch(Context context, AST expression, ASTList cases)
     : base(context)
 {
     this.expression   = expression;
     this.cases        = cases;
     this.default_case = -1;
     for (int i = 0, n = this.cases.count; i < n; i++)
     {
         if (((SwitchCase)(this.cases[i])).IsDefault())
         {
             this.default_case = i;
             break;
         }
     }
     this.completion = new Completion();
 }
Example #23
0
 internal Package(String name, AST id, ASTList classList, Context context)
   : base(context){
   this.name = name;
   this.classList = classList;
   this.scope = (PackageScope)Globals.ScopeStack.Peek();
   this.scope.owner = this;
   this.Engine.AddPackage(this.scope);
   Lookup simpleId = id as Lookup;
   if (simpleId != null)
     simpleId.EvaluateAsWrappedNamespace(true);
   else{
     Member qualifiedId = id as Member;
     if (qualifiedId != null)
       qualifiedId.EvaluateAsWrappedNamespace(true);
   }
 }
Example #24
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            if (this.isFullyResolved)
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
                return;
            }
            //Need to do a dynamic lookup to see if there is a dynamically introduced (by eval or with) hiding definition.
            Label lateBoundCall = il.DefineLabel();
            Label done          = il.DefineLabel();

            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
            il.Emit(OpCodes.Castclass, Typeob.IActivationObject);
            il.Emit(OpCodes.Ldstr, this.name);
            ConstantWrapper.TranslateToILInt(il, this.lexLevel);
            il.Emit(OpCodes.Callvirt, CompilerGlobals.getMemberValueMethod);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Call, CompilerGlobals.isMissingMethod);
            il.Emit(OpCodes.Brfalse, lateBoundCall); //dynamic lookup succeeded, do not call early bound method
            il.Emit(OpCodes.Pop);                    //The dynamic lookup returned Missing.Value, discard it and go on to use the value from the early bound location.
            base.TranslateToILCall(il, Typeob.Object, argList, construct, brackets);
            il.Emit(OpCodes.Br, done);               //Skip over the latebound call sequence
            il.MarkLabel(lateBoundCall);
            this.TranslateToILDefaultThisObject(il);
            argList.TranslateToIL(il, Typeob.ArrayOfObject);
            if (construct)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (brackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValue2Method);
            il.MarkLabel(done);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
 {
     if (base.isFullyResolved)
     {
         base.TranslateToILCall(il, rtype, argList, construct, brackets);
     }
     else
     {
         Label label  = il.DefineLabel();
         Label label2 = il.DefineLabel();
         base.EmitILToLoadEngine(il);
         il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
         il.Emit(OpCodes.Castclass, Typeob.IActivationObject);
         il.Emit(OpCodes.Ldstr, base.name);
         ConstantWrapper.TranslateToILInt(il, this.lexLevel);
         il.Emit(OpCodes.Callvirt, CompilerGlobals.getMemberValueMethod);
         il.Emit(OpCodes.Dup);
         il.Emit(OpCodes.Call, CompilerGlobals.isMissingMethod);
         il.Emit(OpCodes.Brfalse, label);
         il.Emit(OpCodes.Pop);
         base.TranslateToILCall(il, Typeob.Object, argList, construct, brackets);
         il.Emit(OpCodes.Br, label2);
         il.MarkLabel(label);
         this.TranslateToILDefaultThisObject(il);
         argList.TranslateToIL(il, Typeob.ArrayOfObject);
         if (construct)
         {
             il.Emit(OpCodes.Ldc_I4_1);
         }
         else
         {
             il.Emit(OpCodes.Ldc_I4_0);
         }
         if (brackets)
         {
             il.Emit(OpCodes.Ldc_I4_1);
         }
         else
         {
             il.Emit(OpCodes.Ldc_I4_0);
         }
         base.EmitILToLoadEngine(il);
         il.Emit(OpCodes.Call, CompilerGlobals.callValue2Method);
         il.MarkLabel(label2);
         Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
     }
 }
        internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets)
        {
            string str;

            if (constructor || !brackets)
            {
                if (this.isSuper)
                {
                    base.context.HandleError(JSError.IllegalUseOfSuper);
                    return;
                }
                base.context.HandleError(JSError.IllegalUseOfThis);
                return;
            }
            IReflect reflect = this.InferType(null);
            Type     t       = (reflect is Type) ? ((Type)reflect) : null;

            if (reflect is ClassScope)
            {
                t = ((ClassScope)reflect).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if ((defaultMembers != null) && (defaultMembers.Length > 0))
            {
                try
                {
                    this.method = JSBinder.SelectMethod(defaultMembers, argIRs);
                    if (this.method == null)
                    {
                        goto Label_00C5;
                    }
                    if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, base.context, 0, false, true))
                    {
                        this.method = null;
                    }
                }
                catch (AmbiguousMatchException)
                {
                    base.context.HandleError(JSError.AmbiguousMatch);
                }
                return;
            }
Label_00C5:
            str = (reflect is ClassScope) ? ((ClassScope)reflect).GetName() : ((Type)reflect).Name;
            base.context.HandleError(JSError.NotIndexable, str);
        }
Example #27
0
        internal override void TranslateToILPreSet(ILGenerator il, ASTList argList)
        {
            MethodInfo meth = this.method;

            if (meth != null)
            {
                Type t = meth.ReflectedType;
                if (!meth.IsStatic)
                {
                    this.TranslateToIL(il, t);
                }
                Binding.PlaceArgumentsOnStack(il, meth.GetParameters(), argList, 0, 1, Binding.ReflectionMissingCW);
            }
            else
            {
                base.TranslateToILPreSet(il, argList);
            }
        }
 internal Switch(Context context, AST expression, ASTList cases) : base(context)
 {
     this.expression = expression;
     this.cases = cases;
     this.default_case = -1;
     int num = 0;
     int count = this.cases.count;
     while (num < count)
     {
         if (((SwitchCase) this.cases[num]).IsDefault())
         {
             this.default_case = num;
             break;
         }
         num++;
     }
     this.completion = new Completion();
 }
        internal Switch(Context context, AST expression, ASTList cases) : base(context)
        {
            this.expression   = expression;
            this.cases        = cases;
            this.default_case = -1;
            int num   = 0;
            int count = this.cases.count;

            while (num < count)
            {
                if (((SwitchCase)this.cases[num]).IsDefault())
                {
                    this.default_case = num;
                    break;
                }
                num++;
            }
            this.completion = new Completion();
        }
Example #30
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (this.context.document.debugOn)
            {
                il.Emit(OpCodes.Nop);
            }
            ASTList astList = this.operand;
            int     n       = astList.count;

            for (int i = 0; i < n; i++)
            {
                AST      ast = astList[i];
                IReflect ir  = ast.InferType(null);
                if (ir == Typeob.String)
                {
                    ast.TranslateToIL(il, Typeob.String);
                }
                else
                {
                    ast.TranslateToIL(il, Typeob.Object);
                    ConstantWrapper.TranslateToILInt(il, 1);
                    il.Emit(OpCodes.Call, CompilerGlobals.toStringMethod);
                }
                if (i == n - 1)
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
                }
                else
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeMethod);
                }
            }
            if (n == 0)
            {
                il.Emit(OpCodes.Ldstr, "");
                il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
            }
            if (rtype != Typeob.Void)
            {
                il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
                Convert.Emit(this, il, Typeob.Object, rtype);
            }
        }
Example #31
0
        internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets)
        {
            if (constructor || !brackets)
            {
                if (this.isSuper)
                {
                    this.context.HandleError(JSError.IllegalUseOfSuper);
                }
                else
                {
                    this.context.HandleError(JSError.IllegalUseOfThis);
                }
                return;
            }
            IReflect ir = this.InferType(null);
            Type     t  = ir is Type ? (Type)ir : null;

            if (ir is ClassScope)
            {
                t = ((ClassScope)ir).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if (defaultMembers != null && defaultMembers.Length > 0)
            {
                try{
                    this.method = JSBinder.SelectMethod(defaultMembers, argIRs); //Returns property getters as well
                    if (this.method != null)
                    {
                        if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, this.context, 0, false, true))
                        {
                            this.method = null;
                        }
                        return;
                    }
                }catch (AmbiguousMatchException) {
                    this.context.HandleError(JSError.AmbiguousMatch);
                    return;
                }
            }
            String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name;

            this.context.HandleError(JSError.NotIndexable, tname);
        }
Example #32
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            if (base.context.document.debugOn)
            {
                il.Emit(OpCodes.Nop);
            }
            ASTList operand = this.operand;
            int     count   = operand.count;

            for (int i = 0; i < count; i++)
            {
                AST ast = operand[i];
                if (ast.InferType(null) == Typeob.String)
                {
                    ast.TranslateToIL(il, Typeob.String);
                }
                else
                {
                    ast.TranslateToIL(il, Typeob.Object);
                    ConstantWrapper.TranslateToILInt(il, 1);
                    il.Emit(OpCodes.Call, CompilerGlobals.toStringMethod);
                }
                if (i == (count - 1))
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
                }
                else
                {
                    il.Emit(OpCodes.Call, CompilerGlobals.writeMethod);
                }
            }
            if (count == 0)
            {
                il.Emit(OpCodes.Ldstr, "");
                il.Emit(OpCodes.Call, CompilerGlobals.writeLineMethod);
            }
            if (rtype != Typeob.Void)
            {
                il.Emit(OpCodes.Ldsfld, CompilerGlobals.undefinedField);
                Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
            }
        }
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
 {
     if (((base.defaultMember != null) && construct) && brackets)
     {
         base.TranslateToILCall(il, rtype, argList, construct, brackets);
     }
     else
     {
         JSGlobalField member = base.member as JSGlobalField;
         if (((member != null) && member.IsLiteral) && (argList.count == 1))
         {
             Type type = Microsoft.JScript.Convert.ToType((IReflect)member.value);
             argList[0].TranslateToIL(il, type);
             Microsoft.JScript.Convert.Emit(this, il, type, rtype);
         }
         else
         {
             this.TranslateToILWithDupOfThisOb(il);
             argList.TranslateToIL(il, Typeob.ArrayOfObject);
             if (construct)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             if (brackets)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
         }
     }
 }
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
 {
     if (((base.defaultMember != null) && construct) && brackets)
     {
         base.TranslateToILCall(il, rtype, argList, construct, brackets);
     }
     else
     {
         JSGlobalField member = base.member as JSGlobalField;
         if (((member != null) && member.IsLiteral) && (argList.count == 1))
         {
             Type type = Microsoft.JScript.Convert.ToType((IReflect) member.value);
             argList[0].TranslateToIL(il, type);
             Microsoft.JScript.Convert.Emit(this, il, type, rtype);
         }
         else
         {
             this.TranslateToILWithDupOfThisOb(il);
             argList.TranslateToIL(il, Typeob.ArrayOfObject);
             if (construct)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             if (brackets)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, rtype);
         }
     }
 }
 internal Package(string name, AST id, ASTList classList, Context context) : base(context)
 {
     this.name = name;
     this.classList = classList;
     this.scope = (PackageScope) base.Globals.ScopeStack.Peek();
     this.scope.owner = this;
     base.Engine.AddPackage(this.scope);
     Lookup lookup = id as Lookup;
     if (lookup != null)
     {
         lookup.EvaluateAsWrappedNamespace(true);
     }
     else
     {
         Member member = id as Member;
         if (member != null)
         {
             member.EvaluateAsWrappedNamespace(true);
         }
     }
 }
        internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue)
        {
            string   str;
            IReflect reflect = this.InferType(null);
            Type     t       = (reflect is Type) ? ((Type)reflect) : null;

            if (reflect is ClassScope)
            {
                t = ((ClassScope)reflect).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if ((defaultMembers != null) && (defaultMembers.Length > 0))
            {
                try
                {
                    PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs);
                    if (prop == null)
                    {
                        goto Label_00B1;
                    }
                    this.method = JSProperty.GetSetMethod(prop, true);
                    if (this.method == null)
                    {
                        base.context.HandleError(JSError.AssignmentToReadOnly, true);
                    }
                    if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, base.context, 0, false, true))
                    {
                        this.method = null;
                    }
                }
                catch (AmbiguousMatchException)
                {
                    base.context.HandleError(JSError.AmbiguousMatch);
                }
                return;
            }
Label_00B1:
            str = (reflect is ClassScope) ? ((ClassScope)reflect).GetName() : ((Type)reflect).Name;
            base.context.HandleError(JSError.NotIndexable, str);
        }
Example #37
0
        internal Package(string name, AST id, ASTList classList, Context context) : base(context)
        {
            this.name        = name;
            this.classList   = classList;
            this.scope       = (PackageScope)base.Globals.ScopeStack.Peek();
            this.scope.owner = this;
            base.Engine.AddPackage(this.scope);
            Lookup lookup = id as Lookup;

            if (lookup != null)
            {
                lookup.EvaluateAsWrappedNamespace(true);
            }
            else
            {
                Member member = id as Member;
                if (member != null)
                {
                    member.EvaluateAsWrappedNamespace(true);
                }
            }
        }
Example #38
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;
 }
Example #39
0
        internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
        {
            if (this.defaultMember != null && construct && brackets)
            {
                base.TranslateToILCall(il, rtype, argList, construct, brackets);
                return;
            }
            JSGlobalField gf = this.member as JSGlobalField;

            if (gf != null && gf.IsLiteral && argList.count == 1)
            {
                Type t = Convert.ToType((IReflect)gf.value);
                argList[0].TranslateToIL(il, t);
                Convert.Emit(this, il, t, rtype);
                return;
            }
            this.TranslateToILWithDupOfThisOb(il);
            argList.TranslateToIL(il, typeof(Object[]));
            if (construct)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            if (brackets)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
            Convert.Emit(this, il, Typeob.Object, rtype);
        }
Example #40
0
        internal Package(String name, AST id, ASTList classList, Context context)
            : base(context)
        {
            this.name        = name;
            this.classList   = classList;
            this.scope       = (PackageScope)Globals.ScopeStack.Peek();
            this.scope.owner = this;
            this.Engine.AddPackage(this.scope);
            Lookup simpleId = id as Lookup;

            if (simpleId != null)
            {
                simpleId.EvaluateAsWrappedNamespace(true);
            }
            else
            {
                Member qualifiedId = id as Member;
                if (qualifiedId != null)
                {
                    qualifiedId.EvaluateAsWrappedNamespace(true);
                }
            }
        }
Example #41
0
        internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue)
        {
            IReflect ir = this.InferType(null);
            Type     t  = ir is Type ? (Type)ir : null;

            if (ir is ClassScope)
            {
                t = ((ClassScope)ir).GetBakedSuperType();
            }
            MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
            if (defaultMembers != null && defaultMembers.Length > 0)
            {
                try{
                    PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs); //Returns property getters as well
                    if (prop != null)
                    {
                        this.method = JSProperty.GetSetMethod(prop, true);
                        if (this.method == null)
                        {
                            this.context.HandleError(JSError.AssignmentToReadOnly, true);
                        }
                        if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, this.context, 0, false, true))
                        {
                            this.method = null;
                        }
                        return;
                    }
                }catch (AmbiguousMatchException) {
                    this.context.HandleError(JSError.AmbiguousMatch);
                    return;
                }
            }
            String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name;

            this.context.HandleError(JSError.NotIndexable, tname);
        }
Example #42
0
 public ArrayLiteral(Context context, ASTList elements)
   : base(context) {
   this.elements = elements;
 }
 internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets)
 {
     string str;
     if (constructor || !brackets)
     {
         if (this.isSuper)
         {
             base.context.HandleError(JSError.IllegalUseOfSuper);
             return;
         }
         base.context.HandleError(JSError.IllegalUseOfThis);
         return;
     }
     IReflect reflect = this.InferType(null);
     Type t = (reflect is Type) ? ((Type) reflect) : null;
     if (reflect is ClassScope)
     {
         t = ((ClassScope) reflect).GetBakedSuperType();
     }
     MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
     if ((defaultMembers != null) && (defaultMembers.Length > 0))
     {
         try
         {
             this.method = JSBinder.SelectMethod(defaultMembers, argIRs);
             if (this.method == null)
             {
                 goto Label_00C5;
             }
             if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, base.context, 0, false, true))
             {
                 this.method = null;
             }
         }
         catch (AmbiguousMatchException)
         {
             base.context.HandleError(JSError.AmbiguousMatch);
         }
         return;
     }
 Label_00C5:
     str = (reflect is ClassScope) ? ((ClassScope) reflect).GetName() : ((Type) reflect).Name;
     base.context.HandleError(JSError.NotIndexable, str);
 }
    internal override AST PartiallyEvaluate(){
      this.ctor = this.ctor.PartiallyEvaluateAsCallable();

      //first weed out assignment expressions and use them as property initializers
      ASTList positionalArgs = new ASTList(this.args.context);
      ASTList namedArgs = new ASTList(this.args.context);
      for (int i = 0, m = this.args.count; i < m; i++){
        AST arg = this.args[i];
        Assign assign = arg as Assign;
        if (assign != null){
          assign.rhside = assign.rhside.PartiallyEvaluate();
          namedArgs.Append(assign);
        }else
          positionalArgs.Append(arg.PartiallyEvaluate());                    
      }

      int n = positionalArgs.count;
      IReflect[] argIRs = new IReflect[n];
      for (int i = 0; i < n; i++){
        AST arg = positionalArgs[i];
        // only accept ConstantWrappers
        if (arg is ConstantWrapper){
          Object argument = arg.Evaluate();
          if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null){
            this.positionalArgValues.Add(argument);
            continue;
          }
        }else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute()){
          argIRs[i] = Typeob.ArrayObject;
          this.positionalArgValues.Add(arg.Evaluate());
          continue;
        }
        arg.context.HandleError(JSError.InvalidCustomAttributeArgument);
        return null; // the custom attribute is not good and it will be ignored
      }

      //Get the custom attribute and the appropriate constructor (under the covers)
      this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target);
      if (this.type == null) return null;
      if (Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute)){
        this.context.HandleError(JSError.CannotUseStaticSecurityAttribute);
        return null;
      }
      

      //Coerce the positional arguments to the right type and supply default values for optional parameters
      ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member;
      ParameterInfo[] parameters = c.GetParameters();
      int j = 0;
      int len = this.positionalArgValues.Count;
      foreach (ParameterInfo p in parameters){
        IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType;
        if (j < len ){
          Object value = this.positionalArgValues[j];
          this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject);
          j++;
        }else{
          Object value;
          if (TypeReferences.GetDefaultParameterValue(p) == System.Convert.DBNull){
            value = Convert.Coerce(null, ir);
          }else
            value = TypeReferences.GetDefaultParameterValue(p);
          this.positionalArgValues.Add(value);
        }
      }
     
      //Check validity of property/field initializers
      for (int i = 0, m = namedArgs.count; i < m; i++){
        Assign assign = (Assign)namedArgs[i];
        if (assign.lhside is Lookup && 
            (assign.rhside is ConstantWrapper ||
             (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute()))){
          Object value = assign.rhside.Evaluate();
          IReflect argType = null;
          if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object)){
            String name = ((Lookup)assign.lhside).Name;
            MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public|BindingFlags.Instance);
            if (members == null || members.Length == 0){
              assign.context.HandleError(JSError.NoSuchMember);
              return null;
            } 
            if (members.Length == 1){
              MemberInfo member = members[0];
              if (member is FieldInfo){
                FieldInfo fieldInfo = (FieldInfo)member;
                if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly){
                  try{
                    IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType;
                    value = Convert.Coerce(value, ir, value is ArrayObject);
                    this.namedArgFields.Add(member);
                    this.namedArgFieldValues.Add(value);
                    continue;
                  }catch(JScriptException){
                    assign.rhside.context.HandleError(JSError.TypeMismatch);
                    return null; // the custom attribute is not good and it will be ignored
                  }
                }
              }else if (member is PropertyInfo){
                PropertyInfo propertyInfo = (PropertyInfo)member;
                MethodInfo setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false);
                if (setMethodInfo != null){
                  ParameterInfo [] paramInfo = setMethodInfo.GetParameters();
                  if (paramInfo != null && paramInfo.Length == 1){
                    try{
                      IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType;
                      value = Convert.Coerce(value, ir, value is ArrayObject);
                      this.namedArgProperties.Add(member);
                      this.namedArgPropertyValues.Add(value);
                    }catch(JScriptException){
                      assign.rhside.context.HandleError(JSError.TypeMismatch);
                      return null; // the custom attribute is not good and it will be ignored
                    }
                    continue;
                  }
                }
              }
            }
          }
        }
        assign.context.HandleError(JSError.InvalidCustomAttributeArgument);
        return null;
      }

      if (!this.CheckIfTargetOK(this.type))
        return null; //Ignore attribute

      //Consume and discard assembly name attributes
      try{
        Type ty = this.type as Type;
        if (ty != null && this.target is AssemblyCustomAttributeList){
          if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute"){
            if (this.positionalArgValues.Count > 0)
              this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyCultureAttribute"){
            if (this.positionalArgValues.Count > 0){
              String cultureId = Convert.ToString(this.positionalArgValues[0]);
              if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0){
                this.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                return null;
              }
              this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId);
            }
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute"){
            if (this.positionalArgValues.Count > 0)
              this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false);
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute"){
            if (this.positionalArgValues.Count > 0)
              this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint));
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute"){
            if (this.positionalArgValues.Count > 0){
              this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]);
              this.Engine.Globals.assemblyKeyFileNameContext = this.context;
              if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0)
              {
                this.Engine.Globals.assemblyKeyFileName = null;
                this.Engine.Globals.assemblyKeyFileNameContext = null;
              }
            }
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute"){
            if (this.positionalArgValues.Count > 0){
              this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]);
              this.Engine.Globals.assemblyKeyNameContext = this.context;
              if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0) {
                this.Engine.Globals.assemblyKeyName = null;
                this.Engine.Globals.assemblyKeyNameContext = null;
              }
            }
            return null;
          }
          if (ty.FullName == "System.Reflection.AssemblyVersionAttribute"){
            if (this.positionalArgValues.Count > 0)
              this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0]));
            return null;
          }
          if (ty.FullName == "System.CLSCompliantAttribute"){
            this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false);
            return this;
          }
        }
      }catch(ArgumentException){
        this.context.HandleError(JSError.InvalidCall);
      }

      return this;
    }
Example #45
0
 internal override Object ResolveCustomAttribute(ASTList args, IReflect[] argIRs, AST target){
   this.name = this.name + "Attribute";
   this.BindName(null);
   if (this.members == null || this.members.Length == 0){
     this.name = this.name.Substring(0, this.name.Length-9);
     this.BindName(null);
   }
   return base.ResolveCustomAttribute(args, argIRs, target);
 }
 internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue)
 {
     string str;
     IReflect reflect = this.InferType(null);
     Type t = (reflect is Type) ? ((Type) reflect) : null;
     if (reflect is ClassScope)
     {
         t = ((ClassScope) reflect).GetBakedSuperType();
     }
     MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
     if ((defaultMembers != null) && (defaultMembers.Length > 0))
     {
         try
         {
             PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs);
             if (prop == null)
             {
                 goto Label_00B1;
             }
             this.method = JSProperty.GetSetMethod(prop, true);
             if (this.method == null)
             {
                 base.context.HandleError(JSError.AssignmentToReadOnly, true);
             }
             if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, base.context, 0, false, true))
             {
                 this.method = null;
             }
         }
         catch (AmbiguousMatchException)
         {
             base.context.HandleError(JSError.AmbiguousMatch);
         }
         return;
     }
 Label_00B1:
     str = (reflect is ClassScope) ? ((ClassScope) reflect).GetName() : ((Type) reflect).Name;
     base.context.HandleError(JSError.NotIndexable, str);
 }
Example #47
0
 internal override void ResolveCall(ASTList args, IReflect[] argIRs, bool constructor, bool brackets){
   if (constructor || !brackets){
     if (this.isSuper)
       this.context.HandleError(JSError.IllegalUseOfSuper);
     else
       this.context.HandleError(JSError.IllegalUseOfThis);
     return;
   }
   IReflect ir = this.InferType(null);
   Type t = ir is Type ? (Type)ir : null;
   if (ir is ClassScope) t = ((ClassScope)ir).GetBakedSuperType();
   MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
   if (defaultMembers != null && defaultMembers.Length > 0){
     try{
       this.method = JSBinder.SelectMethod(defaultMembers, argIRs); //Returns property getters as well
       if (this.method != null){
         if (!Binding.CheckParameters(this.method.GetParameters(), argIRs, args, this.context, 0, false, true))
           this.method = null;
         return;
       }
     }catch(AmbiguousMatchException){
       this.context.HandleError(JSError.AmbiguousMatch);
       return;
     }
   }
   String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name;
   this.context.HandleError(JSError.NotIndexable, tname);
 }
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets)
 {
     MethodInfo method = this.method;
     if (method != null)
     {
         Type reflectedType = method.ReflectedType;
         if (!method.IsStatic)
         {
             this.method = null;
             this.TranslateToIL(il, reflectedType);
             this.method = method;
         }
         ParameterInfo[] parameters = method.GetParameters();
         Binding.PlaceArgumentsOnStack(il, parameters, argList, 0, 0, Binding.ReflectionMissingCW);
         if ((method.IsVirtual && !method.IsFinal) && (!reflectedType.IsSealed || !reflectedType.IsValueType))
         {
             il.Emit(OpCodes.Callvirt, method);
         }
         else
         {
             il.Emit(OpCodes.Call, method);
         }
         Microsoft.JScript.Convert.Emit(this, il, method.ReturnType, rtype);
     }
     else
     {
         base.TranslateToILCall(il, rtype, argList, construct, brackets);
     }
 }
 internal override void TranslateToILPreSet(ILGenerator il, ASTList argList)
 {
     MethodInfo method = this.method;
     if (method != null)
     {
         Type reflectedType = method.ReflectedType;
         if (!method.IsStatic)
         {
             this.TranslateToIL(il, reflectedType);
         }
         Binding.PlaceArgumentsOnStack(il, method.GetParameters(), argList, 0, 1, Binding.ReflectionMissingCW);
     }
     else
     {
         base.TranslateToILPreSet(il, argList);
     }
 }
Example #50
0
 internal virtual void TranslateToILPreSet(ILGenerator il, ASTList args)
 {
     this.TranslateToIL(il, Typeob.Object);
     args.TranslateToIL(il, typeof(Object[]));
 }
 internal Print(Context context, AST operand) : base(context)
 {
     this.operand = (ASTList) operand;
     this.completion = new Completion();
 }
 internal override AST PartiallyEvaluate()
 {
     this.operand = (ASTList) this.operand.PartiallyEvaluate();
     return this;
 }
Example #53
0
 internal void EmitInitialCalls(ILGenerator il, MethodBase supcons, ParameterInfo[] pars, ASTList argAST, int callerParameterCount){
   bool callFieldInitializer = true;
   if (supcons != null){
     il.Emit(OpCodes.Ldarg_0);
     int n = pars.Length;
     int m = argAST == null ? 0 : argAST.count;
     Object[] tempArray = new Object[n];
     for (int i = 0; i < n; i++){
       AST actual = i < m ? argAST[i] : new ConstantWrapper(null, null);
       if (pars[i].ParameterType.IsByRef)
         tempArray[i] = actual.TranslateToILReference(il, pars[i].ParameterType.GetElementType());
       else{
         actual.TranslateToIL(il, pars[i].ParameterType);
         tempArray[i] = null;
       }
     }
     if (supcons is JSConstructor){
       JSConstructor cons = (JSConstructor)supcons;
       callFieldInitializer = cons.GetClassScope() != this.classob;
       supcons = cons.GetConstructorInfo(this.compilerGlobals);
       //if cons belongs to a nested instance class, load the outer class instance on the stack
       if (cons.GetClassScope().outerClassField != null)
         Convert.EmitLdarg(il, (short)callerParameterCount);
     }
     il.Emit(OpCodes.Call, (ConstructorInfo)supcons);
     for (int i = 0; i < m; i++){
       AST arg = argAST[i];
       if (arg is AddressOf && tempArray[i] != null){
         Type argType = Convert.ToType(arg.InferType(null));
         arg.TranslateToILPreSet(il);
         il.Emit(OpCodes.Ldloc, (LocalBuilder)tempArray[i]);
         Convert.Emit(this, il, pars[i].ParameterType, argType);
         arg.TranslateToILSet(il);
       }
     }
   }
   if (this.classob.outerClassField != null){
     il.Emit(OpCodes.Ldarg_0);
     Convert.EmitLdarg(il, (short)callerParameterCount);
     il.Emit(OpCodes.Stfld, this.classob.outerClassField);
   }
   if (callFieldInitializer){
     il.Emit(OpCodes.Ldarg_0);
     il.Emit(OpCodes.Call, this.fieldInitializer);
     ((Block)(this.body)).TranslateToILInitOnlyInitializers(il);
   }
 }
Example #54
0
        AST PrimaryExpr(AST parent)
        {
            int tt;
            AST pn;

            ts.allow_reg_exp = true;
            tt = ts.GetToken ();
            ts.allow_reg_exp = false;

            if (tt == Token.FUNCTION) {
                return Function (parent, FunctionType.Expression);
            } else if (tt == Token.LB) {
                ASTList elems = new ASTList (parent, new Location (ts.SourceName, ts.LineNumber));
                int skip_count = 0;
                decompiler.AddToken (Token.LB);
                bool after_lb_or_comma = true;
                for (;;) {
                    ts.allow_reg_exp = true;
                    tt = ts.PeekToken ();
                    ts.allow_reg_exp = false;

                    if (tt == Token.COMMA) {
                        ts.GetToken ();
                        decompiler.AddToken (Token.COMMA);
                        if (!after_lb_or_comma)
                            after_lb_or_comma = true;
                        else {
                            elems.Add (null);
                            ++skip_count;
                        }
                    } else if (tt == Token.RB) {
                        ts.GetToken ();
                        decompiler.AddToken (Token.RB);
                        break;
                    } else {
                        if (!after_lb_or_comma)
                            ReportError ("msg.no.bracket.arg");
                        elems.Add (AssignExpr (parent, false));
                        after_lb_or_comma = false;
                    }
                }
                // FIXME: pass a real Context
                return new ArrayLiteral (null, elems, skip_count, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.LC) {
                Location location = new Location (ts.SourceName, ts.LineNumber);
                ArrayList elems = new ArrayList ();
                decompiler.AddToken (Token.LC);

                if (!ts.MatchToken (Token.RC)) {
                    bool first = true;

                    commaloop: {
                    do {
                        ObjectLiteralItem property;

                        if (!first)
                            decompiler.AddToken (Token.COMMA);
                        else
                            first = false;

                        tt = ts.GetToken ();

                        if (tt == Token.NAME || tt == Token.STRING) {
                            string s = ts.GetString;
                            if (tt == Token.NAME)
                                decompiler.AddName (s);
                            else
                                decompiler.AddString (s);
                            property = new ObjectLiteralItem (s);
                        } else if (tt == Token.NUMBER) {
                            double n = ts.GetNumber;
                            decompiler.AddNumber (n);
                            property = new ObjectLiteralItem (n);
                        } else if (tt == Token.RC) {
                            // trailing comma is OK
                            ts.UnGetToken (tt);
                            goto leave_commaloop;
                        } else {
                            ReportError ("msg.bad.prop");
                            goto leave_commaloop;
                        }
                        MustMatchToken (Token.COLON, "msg.no.colon.prop");
                        // OBJLIT is used as ':' in object literal for
                        // decompilation to solve spacing ambiguity.
                        decompiler.AddToken (Token.OBJECTLIT);
                        property.exp = AssignExpr (parent, false);
                        elems.Add (property);
                    } while (ts.MatchToken (Token.COMMA));
                    MustMatchToken (Token.RC, "msg.no.brace.prop");
                    }
                    leave_commaloop:
                    ;
                }
                return new ObjectLiteral (elems, location);
            } else if (tt == Token.LP) {
                decompiler.AddToken (Token.LP);
                pn = Expr (parent, false);
                decompiler.AddToken (Token.RP);
                MustMatchToken (Token.RP, "msg.no.paren");
                decompiler.AddToken (Token.RP);
                return pn;
            } else if (tt == Token.NAME) {
                string name = ts.GetString;
                decompiler.AddName (name);
                return new Identifier (parent, name, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.NUMBER) {
                double n = ts.GetNumber;
                decompiler.AddNumber (n);

                Location location = new Location (ts.SourceName, ts.LineNumber);

                if (HasNoDecimals (n)) {
                    if (InRangeOf (n, Byte.MinValue, Byte.MaxValue))
                        return new ByteConstant (parent, (byte) n, location);
                    else if (InRangeOf (n, Int16.MinValue, Int16.MaxValue))
                        return new ShortConstant (parent, (short) n, location);
                    else if (InRangeOf (n, Int32.MinValue, Int32.MaxValue))
                        return new IntConstant (parent, (int) n, location);
                    else if (InRangeOf (n, Int64.MinValue, Int64.MaxValue))
                        return new LongConstant (parent, (long) n, location);
                    else
                        return new DoubleConstant (parent, n, location);
                } else {
                    if (InRangeOf (n, Single.MinValue, Single.MaxValue))
                        return new FloatConstant (parent, (float) n, location);
                    else if (InRangeOf (n, Double.MinValue, Double.MaxValue))
                        return new DoubleConstant (parent, n, location);
                    else
                        return new DoubleConstant (parent, n, location);
                }
            } else if (tt == Token.STRING) {
                string s = ts.GetString;
                decompiler.AddString (s);
                return new StringLiteral (null, s, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.REGEXP) {
                string flags = ts.reg_exp_flags;
                ts.reg_exp_flags = null;
                string re = ts.GetString;
                decompiler.AddRegexp (re, flags);
                return new RegExpLiteral (parent, re, flags, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.NULL) {
                decompiler.AddToken (tt);
                // FIXME, build the null object;
                return null;
            } else if (tt ==  Token.THIS) {
                decompiler.AddToken (tt);
                return new This (parent, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.FALSE || tt == Token.TRUE) {
                decompiler.AddToken (tt);
                bool v;
                if (tt == Token.FALSE)
                    v = false;
                else
                    v = true;
                return new BooleanConstant (null, v, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.RESERVED) {
                ReportError ("msg.reserved.id");
            } else if (tt == Token.ERROR) {
                /* the scanner or one of its subroutines reported the error. */
            } else
                ReportError ("msg.syntax");
            return null; // should never reach here
        }
Example #55
0
 internal void ResolveAssignmentToDefaultIndexedProperty(ASTList args, IReflect[] argIRs, AST rhvalue){
   IReflect ir = this.InferType(null);
   Type t = ir is Type ? (Type)ir : null;
   if (ir is ClassScope) t = ((ClassScope)ir).GetBakedSuperType();
   MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(t);
   if (defaultMembers != null && defaultMembers.Length > 0){
     try{
       PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs); //Returns property getters as well
       if (prop != null){
         this.method = JSProperty.GetSetMethod(prop, true);
         if (this.method == null)
           this.context.HandleError(JSError.AssignmentToReadOnly, true);
         if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, args, this.context, 0, false, true))
           this.method = null;
         return;
       }
     }catch(AmbiguousMatchException){
       this.context.HandleError(JSError.AmbiguousMatch);
       return;
     }
   }
   String tname = ir is ClassScope ? ((ClassScope)ir).GetName() : ((Type)ir).Name;
   this.context.HandleError(JSError.NotIndexable, tname);
 }
 internal virtual void TranslateToILPreSet(ILGenerator il, ASTList args)
 {
     this.TranslateToIL(il, Typeob.Object);
     args.TranslateToIL(il, Typeob.ArrayOfObject);
 }
Example #57
0
 internal override Object ResolveCustomAttribute(ASTList args, IReflect[] argIRs, AST target){
   if (this.name == "expando")
     this.members = Typeob.Expando.GetConstructors(BindingFlags.Instance|BindingFlags.Public);
   else if (this.name == "override")
     this.members = typeof(Microsoft.JScript.Override).GetConstructors(BindingFlags.Instance|BindingFlags.Public);
   else if (this.name == "hide")
     this.members = typeof(Microsoft.JScript.Hide).GetConstructors(BindingFlags.Instance|BindingFlags.Public);
   else if (this.name == "...")
     this.members = typeof(System.ParamArrayAttribute).GetConstructors(BindingFlags.Instance|BindingFlags.Public);
   else{
     this.name = this.name + "Attribute";
     this.BindName();
     if (this.members == null || this.members.Length == 0){
       this.name = this.name.Substring(0, this.name.Length-9);
       this.BindName();
     }
   }
   return base.ResolveCustomAttribute(args, argIRs, target);
 }
 internal virtual void TranslateToILPreSetPlusGet(ILGenerator il, ASTList args, bool inBrackets)
 {
     il.Emit(OpCodes.Ldnull);
     this.TranslateToIL(il, Typeob.Object);
     il.Emit(OpCodes.Dup);
     LocalBuilder local = il.DeclareLocal(Typeob.Object);
     il.Emit(OpCodes.Stloc, local);
     args.TranslateToIL(il, Typeob.ArrayOfObject);
     il.Emit(OpCodes.Dup);
     LocalBuilder builder2 = il.DeclareLocal(Typeob.ArrayOfObject);
     il.Emit(OpCodes.Stloc, builder2);
     il.Emit(OpCodes.Ldc_I4_0);
     if (inBrackets)
     {
         il.Emit(OpCodes.Ldc_I4_1);
     }
     else
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     this.EmitILToLoadEngine(il);
     il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
     LocalBuilder builder3 = il.DeclareLocal(Typeob.Object);
     il.Emit(OpCodes.Stloc, builder3);
     il.Emit(OpCodes.Ldloc, local);
     il.Emit(OpCodes.Ldloc, builder2);
     il.Emit(OpCodes.Ldloc, builder3);
 }
Example #59
0
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets){
   if (this.isFullyResolved){
     base.TranslateToILCall(il, rtype, argList, construct, brackets);
     return;
   }
   //Need to do a dynamic lookup to see if there is a dynamically introduced (by eval or with) hiding definition.
   Label lateBoundCall = il.DefineLabel();
   Label done = il.DefineLabel();
   this.EmitILToLoadEngine(il);
   il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
   il.Emit(OpCodes.Castclass, typeof(IActivationObject));
   il.Emit(OpCodes.Ldstr, this.name);
   ConstantWrapper.TranslateToILInt(il, this.lexLevel);
   il.Emit(OpCodes.Callvirt, CompilerGlobals.getMemberValueMethod);
   il.Emit(OpCodes.Dup);
   il.Emit(OpCodes.Call, CompilerGlobals.isMissingMethod);
   il.Emit(OpCodes.Brfalse, lateBoundCall); //dynamic lookup succeeded, do not call early bound method
   il.Emit(OpCodes.Pop); //The dynamic lookup returned Missing.Value, discard it and go on to use the value from the early bound location.
   base.TranslateToILCall(il, Typeob.Object, argList, construct, brackets);
   il.Emit(OpCodes.Br, done); //Skip over the latebound call sequence
   il.MarkLabel(lateBoundCall);
   this.TranslateToILDefaultThisObject(il);
   argList.TranslateToIL(il, typeof(Object[]));
   if (construct)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   if (brackets)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   this.EmitILToLoadEngine(il);
   il.Emit(OpCodes.Call, CompilerGlobals.callValue2Method);
   il.MarkLabel(done);
   Convert.Emit(this, il, Typeob.Object, rtype);
 }
Example #60
0
 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets){
   MethodInfo meth = this.method;
   if (meth != null){
     Type t = meth.ReflectedType;
     if (!meth.IsStatic){
       this.method = null;
       this.TranslateToIL(il, t);
       this.method = meth;
     }
     ParameterInfo[] pars = meth.GetParameters();
     Binding.PlaceArgumentsOnStack(il, pars, argList, 0, 0, Binding.ReflectionMissingCW);
     if (meth.IsVirtual && !meth.IsFinal && !t.IsSealed)
       il.Emit(OpCodes.Callvirt, meth);
     else
       il.Emit(OpCodes.Call, meth);
     Convert.Emit(this, il, meth.ReturnType, rtype);
   }else
     base.TranslateToILCall(il, rtype, argList, construct, brackets);
 }