internal static string Join(object thisob, string separator, bool localize)
        {
            StringBuilder builder = new StringBuilder();
            uint          num     = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (num > 0x7fffffff)
            {
                throw new JScriptException(JSError.OutOfMemory);
            }
            if (num > builder.Capacity)
            {
                builder.Capacity = (int)num;
            }
            for (uint i = 0; i < num; i++)
            {
                object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if ((valueAtIndex != null) && !(valueAtIndex is Missing))
                {
                    if (localize)
                    {
                        builder.Append(Microsoft.JScript.Convert.ToLocaleString(valueAtIndex));
                    }
                    else
                    {
                        builder.Append(Microsoft.JScript.Convert.ToString(valueAtIndex));
                    }
                }
                if (i < (num - 1))
                {
                    builder.Append(separator);
                }
            }
            return(builder.ToString());
        }
 public static object unshift(object thisob, params object[] args)
 {
     if ((args != null) && (args.Length != 0))
     {
         if (thisob is ArrayObject)
         {
             return(((ArrayObject)thisob).Unshift(args));
         }
         uint num  = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
         long num2 = num + args.Length;
         LateBinding.SetMemberValue(thisob, "length", num2);
         for (long i = num - 1; i >= 0L; i -= 1L)
         {
             object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong)i);
             if (valueAtIndex is Missing)
             {
                 LateBinding.DeleteValueAtIndex(thisob, (ulong)(i + args.Length));
             }
             else
             {
                 LateBinding.SetValueAtIndex(thisob, (ulong)(i + args.Length), valueAtIndex);
             }
         }
         for (uint j = 0; j < args.Length; j++)
         {
             LateBinding.SetValueAtIndex(thisob, (ulong)j, args[j]);
         }
     }
     return(thisob);
 }
Пример #3
0
        public static bool hasOwnProperty(object thisob, object name)
        {
            string str = Microsoft.JScript.Convert.ToString(name);

            if (thisob is ArrayObject)
            {
                long num = ArrayObject.Array_index_for(str);
                if (num >= 0L)
                {
                    object valueAtIndex = ((ArrayObject)thisob).GetValueAtIndex((uint)num);
                    return((valueAtIndex != null) && (valueAtIndex != Microsoft.JScript.Missing.Value));
                }
            }
            if (!(thisob is JSObject))
            {
                return(!(LateBinding.GetMemberValue(thisob, str) is Microsoft.JScript.Missing));
            }
            MemberInfo[] member = ((JSObject)thisob).GetMember(str, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            int          length = member.Length;

            if (length <= 1)
            {
                if (length < 1)
                {
                    return(false);
                }
                if (member[0] is JSPrototypeField)
                {
                    return(!(((JSPrototypeField)member[0]).value is Microsoft.JScript.Missing));
                }
            }
            return(true);
        }
Пример #4
0
        internal override LateBinding EvaluateAsLateBinding()
        {
            if (!this.isFullyResolved)
            {
                this.BindName(); //Doing this at runtime. Binding is now final (for this call). Do it here so that scope chain logic works as at compile time.
                this.isFullyResolved = false;
            }
            if (this.defaultMember == this.member)
            {
                this.defaultMember = null;
            }
            Object      ob = this.GetObject();
            LateBinding lb = this.lateBinding;

            if (lb == null)
            {
                lb = this.lateBinding = new LateBinding(this.name, ob, VsaEngine.executeForJSEE);
            }
            lb.obj          = ob;
            lb.last_object  = ob;
            lb.last_members = this.members;
            lb.last_member  = this.member;
            if (!this.isFullyResolved)
            {
                this.members = null;
            }
            return(lb);
        }
        public static Object shift(Object thisob)
        {
            Object res = null;

            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Shift());
            }
            uint length = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (length == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(res);
            }
            res = LateBinding.GetValueAtIndex(thisob, 0);
            for (uint i = 1; i < length; i++)
            {
                Object val = LateBinding.GetValueAtIndex(thisob, i);
                if (val is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, i - 1);
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, i - 1, val);
                }
            }
            LateBinding.DeleteValueAtIndex(thisob, length - 1);
            LateBinding.SetMemberValue(thisob, "length", length - 1);
            return(res);
        }
