상속: JSObject
예제 #1
0
        private static bool TryDirectGetObjectProperty(out object result, object obj, string rhs)
        {
            ArrayObject  ary    = obj as ArrayObject;
            StringObject str    = obj as StringObject;
            ScriptObject js_obj = obj as ScriptObject;

            if (js_obj != null)
            {
                Hashtable elems = js_obj.elems;

                // Numeric index?
                uint index;
                if (IsArrayIndex(rhs, out index))
                {
                    if (ary != null)
                    {
                        result = elems [index];
                        return(true);
                    }
                    else if (str != null)
                    {
                        string str_val = str.value;
                        if (index < str_val.Length)
                        {
                            result = str_val.Substring((int)index, 1);
                        }
                        else
                        {
                            result = null;
                        }
                        return(true);
                    }
                }

                if (elems.ContainsKey(rhs))
                {
                    object      val   = elems [rhs];
                    JSFieldInfo field = val as JSFieldInfo;
                    if (field != null)
                    {
                        result = field.GetValue(rhs);
                    }
                    else
                    {
                        result = val;
                    }
                    return(true);
                }
            }

            bool success = TryGetNativeProperty(out result, obj, rhs);

            return(success);
        }
예제 #2
0
        public override bool Equals(Object obj)
        {
            StringObject other = obj as StringObject;

            if (other == null)
            {
                return(false);
            }
            else
            {
                return(other.value == this.value);
            }
        }
예제 #3
0
        private static void DirectSetObjectProperty(object obj, string rhs, object value)
        {
            ArrayObject  ary       = obj as ArrayObject;
            StringObject str       = obj as StringObject;
            ScriptObject js_obj    = obj as ScriptObject;
            bool         is_js_obj = js_obj != null;

            if (is_js_obj)
            {
                InvalidateCacheEntry(js_obj, rhs);
            }

            // Numeric index?
            uint index;

            if (IsArrayIndex(rhs, out index))
            {
                if (ary != null)
                {
                    Hashtable elems     = ary.elems;
                    bool      had_value = elems.ContainsKey(index);
                    elems [index] = value;
                    if (!had_value)
                    {
                        AdjustArrayLength(ary, index);
                    }
                    return;
                }
                else if (str != null)
                {
                    return;
                }
            }
            if (!TrySetNativeProperty(obj, rhs, value) && is_js_obj)
            {
                FieldInfo field = js_obj.GetField(rhs);
                if (field == null)
                {
                    field = js_obj.AddField(rhs);
                }
                field.SetValue(rhs, value);
            }
        }
예제 #4
0
        public static String toString(Object thisob)
        {
            StringObject strob = thisob as StringObject;

            if (strob != null)
            {
                return(strob.value);
            }
            ConcatString concatStr = thisob as ConcatString;

            if (concatStr != null)
            {
                return(concatStr.ToString());
            }
            IConvertible ic = Convert.GetIConvertible(thisob);

            if (Convert.GetTypeCode(thisob, ic) == TypeCode.String)
            {
                return(ic.ToString(null));
            }
            throw new JScriptException(JSError.StringExpected);
        }
        public static string toString(object thisob)
        {
            StringObject obj2 = thisob as StringObject;

            if (obj2 != null)
            {
                return(obj2.value);
            }
            ConcatString str = thisob as ConcatString;

            if (str != null)
            {
                return(str.ToString());
            }
            IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(thisob);

            if (Microsoft.JScript.Convert.GetTypeCode(thisob, iConvertible) != TypeCode.String)
            {
                throw new JScriptException(JSError.StringExpected);
            }
            return(iConvertible.ToString(null));
        }