Call() private method

private Call ( Binder binder, Object arguments, ParameterModifier modifiers, CultureInfo culture, String namedParameters, bool construct, bool brackets, VsaEngine engine ) : Object
binder Binder
arguments Object
modifiers System.Reflection.ParameterModifier
culture CultureInfo
namedParameters String
construct bool
brackets bool
engine Microsoft.JScript.Vsa.VsaEngine
return Object
 public static object CallMethod(string name, object thisob, object[] arguments, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     LateBinding binding = new LateBinding(name, thisob, true);
     return binding.Call(arguments, false, false, engine);
 }
 public static object CallStaticMethod(string name, string typename, object[] arguments, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     object type = GetType(typename);
     LateBinding binding = new LateBinding(name, type, true);
     return binding.Call(arguments, false, false, engine);
 }
        public static object CallMethod(string name, object thisob, object[] arguments, VsaEngine engine)
        {
            if (engine == null)
            {
                engine = VsaEngine.CreateEngine();
            }
            LateBinding binding = new LateBinding(name, thisob, true);

            return(binding.Call(arguments, false, false, engine));
        }
        public static object CallStaticMethod(string name, string typename, object[] arguments, VsaEngine engine)
        {
            if (engine == null)
            {
                engine = VsaEngine.CreateEngine();
            }
            object      type    = GetType(typename);
            LateBinding binding = new LateBinding(name, type, true);

            return(binding.Call(arguments, false, false, engine));
        }
Esempio n. 5
0
        internal override Object Invoke(Object obj, Object thisob, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture)
        {
            bool   construct = (options & BindingFlags.CreateInstance) != 0;
            bool   brackets  = (options & BindingFlags.GetProperty) != 0 && (options & BindingFlags.InvokeMethod) == 0;
            Object f         = this.func;

            if (f == null)
            {
                f = this.field.GetValue(this.obj);
            }
            FunctionObject func = f as FunctionObject;
            JSObject       jsOb = obj as JSObject;

            if (jsOb != null && func != null && func.isMethod && (func.attributes & MethodAttributes.Virtual) != 0 &&
                jsOb.GetParent() != func.enclosing_scope && ((ClassScope)func.enclosing_scope).HasInstance(jsOb))
            {
                LateBinding lb = new LateBinding(func.name);
                lb.obj = jsOb;
                return(lb.Call(parameters, construct, brackets, ((ScriptObject)this.obj).engine));
            }
            return(LateBinding.CallValue(f, parameters, construct, brackets, ((ScriptObject)this.obj).engine, thisob, binder, culture, null));
        }
        public static object GetDefaultIndexedPropertyValue(object thisob, object[] arguments, VsaEngine engine, string[] namedParameters)
        {
            if (engine == null)
            {
                engine = VsaEngine.CreateEngine();
            }
            object[] target = null;
            int      num    = (arguments == null) ? 0 : arguments.Length;

            if (((namedParameters != null) && (namedParameters.Length > 0)) && ((namedParameters[0] == "this") && (num > 0)))
            {
                target = new object[num - 1];
                ArrayObject.Copy(arguments, 1, target, 0, num - 1);
            }
            else
            {
                target = arguments;
            }
            LateBinding binding = new LateBinding(null, thisob, true);

            return(binding.Call(target, false, false, engine));
        }