Пример #6
0
        internal override bool Delete()
        {
            Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
            int      n  = actual_arguments.Length;
            Object   ob = this.func.Evaluate();

            if (ob == null)
            {
                return(true);        //As per the standard, not backwards compatible with JS5
            }
            if (n == 0)
            {
                return(true);
            }
            Type       obType   = ob.GetType();
            MethodInfo deleteOp = obType.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static,
                                                   null, new Type[] { obType, Typeob.ArrayOfObject }, null);

            if (deleteOp == null || (deleteOp.Attributes & MethodAttributes.SpecialName) == 0 || deleteOp.ReturnType != Typeob.Boolean)
            {
                return(LateBinding.DeleteMember(ob, Convert.ToString(actual_arguments[n - 1])));
            }
            else
            {
                deleteOp = new JSMethodInfo(deleteOp);
                return((bool)deleteOp.Invoke(null, new Object[] { ob, actual_arguments }));
            }
        }
Пример #7
0
        public static bool hasOwnProperty(Object thisob, Object name)
        {
            String nameStr = Convert.ToString(name);

            if (thisob is ArrayObject)
            {
                long index = ArrayObject.Array_index_for(nameStr);
                if (index >= 0)
                {
                    Object ob = ((ArrayObject)thisob).GetValueAtIndex((uint)index);
                    return(ob != null && ob != Missing.Value);
                }
            }
            if (thisob is JSObject)
            {
                MemberInfo[] members = ((JSObject)thisob).GetMember(nameStr, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                int          n       = members.Length;
                if (n > 1)
                {
                    return(true);
                }
                if (n < 1)
                {
                    return(false);
                }
                if (members[0] is JSPrototypeField)
                {
                    //Do not count it as an "own" property unless it has been written to
                    return(!(((JSPrototypeField)members[0]).value is Missing));
                }
                return(true);
            }
            return(!(LateBinding.GetMemberValue(thisob, nameStr) is Missing));
        }
        internal void SortObject(long left, long right)
        {
            object obj3;

            if (right <= left)
            {
                return;
            }
            long num = left + ((long)((right - left) * MathObject.random()));

            LateBinding.SwapValues(this.obj, (uint)num, (uint)right);
            object valueAtIndex = LateBinding.GetValueAtIndex(this.obj, (ulong)right);
            long   num2         = left - 1L;
            long   num3         = right;

Label_0039:
            obj3 = LateBinding.GetValueAtIndex(this.obj, (ulong)(num2 += 1L));
            if ((num2 < num3) && (this.Compare(valueAtIndex, obj3) >= 0))
            {
                goto Label_0039;
            }
            do
            {
                obj3 = LateBinding.GetValueAtIndex(this.obj, (ulong)(num3 -= 1L));
            }while ((num3 > num2) && (this.Compare(valueAtIndex, obj3) <= 0));
            if (num2 < num3)
            {
                LateBinding.SwapValues(this.obj, (uint)num2, (uint)num3);
                goto Label_0039;
            }
            LateBinding.SwapValues(this.obj, (uint)num2, (uint)right);
            this.SortObject(left, num2 - 1L);
            this.SortObject(num2 + 1L, right);
        }
Пример #9
0
        public JSObject()
        {
            elems          = new Hashtable();
            property_cache = new Hashtable();

            /* Initialize cache for common properties if this is a Prototype */
            Type type = this.GetType();

            if (type.GetField("Proto", BindingFlags.NonPublic | BindingFlags.Static) != null)
            {
                foreach (MemberInfo field in type.GetMembers())
                {
                    if (field.DeclaringType != type)
                    {
                        continue;
                    }

                    string name = field.Name;
                    if (name.StartsWith("get_"))
                    {
                        name = name.Substring(4);
                    }
                    if (name == "Item" || name.StartsWith("set_") || name.StartsWith("."))
                    {
                        continue;
                    }

                    property_cache [LateBinding.MapToExternalName(name)] = this;
                }
            }
        }
        public static object shift(object thisob)
        {
            object valueAtIndex = null;

            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Shift());
            }
            uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (num == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(valueAtIndex);
            }
            valueAtIndex = LateBinding.GetValueAtIndex(thisob, 0L);
            for (uint i = 1; i < num; i++)
            {
                object obj3 = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if (obj3 is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, (ulong)(i - 1));
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i - 1), obj3);
                }
            }
            LateBinding.DeleteValueAtIndex(thisob, (ulong)(num - 1));
            LateBinding.SetMemberValue(thisob, "length", num - 1);
            return(valueAtIndex);
        }
        internal void SortObject(long left, long right) //left and right are longs to allow for values < 0. Their positives values are always < UInt32.MaxValue.
        {
            Object x, y;

            if (right > left)
            {
                long piv = left + (long)((right - left) * MathObject.random());
                LateBinding.SwapValues(this.obj, (uint)piv, (uint)right);
                x = LateBinding.GetValueAtIndex(this.obj, (ulong)right);
                long i = left - 1, j = right;
                while (true)
                {
                    do
                    {
                        y = LateBinding.GetValueAtIndex(this.obj, (ulong)++i);
                    }while(i < j && this.Compare(x, y) >= 0);
                    do
                    {
                        y = LateBinding.GetValueAtIndex(this.obj, (ulong)--j);
                    }while(j > i && this.Compare(x, y) <= 0);
                    if (i >= j)
                    {
                        break;
                    }
                    LateBinding.SwapValues(this.obj, (uint)i, (uint)j);
                }
                LateBinding.SwapValues(this.obj, (uint)i, (uint)right);
                this.SortObject(left, i - 1);
                this.SortObject(i + 1, right);
            }
        }
