Пример #1
0
        public static object call(object thisObj, object thisArg, params object [] args)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(ScriptFunction));
            ScriptFunction fun = (ScriptFunction)thisObj;

            return(fun.Invoke(thisArg, args));
        }
Пример #2
0
        public static string toString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(RegExpObject));
            RegExpObject re = (RegExpObject)thisObj;

            return(re.ToString());
        }
Пример #3
0
        public static double setUTCSeconds(object thisObj, double dsec, object msec)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;
            double     t    = date.ms;

            double new_ms;

            if (msec == null)
            {
                new_ms = DateConstructor.msFromTime(t);
            }
            else
            {
                new_ms = Convert.ToNumber(msec);
            }

            double time = DateConstructor.MakeTime(DateConstructor.HourFromTime(t), DateConstructor.MinFromTime(t),
                                                   dsec, new_ms);
            double day     = Math.Floor(t / DateConstructor.MS_PER_DAY);
            double new_val = DateConstructor.MakeDate(day, time);

            date.ms = DateConstructor.TimeClip(new_val);
            return(date.ms);
        }
Пример #4
0
        public static string toLocaleString(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;

            string separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ";

            Hashtable     elems = array_obj.elems;
            uint          n     = (uint)array_obj.length;
            StringBuilder str   = new StringBuilder();
            bool          first = true;

            for (uint i = 0; i < n; i++)
            {
                ScriptObject elem = (ScriptObject)Convert.ToObject(elems [i], null);
                if (!first && elem != null)
                {
                    str.Append(separator);
                }
                first = false;
                if (elem != null)
                {
                    str.Append(Convert.ToString(elem.CallMethod("toLocaleString", new object [] { })));
                }
            }
            return(str.ToString());
        }
Пример #5
0
        public static double setMonth(object thisObj, double dmonth,
                                      object date)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject dt = (DateObject)thisObj;
            double     t  = DateConstructor.LocalTime(dt.ms);

            double new_date;

            if (date == null)
            {
                new_date = DateConstructor.DateFromTime(t);
            }
            else
            {
                new_date = Convert.ToNumber(date);
            }

            double day = DateConstructor.MakeDay((double)DateConstructor.YearFromTime(t),
                                                 dmonth, new_date);
            double new_val = DateConstructor.ToUTC(DateConstructor.MakeDate(day, t % DateConstructor.MS_PER_DAY));

            dt.ms = DateConstructor.TimeClip(new_val);
            return(dt.ms);
        }
Пример #6
0
        public static string toString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(ErrorObject));
            ErrorObject error = (ErrorObject)thisObj;

            return(error.message.ToString());
        }
Пример #7
0
        public static string toUTCString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date_obj = (DateObject)thisObj;
            double     val      = date_obj.ms;
            int        year     = DateConstructor.YearFromTime(val);
            int        month    = DateConstructor.MonthFromTime(val);
            int        date     = DateConstructor.DateFromTime(val);
            int        hour     = DateConstructor.HourFromTime(val);
            int        min      = DateConstructor.MinFromTime(val);
            int        sec      = DateConstructor.SecFromTime(val);

            DateTime dt;

            try {
                dt = new DateTime(year, month + 1, date);
            } catch (ArgumentOutOfRangeException) {
                return(InvalidDateString);
            }

            string date_string = dt.ToString("ddd, d MMM yyyy ", CultureInfo.InvariantCulture);
            string time_string = String.Format(@"{0:00}:{1:00}:{2:00} UTC", hour, min, sec);

            return(date_string + time_string);
        }
Пример #8
0
        public static object shift(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint   n      = (uint)array_obj.length;
            object result = null;

            if (n > 0)
            {
                if (elems.ContainsKey((uint)0))
                {
                    result = elems [(uint)0];
                    elems.Remove((uint)0);
                    for (uint i = 1; i < n; i++)
                    {
                        elems [i - 1] = elems [i];
                    }
                }
                // Last element gets removed automatically
                array_obj.length = n - 1;
            }
            return(result);
        }
Пример #9
0
        public static double getTime(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;

            return(date.ms);
        }