Esempio n. 7
0
        internal override object Invoke(object obj, object thisob, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
        {
            bool   construct = (options & BindingFlags.CreateInstance) != BindingFlags.Default;
            bool   brackets  = ((options & BindingFlags.GetProperty) != BindingFlags.Default) && ((options & BindingFlags.InvokeMethod) == BindingFlags.Default);
            object func      = this.func;

            if (func == null)
            {
                func = this.field.GetValue(base.obj);
            }
            FunctionObject obj3 = func as FunctionObject;
            JSObject       ob   = obj as JSObject;

            if ((((ob != null) && (obj3 != null)) && (obj3.isMethod && ((obj3.attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope))) && ((ob.GetParent() != obj3.enclosing_scope) && ((ClassScope)obj3.enclosing_scope).HasInstance(ob)))
            {
                LateBinding binding = new LateBinding(obj3.name)
                {
                    obj = ob
                };
                return(binding.Call(parameters, construct, brackets, ((ScriptObject)base.obj).engine));
            }
            return(LateBinding.CallValue(func, parameters, construct, brackets, ((ScriptObject)base.obj).engine, thisob, binder, culture, null));
        }
Esempio n. 8
0
        internal override object Evaluate()
        {
            object obj3;

            if ((this.outParameterCount > 0) && VsaEngine.executeForJSEE)
            {
                throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
            }
            LateBinding callee = this.func.EvaluateAsLateBinding();

            object[] objArray = (this.args == null) ? null : this.args.EvaluateAsArray();
            base.Globals.CallContextStack.Push(new CallContext(base.context, callee, objArray));
            try
            {
                object             obj2 = null;
                CallableExpression func = this.func as CallableExpression;
                if ((func == null) || !(func.expression is Call))
                {
                    obj2 = callee.Call(objArray, this.isConstructor, this.inBrackets, base.Engine);
                }
                else
                {
                    obj2 = LateBinding.CallValue(callee.obj, objArray, this.isConstructor, this.inBrackets, base.Engine, func.GetObject2(), JSBinder.ob, null, null);
                }
                if (this.outParameterCount > 0)
                {
                    int index = 0;
                    int count = this.args.count;
                    while (index < count)
                    {
                        if (this.args[index] is AddressOf)
                        {
                            this.args[index].SetValue(objArray[index]);
                        }
                        index++;
                    }
                }
                obj3 = obj2;
            }
            catch (TargetInvocationException exception)
            {
                JScriptException innerException;
                if (exception.InnerException is JScriptException)
                {
                    innerException = (JScriptException)exception.InnerException;
                    if (innerException.context == null)
                    {
                        if (innerException.Number == -2146823281)
                        {
                            innerException.context = this.func.context;
                        }
                        else
                        {
                            innerException.context = base.context;
                        }
                    }
                }
                else
                {
                    innerException = new JScriptException(exception.InnerException, base.context);
                }
                throw innerException;
            }
            catch (JScriptException exception3)
            {
                if (exception3.context == null)
                {
                    if (exception3.Number == -2146823281)
                    {
                        exception3.context = this.func.context;
                    }
                    else
                    {
                        exception3.context = base.context;
                    }
                }
                throw exception3;
            }
            catch (Exception exception4)
            {
                throw new JScriptException(exception4, base.context);
            }
            finally
            {
                base.Globals.CallContextStack.Pop();
            }
            return(obj3);
        }
Esempio n. 9
0
        public virtual Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target,
                                           Object[] args, ParameterModifier[] modifiers, CultureInfo locale, String[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }

            bool preferredTypeSpecified = name.StartsWith("< JScript-");
            bool dispid0 = (name == null || name == String.Empty || name.Equals("[DISPID=0]") || preferredTypeSpecified);

            if ((invokeAttr & BindingFlags.CreateInstance) != 0)
            {
                if ((invokeAttr & (BindingFlags.InvokeMethod | BindingFlags.GetField | BindingFlags.GetProperty |
                                   BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
                {
                    throw new ArgumentException();
                }
                //js: x = new foo() --> dispid0, create
                if (dispid0)
                {
                    throw new MissingMethodException();
                }

                //js: x = new foo.name() --> dispid0, create
                LateBinding lb = new LateBinding(name, this);
                return(lb.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine));
            }

            //According to docs, name == null is only valid for CreateInstance
            if (name == null)
            {
                throw new ArgumentException();
            }

            if ((invokeAttr & (BindingFlags.InvokeMethod | BindingFlags.GetField | BindingFlags.GetProperty)) != 0)
            {
                if ((invokeAttr & (BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
                {
                    throw new ArgumentException();
                }

                if (dispid0)
                {
                    //All callable functions inherit from ScriptFunction which overrides this method to handle
                    //the InvokeMethod case.

                    //js,vbs: x = foo() --> dispid0, invoke
                    if ((invokeAttr & (BindingFlags.GetField | BindingFlags.GetProperty)) == 0)
                    {
                        throw new MissingMethodException();
                    }

                    //js: x = foo --> dispid0, propget; vbs: x = foo --> dispid0, invoke|propget
                    if (args == null || args.Length == 0)
                    {
                        if (this is JSObject || this is GlobalScope || this is ClassScope)
                        {
                            PreferredType preferredType = PreferredType.Either;
                            if (preferredTypeSpecified)
                            {
                                if (name.StartsWith("< JScript-Number"))
                                {
                                    preferredType = PreferredType.Number;
                                }
                                else if (name.StartsWith("< JScript-String"))
                                {
                                    preferredType = PreferredType.String;
                                }
                                else if (name.StartsWith("< JScript-LocaleString"))
                                {
                                    preferredType = PreferredType.LocaleString;
                                }
                            }
                            return(this.GetDefaultValue(preferredType));
                        }
                        throw new MissingFieldException();
                    }

                    //We support indexed properties with exactly one index on all script objects.

                    //js,vbs: x = foo(1,2) --> dispid0, invoke|propget
                    if (args.Length > 1)
                    {
                        throw new ArgumentException();
                    }

                    //js,vbs: x = foo(1) --> dispid0, invoke|propget
                    Object val = args[0];
                    if (val is Int32)
                    {
                        return(this[(int)val]);
                    }
                    IConvertible ic = Convert.GetIConvertible(val);
                    if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode()))
                    {
                        double d = ic.ToDouble(null);
                        if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d))
                        {
                            return(this[(int)d]);
                        }
                    }
                    return(this[Convert.ToString(val)]);
                }

                //If no arguments are supplied, prefer GetXXXX rather than Invoke.
                //js: x = foo.bar --> name="bar", propget; vbs: x = foo.bar --> name="bar", propget|invoke
                if ((args == null || args.Length == 0) && (invokeAttr & (BindingFlags.GetField | BindingFlags.GetProperty)) != 0)
                {
                    Object member = this.GetMemberValue(name);
                    if (member != Missing.Value)
                    {
                        return(member);
                    }

                    //js: x = foo.bar --> name="bar", propget
                    if ((invokeAttr & BindingFlags.InvokeMethod) == 0)
                    {
                        throw new MissingFieldException();
                    }
                }

                //Use LateBinding to call because arguments have been supplied.
                //vbs: x = foo.bar --> name="bar", propget|invoke
                //js,vbs: x = foo.bar() --> name="bar", invoke
                //js,vbs: x = foo.bar(1) --> name="bar", invoke|propget
                LateBinding lb = new LateBinding(name, this);
                return(lb.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine));
            }

            if ((invokeAttr & (BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
            {
                if (dispid0)
                {
                    if (args == null || args.Length != 2)
                    {
                        throw new ArgumentException();
                    }
                    Object val = args[0];
                    if (val is Int32)
                    {
                        this[(int)val] = args[1];
                        return(null);
                    }
                    IConvertible ic = Convert.GetIConvertible(val);
                    if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode()))
                    {
                        double d = ic.ToDouble(null);
                        if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d))
                        {
                            this[(int)d] = args[1];
                            return(null);
                        }
                    }
                    this[Convert.ToString(val)] = args[1];
                    return(null);
                }
                if (args == null || args.Length > 1)
                {
                    throw new ArgumentException();
                }
                this.SetMemberValue(name, args[0]);
                return(null);
            }

            throw new ArgumentException();
        }
 public virtual object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo locale, string[] namedParameters)
 {
     if (target != this)
     {
         throw new TargetException();
     }
     bool flag = name.StartsWith("< JScript-", StringComparison.Ordinal);
     bool flag2 = (((name == null) || (name == string.Empty)) || name.Equals("[DISPID=0]")) || flag;
     if ((invokeAttr & BindingFlags.CreateInstance) != BindingFlags.Default)
     {
         if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.SetField | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
         {
             throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
         }
         if (flag2)
         {
             throw new MissingMethodException();
         }
         LateBinding binding = new LateBinding(name, this);
         return binding.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine);
     }
     if (name == null)
     {
         throw new ArgumentException(JScriptException.Localize("Bad name", locale));
     }
     if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
     {
         if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) != BindingFlags.Default)
         {
             throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
         }
         if (flag2)
         {
             if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) == BindingFlags.Default)
             {
                 throw new MissingMethodException();
             }
             if ((args == null) || (args.Length == 0))
             {
                 if ((!(this is JSObject) && !(this is GlobalScope)) && !(this is ClassScope))
                 {
                     throw new MissingFieldException();
                 }
                 PreferredType either = PreferredType.Either;
                 if (flag)
                 {
                     if (name.StartsWith("< JScript-Number", StringComparison.Ordinal))
                     {
                         either = PreferredType.Number;
                     }
                     else if (name.StartsWith("< JScript-String", StringComparison.Ordinal))
                     {
                         either = PreferredType.String;
                     }
                     else if (name.StartsWith("< JScript-LocaleString", StringComparison.Ordinal))
                     {
                         either = PreferredType.LocaleString;
                     }
                 }
                 return this.GetDefaultValue(either);
             }
             if (args.Length > 1)
             {
                 throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
             }
             object ob = args[0];
             if (ob is int)
             {
                 return this[(int) ob];
             }
             IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob);
             if ((iConvertible != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(iConvertible.GetTypeCode()))
             {
                 double a = iConvertible.ToDouble(null);
                 if (((a >= 0.0) && (a <= 2147483647.0)) && (a == Math.Round(a)))
                 {
                     return this[(int) a];
                 }
             }
             return this[Microsoft.JScript.Convert.ToString(ob)];
         }
         if (((args == null) || (args.Length == 0)) && ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) != BindingFlags.Default))
         {
             object memberValue = this.GetMemberValue(name);
             if (memberValue != Microsoft.JScript.Missing.Value)
             {
                 return memberValue;
             }
             if ((invokeAttr & BindingFlags.InvokeMethod) == BindingFlags.Default)
             {
                 throw new MissingFieldException();
             }
         }
         LateBinding binding2 = new LateBinding(name, this);
         return binding2.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine);
     }
     if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) == BindingFlags.Default)
     {
         throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
     }
     if (flag2)
     {
         if ((args == null) || (args.Length < 2))
         {
             throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
         }
         if (args.Length > 2)
         {
             throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
         }
         object obj4 = args[0];
         if (obj4 is int)
         {
             this[(int) obj4] = args[1];
             return null;
         }
         IConvertible convertible2 = Microsoft.JScript.Convert.GetIConvertible(obj4);
         if ((convertible2 != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(convertible2.GetTypeCode()))
         {
             double num2 = convertible2.ToDouble(null);
             if (((num2 >= 0.0) && (num2 <= 2147483647.0)) && (num2 == Math.Round(num2)))
             {
                 this[(int) num2] = args[1];
                 return null;
             }
         }
         this[Microsoft.JScript.Convert.ToString(obj4)] = args[1];
         return null;
     }
     if ((args == null) || (args.Length < 1))
     {
         throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
     }
     if (args.Length > 1)
     {
         throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
     }
     this.SetMemberValue(name, args[0]);
     return null;
 }