Пример #12
0
        internal override LateBinding EvaluateAsLateBinding()
        {
            LateBinding lateBinding = this.lateBinding;

            if (lateBinding == null)
            {
                if ((base.member != null) && !this.rootObjectInferredType.Equals(this.rootObject.InferType(null)))
                {
                    base.InvalidateBinding();
                }
                this.lateBinding        = lateBinding = new LateBinding(base.name, null, VsaEngine.executeForJSEE);
                lateBinding.last_member = base.member;
            }
            object obj2 = this.rootObject.Evaluate();

            try
            {
                lateBinding.obj = obj2 = Microsoft.JScript.Convert.ToObject(obj2, base.Engine);
                if ((base.defaultMember == null) && (base.member != null))
                {
                    lateBinding.last_object = obj2;
                }
            }
            catch (JScriptException exception)
            {
                if (exception.context == null)
                {
                    exception.context = this.rootObject.context;
                }
                throw exception;
            }
            return(lateBinding);
        }
Пример #13
0
        internal static String Join(Object thisob, String separator, bool localize)
        {
            StringBuilder str        = new StringBuilder();
            uint          thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            for (uint i = 0; i < thisLength; i++)
            {
                Object value = LateBinding.GetValueAtIndex(thisob, i);
                if (value != null && !(value is Missing))
                {
                    if (localize)
                    {
                        str.Append(Convert.ToLocaleString(value));
                    }
                    else
                    {
                        str.Append(Convert.ToString(value));
                    }
                }
                if (i < thisLength - 1)
                {
                    str.Append(separator);
                }
            }
            return(str.ToString());
        }
Пример #14
0
        internal override void SetMemberValue(String name, Object value)
        {
            MemberInfo[] members = this.GetMember(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
            if (members.Length == 0)
            {
                // We do not want to create expando fields on the global object when assigning to an undefined
                // variable in the debugger.
                if (VsaEngine.executeForJSEE)
                {
                    throw new JScriptException(JSError.UndefinedIdentifier, new Context(new DocumentContext("", null), name));
                }
                FieldInfo field = this.AddField(name);
                if (field != null)
                {
                    field.SetValue(this, value);
                }
                return;
            }
            MemberInfo m = LateBinding.SelectMember(members);

            if (m == null)
            {
                throw new JScriptException(JSError.AssignmentToReadOnly);
            }
            LateBinding.SetMemberValue(this, name, value, m, members);
        }
        public static Object unshift(Object thisob, params Object[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(thisob);
            }
            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Unshift(args));
            }
            uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            long newLength = oldLength + args.Length;

            LateBinding.SetMemberValue(thisob, "length", newLength);
            // shift the array
            for (long i = oldLength - 1; i >= 0; i--)
            {
                Object val = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if (val is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, (ulong)(i + args.Length));
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i + args.Length), val);
                }
            }
            // copy the input args
            for (uint i = 0; i < args.Length; i++)
            {
                LateBinding.SetValueAtIndex(thisob, i, args[i]);
            }
            return(thisob);
        }