Пример #10
0
        public static object unshift(object thisObj, params object [] args)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint old_length = (uint)array_obj.length;
            uint arg_length = (uint)args.Length;
            uint new_length = old_length + arg_length;

            if (arg_length > 0)
            {
                // First let's make some free space for the new items
                long i = (long)old_length - 1;
                long j = i + (long)arg_length;
                for (; i >= 0; i--, j--)
                {
                    elems [(uint)j] = elems [(uint)i];
                }

                // Then insert the new items in the now free space
                for (; j >= 0; j--)
                {
                    elems [(uint)j] = args [(uint)j];
                }
            }
            //
            // NOTE: MSC returns the new array, but
            // ECMA-262 says to return the new length. We
            // conform to the standard.
            //
            array_obj.length = new_length;
            return(new_length);
        }
Пример #11
0
        public static double setTime(object thisObj, double time)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;

            date.ms = DateConstructor.TimeClip(time);
            return(date.ms);
        }
Пример #12
0
        public static ArrayObject slice(object thisObj, VsaEngine engine, double start, object end)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            uint        array_len = (uint)array_obj.length;
            uint        _start, _end;

            if (start > array_len)
            {
                _start = array_len;
            }
            else
            {
                _start = (uint)start;
                if (_start < 0)
                {
                    _start += array_len;
                }
            }

            if (end == null)
            {
                _end = array_len;
            }
            else
            {
                _end = Convert.ToUint32(end);

                if (_end < 0)
                {
                    _end += array_len;
                }
                else if (_end > array_len)
                {
                    _end = array_len;
                }
            }

            if (_end < _start)
            {
                _end = _start;
            }

            ArrayObject result = new ArrayObject();

            result.length = _end - _start;

            for (uint i = _start; i < _end; i++)
            {
                result.elems [i - _start] = array_obj.elems [i];
            }

            return(result);
        }
Пример #13
0
        public static string toString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            string date_str = toDateString(thisObj);

            if (date_str == InvalidDateString)
            {
                return(date_str);
            }

            return(date_str.Insert(date_str.LastIndexOf(' '), " " + toTimeString(thisObj)));
        }
Пример #14
0
        public static double setUTCDate(object thisObj, double ddate)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;
            double     t    = date.ms;
            double     day  = DateConstructor.MakeDay((double)DateConstructor.YearFromTime(t),
                                                      (double)DateConstructor.MonthFromTime(t), ddate);
            double new_val = DateConstructor.MakeDate(day, t % DateConstructor.MS_PER_DAY);

            date.ms = DateConstructor.TimeClip(new_val);
            return(date.ms);
        }
Пример #15
0
        public static double setUTCMilliseconds(object thisObj, double msec)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;
            double     t    = date.ms;
            double     time = DateConstructor.MakeTime(DateConstructor.HourFromTime(t), DateConstructor.MinFromTime(t),
                                                       DateConstructor.SecFromTime(t), msec);
            double day     = Math.Floor(t / DateConstructor.MS_PER_DAY);
            double new_val = DateConstructor.MakeDate(day, time);

            date.ms = DateConstructor.TimeClip(new_val);
            return(date.ms);
        }
Пример #16
0
        public static object sort(object thisObj, object function)
        {
            // TODO: Shouldn't this be generic?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject    array_obj = (ArrayObject)thisObj;
            ScriptFunction fun       = function as ScriptFunction;
            uint           n         = (uint)array_obj.length;

            if (n > 1)
            {
                SortHelper.qsort(array_obj.elems, 0, n - 1, SortHelper.CompareDelegateFor(fun));
            }
            return(array_obj);
        }
Пример #17
0
        public static string toTimeString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date_obj = (DateObject)thisObj;
            double     val      = date_obj.ms;
            double     lv       = DateConstructor.LocalTime(val);
            int        hour     = DateConstructor.HourFromTime(lv);
            int        min      = DateConstructor.MinFromTime(lv);
            int        sec      = DateConstructor.SecFromTime(lv);
            double     off      = getTimezoneOffset(thisObj);

            return(String.Format(@"{0:00}:{1:00}:{2:00} UTC{3:\+0;\-0;\+0}", hour, min, sec, -off / 60));
        }
Пример #18
0
        public static double getUTCMilliseconds(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date = (DateObject)thisObj;
            double     val  = date.ms;

            if (Double.IsNaN(val))
            {
                return(Double.NaN);
            }
            else
            {
                return(DateConstructor.msFromTime(val));
            }
        }