Esempio n. 11
0
        internal override Object Evaluate()
        {
            if (this.outParameterCount > 0 && VsaEngine.executeForJSEE)
            {
                throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
            }
            LateBinding funcref = this.func.EvaluateAsLateBinding();

            Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
            Globals.CallContextStack.Push(new CallContext(this.context, funcref, actual_arguments));
            try{
                try{
                    Object             result = null;
                    CallableExpression cexpr  = this.func as CallableExpression;
                    if (cexpr == null || !(cexpr.expression is Call))
                    {
                        result = funcref.Call(actual_arguments, this.isConstructor, this.inBrackets, this.Engine);
                    }
                    else
                    {
                        result = LateBinding.CallValue(funcref.obj, actual_arguments, this.isConstructor, this.inBrackets, this.Engine,
                                                       cexpr.GetObject2(), JSBinder.ob, null, null);
                    }
                    if (this.outParameterCount > 0)
                    {
                        for (int i = 0, n = this.args.count; i < n; i++)
                        {
                            if (this.args[i] is AddressOf)
                            {
                                this.args[i].SetValue(actual_arguments[i]);
                            }
                        }
                    }
                    return(result);
                }catch (TargetInvocationException e) {
                    JScriptException se;
                    if (e.InnerException is JScriptException)
                    {
                        se = (JScriptException)e.InnerException;
                        if (se.context == null)
                        {
                            if (((uint)se.Number) == (0x800A0000 | (uint)JSError.ObjectExpected))
                            {
                                se.context = this.func.context;
                            }
                            else
                            {
                                se.context = this.context;
                            }
                        }
                    }
                    else
                    {
                        se = new JScriptException(e.InnerException, this.context);
                    }
                    throw se;
                }catch (JScriptException e) {
                    if (e.context == null)
                    {
                        if (((uint)e.Number) == (0x800A0000 | (uint)JSError.ObjectExpected))
                        {
                            e.context = this.func.context;
                        }
                        else
                        {
                            e.context = this.context;
                        }
                    }
                    throw e;
                }catch (Exception e) {
                    throw new JScriptException(e, this.context);
                }catch {
                    throw new JScriptException(JSError.NonClsException, this.context);
                }
            }finally{
                Globals.CallContextStack.Pop();
            }
        }
 internal override Object Invoke(Object obj, Object thisob, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture){
   bool construct = (options & BindingFlags.CreateInstance) != 0;
   bool brackets = (options & BindingFlags.GetProperty) != 0 && (options & BindingFlags.InvokeMethod) == 0;
   Object f = this.func;
   if (f == null) f = this.field.GetValue(this.obj);
   FunctionObject func = f as FunctionObject;
   JSObject jsOb = obj as JSObject;
   if (jsOb != null && func != null && func.isMethod && (func.attributes & MethodAttributes.Virtual) != 0 && 
      jsOb.GetParent() != func.enclosing_scope && ((ClassScope)func.enclosing_scope).HasInstance(jsOb)){
     LateBinding lb = new LateBinding(func.name);
     lb.obj = jsOb;
     return lb.Call(parameters, construct, brackets, ((ScriptObject)this.obj).engine);
   }
   return LateBinding.CallValue(f, parameters, construct, brackets, ((ScriptObject)this.obj).engine, thisob, binder, culture, null);
 }     
 public static object GetDefaultIndexedPropertyValue(object thisob, object[] arguments, VsaEngine engine, string[] namedParameters)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     object[] target = null;
     int num = (arguments == null) ? 0 : arguments.Length;
     if (((namedParameters != null) && (namedParameters.Length > 0)) && ((namedParameters[0] == "this") && (num > 0)))
     {
         target = new object[num - 1];
         ArrayObject.Copy(arguments, 1, target, 0, num - 1);
     }
     else
     {
         target = arguments;
     }
     LateBinding binding = new LateBinding(null, thisob, true);
     return binding.Call(target, false, false, engine);
 }
      public virtual Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target,
                                         Object[] args, ParameterModifier[] modifiers, CultureInfo locale, String[] namedParameters){
        if (target != this)
          throw new TargetException();

        bool preferredTypeSpecified = name.StartsWith("< JScript-", StringComparison.Ordinal);
        bool dispid0 = (name == null || name == String.Empty || name.Equals("[DISPID=0]") || preferredTypeSpecified);
        
        if ((invokeAttr & BindingFlags.CreateInstance) != 0){
          if ((invokeAttr & (BindingFlags.InvokeMethod|BindingFlags.GetField|BindingFlags.GetProperty|
                BindingFlags.SetField|BindingFlags.SetProperty|BindingFlags.PutDispProperty)) != 0)
            throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
          //js: x = new foo() --> dispid0, create
          if (dispid0)
            throw new MissingMethodException();
          
          //js: x = new foo.name() --> dispid0, create
          LateBinding lb = new LateBinding(name, this);
          return lb.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine);
        }
        
        //According to docs, name == null is only valid for CreateInstance
        if (name == null)
          throw new ArgumentException(JScriptException.Localize("Bad name", locale));

        if ((invokeAttr & (BindingFlags.InvokeMethod|BindingFlags.GetField|BindingFlags.GetProperty)) != 0){
          if ((invokeAttr & (BindingFlags.SetField|BindingFlags.SetProperty|BindingFlags.PutDispProperty)) != 0)
            throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
            
          if (dispid0){
            //All callable functions inherit from ScriptFunction which overrides this method to handle
            //the InvokeMethod case.
            
            //js,vbs: x = foo() --> dispid0, invoke
            if ((invokeAttr & (BindingFlags.GetField|BindingFlags.GetProperty)) == 0)
              throw new MissingMethodException();
              
            //js: x = foo --> dispid0, propget; vbs: x = foo --> dispid0, invoke|propget
            if (args == null || args.Length == 0){
              if (this is JSObject || this is GlobalScope || this is ClassScope){
                PreferredType preferredType = PreferredType.Either;
                if (preferredTypeSpecified){
                  if (name.StartsWith("< JScript-Number", StringComparison.Ordinal))
                    preferredType = PreferredType.Number;
                  else if (name.StartsWith("< JScript-String", StringComparison.Ordinal))
                    preferredType = PreferredType.String;
                  else if (name.StartsWith("< JScript-LocaleString", StringComparison.Ordinal))
                    preferredType = PreferredType.LocaleString;
                }
                return this.GetDefaultValue(preferredType);
              }
              throw new MissingFieldException();
            }
            
            //We support indexed properties with exactly one index on all script objects.
            
            //js,vbs: x = foo(1,2) --> dispid0, invoke|propget
            if (args.Length > 1) 
              throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
              
            //js,vbs: x = foo(1) --> dispid0, invoke|propget
            Object val = args[0];
            if (val is Int32)
              return this[(int)val];
            IConvertible ic = Convert.GetIConvertible(val);
            if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode())){
              double d = ic.ToDouble(null);
              if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d))
                return this[(int)d];
            }
            return this[Convert.ToString(val)];
          }
            
          //If no arguments are supplied, prefer GetXXXX rather than Invoke.
          //js: x = foo.bar --> name="bar", propget; vbs: x = foo.bar --> name="bar", propget|invoke
          if ((args == null || args.Length == 0) && (invokeAttr & (BindingFlags.GetField|BindingFlags.GetProperty)) != 0){
            Object member = this.GetMemberValue(name);
            if (member != Missing.Value)
              return member;
            
            //js: x = foo.bar --> name="bar", propget
            if ((invokeAttr & BindingFlags.InvokeMethod) == 0)
              throw new MissingFieldException();
          }
          
          //Use LateBinding to call because arguments have been supplied.
          //vbs: x = foo.bar --> name="bar", propget|invoke
          //js,vbs: x = foo.bar() --> name="bar", invoke
          //js,vbs: x = foo.bar(1) --> name="bar", invoke|propget
          LateBinding lb = new LateBinding(name, this);
          return lb.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine);
        }

        if ((invokeAttr & (BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0){
          if (dispid0){
            if (args == null || args.Length < 2)
              throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
            else if (args.Length > 2)
              throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
            Object val = args[0];
            if (val is Int32){
              this[(int)val] = args[1];
              return null;
            }
            IConvertible ic = Convert.GetIConvertible(val);
            if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode())){
              double d = ic.ToDouble(null);
              if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d)){
                this[(int)d] = args[1];
                return null;
              }
            }
            this[Convert.ToString(val)] = args[1];
            return null;
          }
          if (args == null || args.Length < 1)
            throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
          else if (args.Length > 1)
            throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
          this.SetMemberValue(name, args[0]);
          return null;
        }
                
        throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
      }