Пример #16
0
 internal override void SetMemberValue(string name, object value)
 {
     MemberInfo[] member = this.GetMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
     if (member.Length == 0)
     {
         if (VsaEngine.executeForJSEE)
         {
             throw new JScriptException(JSError.UndefinedIdentifier, new Context(new DocumentContext("", null), name));
         }
         FieldInfo info = this.AddField(name);
         if (info != null)
         {
             info.SetValue(this, value);
         }
     }
     else
     {
         MemberInfo info2 = LateBinding.SelectMember(member);
         if (info2 == null)
         {
             throw new JScriptException(JSError.AssignmentToReadOnly);
         }
         LateBinding.SetMemberValue(this, name, value, info2, member);
     }
 }
        internal static String Join(Object thisob, String separator, bool localize)
        {
            StringBuilder str        = new StringBuilder();
            uint          thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (thisLength > int.MaxValue)
            {
                throw new JScriptException(JSError.OutOfMemory);
            }
            // Small optimization so we're not doing a bunch of reallocs for large arrays.
            if (thisLength > str.Capacity)
            {
                str.Capacity = (int)thisLength;
            }
            for (uint i = 0; i < thisLength; i++)
            {
                Object value = LateBinding.GetValueAtIndex(thisob, i);
                if (value != null && !(value is Missing))
                {
                    if (localize)
                    {
                        str.Append(Convert.ToLocaleString(value));
                    }
                    else
                    {
                        str.Append(Convert.ToString(value));
                    }
                }
                if (i < thisLength - 1)
                {
                    str.Append(separator);
                }
            }
            return(str.ToString());
        }
Пример #18
0
        internal override LateBinding EvaluateAsLateBinding()
        {
            if (!base.isFullyResolved)
            {
                this.BindName();
                base.isFullyResolved = false;
            }
            if (base.defaultMember == base.member)
            {
                base.defaultMember = null;
            }
            object      obj2        = this.GetObject();
            LateBinding lateBinding = this.lateBinding;

            if (lateBinding == null)
            {
                lateBinding = this.lateBinding = new LateBinding(base.name, obj2, VsaEngine.executeForJSEE);
            }
            lateBinding.obj          = obj2;
            lateBinding.last_object  = obj2;
            lateBinding.last_members = base.members;
            lateBinding.last_member  = base.member;
            if (!base.isFullyResolved)
            {
                base.members = null;
            }
            return(lateBinding);
        }
Пример #19
0
        internal override bool DeleteMember(String name)
        {
            FieldInfo field = (FieldInfo)this.NameTable[name];

            if (field != null)
            {
                if (field is JSExpandoField)
                {
                    field.SetValue(this, Missing.Value);
                    this.name_table.Remove(name);
                    this.field_table.Remove(field);
                    return(true);
                }
                else if (field is JSPrototypeField)
                {
                    field.SetValue(this, Missing.Value);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (this.parent != null)
            {
                return(LateBinding.DeleteMember(this.parent, name));
            }
            else
            {
                return(false);
            }
        }
Пример #20
0
        internal override LateBinding EvaluateAsLateBinding()
        {
            LateBinding lb = this.lateBinding;

            if (lb == null)
            {
                if (this.member != null && !this.rootObjectInferredType.Equals(this.rootObject.InferType(null)))
                {
                    this.InvalidateBinding();
                }
                this.lateBinding = lb = new LateBinding(this.name, null, VsaEngine.executeForJSEE);
                lb.last_member   = this.member;
            }
            Object val = this.rootObject.Evaluate();

            try{
                lb.obj = val = Convert.ToObject(val, this.Engine);
                if (this.defaultMember == null && this.member != null)
                {
                    lb.last_object = val;
                }
            }catch (JScriptException e) {
                if (e.context == null)
                {
                    e.context = this.rootObject.context;
                }
                throw e;
            }
            return(lb);
        }
 public static object InvokeMethodInfo(MethodInfo m, object[] arguments, bool construct, object thisob, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     return(LateBinding.CallOneOfTheMembers(new MemberInfo[] { m }, arguments, construct, thisob, JSBinder.ob, null, null, engine));
 }
Пример #22
0
 public object InvokeMember(string name, BindingFlags flags, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo locale, string[] namedParameters)
 {
     if ((flags & BindingFlags.CreateInstance) == BindingFlags.Default)
     {
         return(LateBinding.CallValue(this.elementType, args, true, true, null, null, binder, locale, namedParameters));
     }
     return(Typeob.Array.InvokeMember(name, flags, binder, target, args, modifiers, locale, namedParameters));
 }
 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);
 }