Пример #19
0
        public static double getFullYear(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date = (DateObject)thisObj;
            double     val  = date.ms;

            if (Double.IsNaN(val))
            {
                return(Double.NaN);
            }
            else
            {
                return(DateConstructor.YearFromTime(DateConstructor.LocalTime(val)));
            }
        }
Пример #20
0
        public static double getTimezoneOffset(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date = (DateObject)thisObj;
            double     val  = date.ms;

            if (Double.IsNaN(val))
            {
                return(Double.NaN);
            }
            else
            {
                return((val - DateConstructor.LocalTime(val)) / DateConstructor.MS_PER_MINUTE);
            }
        }
Пример #21
0
        public static double setHours(object thisObj, double dhour, object min,
                                      object sec, object msec)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;
            double     t    = DateConstructor.LocalTime(date.ms);

            double new_min;

            if (min == null)
            {
                new_min = DateConstructor.MinFromTime(t);
            }
            else
            {
                new_min = Convert.ToNumber(min);
            }

            double new_sec;

            if (sec == null)
            {
                new_sec = DateConstructor.SecFromTime(t);
            }
            else
            {
                new_sec = Convert.ToNumber(sec);
            }

            double new_ms;

            if (msec == null)
            {
                new_ms = DateConstructor.msFromTime(t);
            }
            else
            {
                new_ms = Convert.ToNumber(msec);
            }

            double time    = DateConstructor.MakeTime(dhour, new_min, new_sec, new_ms);
            double day     = Math.Floor(t / DateConstructor.MS_PER_DAY);
            double new_val = DateConstructor.ToUTC(DateConstructor.MakeDate(day, time));

            date.ms = DateConstructor.TimeClip(new_val);
            return(date.ms);
        }
Пример #22
0
        public static long push(object thisObj, params object [] args)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint i = (uint)array_obj.length;
            long n = i + args.Length;

            for (uint j = 0; i < n; i++, j++)
            {
                elems [i] = args [j];
            }

            array_obj.length = n;
            return(n);
        }
Пример #23
0
        public static string toLocaleDateString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));

            DateObject date_obj = (DateObject)thisObj;
            double     val      = date_obj.ms;
            double     lv       = DateConstructor.LocalTime(val);
            int        year     = DateConstructor.YearFromTime(lv);
            int        month    = DateConstructor.MonthFromTime(lv);
            int        date     = DateConstructor.DateFromTime(lv);

            DateTime dt;

            try {
                dt = new DateTime(year, month + 1, date);
            } catch (ArgumentOutOfRangeException) {
                return(InvalidDateString);
            }

            return(dt.ToString("D"));
        }
Пример #24
0
        public static object reverse(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint   n      = (uint)array_obj.length;
            uint   half_n = n / 2;
            uint   j      = n - 1;
            object temp;

            for (uint i = 0; i < half_n; i++, j--)
            {
                temp      = elems [i];
                elems [i] = elems [j];
                elems [j] = temp;
            }

            return(array_obj);
        }
Пример #25
0
        public static double setUTCFullYear(object thisObj, double dyear,
                                            object month, object date)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject dt = (DateObject)thisObj;
            double     t  = dt.ms;

            if (Double.IsNaN(t))
            {
                t = 0;
            }

            double new_month;

            if (month == null)
            {
                new_month = DateConstructor.MonthFromTime(t);
            }
            else
            {
                new_month = Convert.ToNumber(month);
            }

            double new_date;

            if (date == null)
            {
                new_date = DateConstructor.DateFromTime(t);
            }
            else
            {
                new_date = Convert.ToNumber(date);
            }

            double day     = DateConstructor.MakeDay(dyear, new_month, new_date);
            double new_val = DateConstructor.MakeDate(day, t % DateConstructor.MS_PER_DAY);

            dt.ms = DateConstructor.TimeClip(new_val);
            return(dt.ms);
        }