Esempio n. 15
0
        public virtual object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo locale, string[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }
            bool flag  = name.StartsWith("< JScript-", StringComparison.Ordinal);
            bool flag2 = (((name == null) || (name == string.Empty)) || name.Equals("[DISPID=0]")) || flag;

            if ((invokeAttr & BindingFlags.CreateInstance) != BindingFlags.Default)
            {
                if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.SetField | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }
                if (flag2)
                {
                    throw new MissingMethodException();
                }
                LateBinding binding = new LateBinding(name, this);
                return(binding.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine));
            }
            if (name == null)
            {
                throw new ArgumentException(JScriptException.Localize("Bad name", locale));
            }
            if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
            {
                if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) != BindingFlags.Default)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }
                if (flag2)
                {
                    if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) == BindingFlags.Default)
                    {
                        throw new MissingMethodException();
                    }
                    if ((args == null) || (args.Length == 0))
                    {
                        if ((!(this is JSObject) && !(this is GlobalScope)) && !(this is ClassScope))
                        {
                            throw new MissingFieldException();
                        }
                        PreferredType either = PreferredType.Either;
                        if (flag)
                        {
                            if (name.StartsWith("< JScript-Number", StringComparison.Ordinal))
                            {
                                either = PreferredType.Number;
                            }
                            else if (name.StartsWith("< JScript-String", StringComparison.Ordinal))
                            {
                                either = PreferredType.String;
                            }
                            else if (name.StartsWith("< JScript-LocaleString", StringComparison.Ordinal))
                            {
                                either = PreferredType.LocaleString;
                            }
                        }
                        return(this.GetDefaultValue(either));
                    }
                    if (args.Length > 1)
                    {
                        throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                    }
                    object ob = args[0];
                    if (ob is int)
                    {
                        return(this[(int)ob]);
                    }
                    IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob);
                    if ((iConvertible != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(iConvertible.GetTypeCode()))
                    {
                        double a = iConvertible.ToDouble(null);
                        if (((a >= 0.0) && (a <= 2147483647.0)) && (a == Math.Round(a)))
                        {
                            return(this[(int)a]);
                        }
                    }
                    return(this[Microsoft.JScript.Convert.ToString(ob)]);
                }
                if (((args == null) || (args.Length == 0)) && ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) != BindingFlags.Default))
                {
                    object memberValue = this.GetMemberValue(name);
                    if (memberValue != Microsoft.JScript.Missing.Value)
                    {
                        return(memberValue);
                    }
                    if ((invokeAttr & BindingFlags.InvokeMethod) == BindingFlags.Default)
                    {
                        throw new MissingFieldException();
                    }
                }
                LateBinding binding2 = new LateBinding(name, this);
                return(binding2.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine));
            }
            if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) == BindingFlags.Default)
            {
                throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
            }
            if (flag2)
            {
                if ((args == null) || (args.Length < 2))
                {
                    throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
                }
                if (args.Length > 2)
                {
                    throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                }
                object obj4 = args[0];
                if (obj4 is int)
                {
                    this[(int)obj4] = args[1];
                    return(null);
                }
                IConvertible convertible2 = Microsoft.JScript.Convert.GetIConvertible(obj4);
                if ((convertible2 != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(convertible2.GetTypeCode()))
                {
                    double num2 = convertible2.ToDouble(null);
                    if (((num2 >= 0.0) && (num2 <= 2147483647.0)) && (num2 == Math.Round(num2)))
                    {
                        this[(int)num2] = args[1];
                        return(null);
                    }
                }
                this[Microsoft.JScript.Convert.ToString(obj4)] = args[1];
                return(null);
            }
            if ((args == null) || (args.Length < 1))
            {
                throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
            }
            if (args.Length > 1)
            {
                throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
            }
            this.SetMemberValue(name, args[0]);
            return(null);
        }