Пример #24
0
 internal virtual Object GetMemberValue(String name)
 {
     MemberInfo[] members = this.GetMember(name, BindingFlags.Instance | BindingFlags.Public);
     if (members.Length == 0)
     {
         return(Missing.Value);
     }
     return(LateBinding.GetMemberValue(this, name, LateBinding.SelectMember(members), members));
 }
Пример #25
0
 // this is the typical Lookup constructor. The context points to the identifier
 internal Lookup(Context context)
   : base(context, context.GetCode()){
   this.lexLevel = 0;
   this.evalLexLevel = 0;
   this.fieldLoc = null;
   this.refLoc = null;
   this.lateBinding = null;
   this.thereIsAnObjectOnTheStack = false;
 }
Пример #26
0
 internal Lookup(Context context) : base(context, context.GetCode())
 {
     this.lexLevel     = 0;
     this.evalLexLevel = 0;
     this.fieldLoc     = null;
     this.refLoc       = null;
     this.lateBinding  = null;
     this.thereIsAnObjectOnTheStack = false;
 }
Пример #27
0
 internal virtual object GetMemberValue(string name)
 {
     MemberInfo[] member = this.GetMember(name, BindingFlags.Public | BindingFlags.Instance);
     if (member.Length == 0)
     {
         return(Microsoft.JScript.Missing.Value);
     }
     return(LateBinding.GetMemberValue(this, name, LateBinding.SelectMember(member), member));
 }
 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 CallConstructor(string typename, object[] arguments, VsaEngine engine)
        {
            if (engine == null)
            {
                engine = VsaEngine.CreateEngine();
            }
            object type = GetType(typename);

            return(LateBinding.CallValue(null, type, arguments, true, false, engine));
        }
Пример #31
0
 public Object InvokeMember(String name, BindingFlags flags, Binder binder, Object target,
                            Object[] args, ParameterModifier[] modifiers, CultureInfo locale, String[] namedParameters)
 {
     if ((flags & BindingFlags.CreateInstance) == 0)
     {
         //Try to create an instance of the array
         return(LateBinding.CallValue(this.elementType, args, true, true, null, null, binder, locale, namedParameters));
     }
     return(Typeob.Array.InvokeMember(name, flags, binder, target, args, modifiers, locale, namedParameters));
 }
Пример #32
0
 internal override void SetMemberValue(String name, Object value)
 {
     if (LateBinding.GetMemberValue2(this.contained_object, name) is Missing)
     {
         ((ScriptObject)this.parent).SetMemberValue(name, value);
     }
     else
     {
         LateBinding.SetMemberValue(this.contained_object, name, value);
     }
 }
        public static Object reverse(Object thisob)
        {
            uint thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            uint halfSize   = thisLength / 2;

            for (uint low = 0, high = thisLength - 1; low < halfSize; low++, high--)
            {
                LateBinding.SwapValues(thisob, low, high);
            }
            return(thisob);
        }