Пример #26
0
        public static ArrayObject concat(object thisObj, VsaEngine engine,
                                         params object [] args)
        {
            uint        i         = 0;
            ArrayObject result    = new ArrayObject();
            int         arg_idx   = -1;
            int         arg_count = args.Length;

            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            object cur_obj = thisObj;

            ArrayObject cur_ary;

            while (cur_obj != null)
            {
                if (cur_obj is ArrayObject)
                {
                    cur_ary = (ArrayObject)cur_obj;

                    uint n = (uint)cur_ary.length;
                    for (uint j = 0; j < n; j++, i++)
                    {
                        result.elems [i] = cur_ary.elems [j];
                    }
                }
                else
                {
                    result.elems [i++] = cur_obj;
                }

                arg_idx++;
                cur_obj = arg_idx < arg_count ? args [arg_idx] : null;
            }

            result.length = i;

            return(result);
        }
Пример #27
0
        public static object pop(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint   n      = (uint)array_obj.length;
            object result = null;

            if (n > 0)
            {
                uint new_len = n - 1;
                if (elems.ContainsKey(new_len))
                {
                    result = elems [new_len];
                }
                // Element gets removed automatically
                array_obj.length = new_len;
            }
            return(result);
        }
Пример #28
0
        public static string join(object thisObj, object separator)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;

            string _separator;

            if (separator == null)
            {
                _separator = ",";
            }
            else
            {
                _separator = Convert.ToString(separator);
            }

            Hashtable     elems = array_obj.elems;
            uint          n     = (uint)array_obj.length;
            StringBuilder str   = new StringBuilder();
            bool          first = true;

            for (uint i = 0; i < n; i++)
            {
                if (!first)
                {
                    str.Append(_separator);
                }
                first = false;
                object elem = elems [i];
                if (elem != null)
                {
                    str.Append(Convert.ToString(elem));
                }
            }
            return(str.ToString());
        }
Пример #29
0
        public static ArrayObject splice(object thisObj, VsaEngine engine,
                                         double start, double deleteCnt,
                                         params object [] args)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            ArrayObject result    = new ArrayObject();
            Hashtable   elems     = array_obj.elems;
            Hashtable   del_elems = result.elems;

            uint old_length = (uint)array_obj.length;

            start = (long)start;
            if (start < 0)
            {
                start = Math.Max(start + old_length, 0);
            }
            else
            {
                start = Math.Min(old_length, start);
            }

            deleteCnt = (long)deleteCnt;
            deleteCnt = Math.Min(Math.Max(deleteCnt, 0), old_length - start);

            uint arg_length = (uint)args.Length;
            long add_length = (long)((long)arg_length - (uint)deleteCnt);

            add_length = (long)Math.Max(add_length, -((long)old_length));
            long del_length = -add_length;
            uint new_length = (uint)((long)old_length + add_length);

            long i, j, m;

            // First let's make some free space for the new items (if needed)
            if (add_length > 0)
            {
                i = (long)old_length - 1;
                j = (uint)(i + add_length);
                for (; i >= start; i--, j--)
                {
                    elems [(uint)j] = elems [(uint)i];
                }
            }

            // Then insert the new items in the now free space / replace existing ones
            j = m = 0;
            long old_start = (long)(start + add_length);

            for (i = (long)start; j < arg_length; i++, j++)
            {
                if (i >= old_start && elems.ContainsKey((uint)i))
                {
                    del_elems [(uint)m] = elems [(uint)i];
                    m++;
                    elems.Remove((uint)i);
                }

                if (j < arg_length)
                {
                    elems [(uint)i] = args [(uint)j];
                }
            }

            // Finally, delete elements which have no replacement elements
            if (add_length < 0)
            {
                uint last_elem_idx = (uint)(i + del_length);
                for (uint k = 0; k < del_length; i++, j++, k++)
                {
                    if (elems.ContainsKey((uint)i))
                    {
                        del_elems [(uint)m] = elems [(uint)i];
                        m++;
                        elems.Remove((uint)i);
                    }
                }

                // And move up trailing elements
                uint l = (uint)(last_elem_idx - del_length);
                for (uint k = last_elem_idx; l < old_length; k++, l++)
                {
                    if (elems.ContainsKey(k))
                    {
                        elems [l] = elems [k];
                    }
                    else if (elems.ContainsKey(l))
                    {
                        elems.Remove(l);
                    }
                }
            }

            array_obj.length = new_length;
            result.length    = (uint)deleteCnt;
            return(result);
        }
Пример #30
0
 public static string toString(object thisObj)
 {
     SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
     return(ArrayPrototype.join(thisObj, null));
 }