Пример #34
0
 internal Member(Context context, AST rootObject, AST memberName)
   : base(context, memberName.context.GetCode()){
   this.fast = this.Engine.doFast;
   this.isImplicitWrapper = false;
   this.isNonVirtual = rootObject is ThisLiteral && ((ThisLiteral)rootObject).isSuper;
   this.lateBinding = null;
   this.memberNameContext = memberName.context;
   this.rootObject = rootObject;
   this.rootObjectInferredType = null;
   this.refLoc = null;
   this.temp = null;
 }
 internal override LateBinding EvaluateAsLateBinding()
 {
     LateBinding lateBinding = this.lateBinding;
     if (lateBinding == null)
     {
         if ((base.member != null) && !this.rootObjectInferredType.Equals(this.rootObject.InferType(null)))
         {
             base.InvalidateBinding();
         }
         this.lateBinding = lateBinding = new LateBinding(base.name, null, VsaEngine.executeForJSEE);
         lateBinding.last_member = base.member;
     }
     object obj2 = this.rootObject.Evaluate();
     try
     {
         lateBinding.obj = obj2 = Microsoft.JScript.Convert.ToObject(obj2, base.Engine);
         if ((base.defaultMember == null) && (base.member != null))
         {
             lateBinding.last_object = obj2;
         }
     }
     catch (JScriptException exception)
     {
         if (exception.context == null)
         {
             exception.context = this.rootObject.context;
         }
         throw exception;
     }
     return lateBinding;
 }
 internal static object GetMemberValue(object obj, string name)
 {
     if (obj is ScriptObject)
     {
         return ((ScriptObject) obj).GetMemberValue(name);
     }
     LateBinding binding = new LateBinding(name, obj);
     return binding.GetNonMissingValue();
 }
 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);
 }
Пример #38
0
 internal override LateBinding EvaluateAsLateBinding(){
   LateBinding lb = this.lateBinding;
   if (lb == null){
     if (this.member != null && !this.rootObjectInferredType.Equals(this.rootObject.InferType(null)))
       this.InvalidateBinding();
     this.lateBinding = lb = new LateBinding(this.name, null, VsaEngine.executeForJSEE);
     lb.last_member = this.member;
   }
   Object val = this.rootObject.Evaluate();
   try{
     lb.obj = val = Convert.ToObject(val, this.Engine);
     if (this.defaultMember == null && this.member != null)
       lb.last_object = val;
   }catch(JScriptException e){
     if (e.context == null){
       e.context = this.rootObject.context;
     }
     throw e;
   }
   return lb;
 }
Пример #39
0
 internal override LateBinding EvaluateAsLateBinding(){
   if (!this.isFullyResolved){
     this.BindName(); //Doing this at runtime. Binding is now final (for this call). Do it here so that scope chain logic works as at compile time.
     this.isFullyResolved = false;
   }
   if (this.defaultMember == this.member) this.defaultMember = null;
   Object ob = this.GetObject();
   LateBinding lb = this.lateBinding;
   if (lb == null)
     lb = this.lateBinding = new LateBinding(this.name, ob, VsaEngine.executeForJSEE);
   lb.obj = ob;
   lb.last_object = ob;
   lb.last_members = this.members;
   lb.last_member = this.member;
   if (!this.isFullyResolved)
     this.members = null;
   return lb;
 }
 internal CallContext(Context sourceContext, LateBinding callee, object[] actual_parameters)
 {
     this.sourceContext = sourceContext;
     this.callee = callee;
     this.actual_parameters = actual_parameters;
 }
Пример #41
0
 internal static Object GetMemberValue2(Object obj, String name){
   if (obj is ScriptObject)
     return ((ScriptObject)obj).GetMemberValue(name);
   //Create a LateBinding instance so that we can reuse the ugly logic in BindToMember to get the members.
   LateBinding lb = new LateBinding(name, obj);
   return lb.GetValue();
 }
Пример #42
0
 internal CallContext(Context sourceContext, Object evalParam){
   this.sourceContext = sourceContext;
   this.callee = null;
   this.actual_parameters = new Object[]{evalParam};
 }
Пример #43
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-", 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));
      }
Пример #44
0
 internal static void SetMemberValue(Object obj, String name, Object value){
   if (obj is ScriptObject){
     ((ScriptObject)obj).SetMemberValue(name, value);
     return;
   }
   LateBinding lb = new LateBinding(name, obj);
   lb.SetValue(value);
 }
 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 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;
 }
Пример #47
0
 internal static Object GetMemberValue2(Object obj, String name){
   if (obj is ScriptObject)
     return ((ScriptObject)obj).GetMemberValue(name);
   LateBinding lb = new LateBinding(name, obj);
   return lb.GetValue();
 }