コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static double getTime(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(DateObject));
            DateObject date = (DateObject)thisObj;

            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 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);
        }
コード例 #6
0
        internal bool HasMethod(string name)
        {
            Type       prototype = SemanticAnalyser.map_to_prototype(this);
            MethodInfo method    = prototype.GetMethod(name, BindingFlags.Public | BindingFlags.Static);

            return(method != null);
        }
コード例 #7
0
ファイル: ErrorPrototype.cs プロジェクト: raj581/Marvin
        public static string toString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(ErrorObject));
            ErrorObject error = (ErrorObject)thisObj;

            return(error.message.ToString());
        }
コード例 #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
        internal static MemberInfo get_member(AST left, AST right)
        {
            bool right_is_identifier = false;

            if (left != null && right != null)
            {
                right_is_identifier = right is Identifier;

                Type   target_type = null;
                string prop_name   = string.Empty;
                string obj         = string.Empty;

                if (left is Identifier && right_is_identifier)
                {
                    obj         = ((Identifier)left).name.Value;
                    prop_name   = ((Identifier)right).name.Value;
                    target_type = SemanticAnalyser.map_to_ctr(obj);
                }
                else if (left is ICanLookupPrototype && right_is_identifier)
                {
                    prop_name   = ((Identifier)right).name.Value;
                    target_type = SemanticAnalyser.map_to_prototype(left);
                }
                if (target_type != null && prop_name != string.Empty)
                {
                    return(Find(target_type, prop_name));
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: RegExpPrototype.cs プロジェクト: raj581/Marvin
        public static string toString(object thisObj)
        {
            SemanticAnalyser.assert_type(thisObj, typeof(RegExpObject));
            RegExpObject re = (RegExpObject)thisObj;

            return(re.ToString());
        }
コード例 #11
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);
        }
コード例 #12
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));
        }
コード例 #13
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);
        }
コード例 #14
0
 protected bool ValidLabel()
 {
     binding = SemanticAnalyser.GetLabel(label);
     if (binding == null || !IsLabel(binding))
     {
         throw new Exception("error JS1026: Label not found");
     }
     return(true);
 }
コード例 #15
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);
        }
コード例 #16
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);
        }
コード例 #17
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)));
        }
コード例 #18
0
        public MethodInfo GetMethod(string name, BindingFlags bindFlags)
        {
            Type prototype = SemanticAnalyser.map_to_prototype(this);

            if (prototype != null)
            {
                return(prototype.GetMethod(name, bindFlags | BindingFlags.Static));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #19
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);
        }
コード例 #20
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));
        }
コード例 #21
0
 internal override bool Resolve(Environment env)
 {
     try {
         SemanticAnalyser.AddLabel(name, this);
     } catch (ArgumentException) {
         throw new Exception("error JS1025: Label redefined");
     }
     if (stm != null)
     {
         stm.Resolve(env);
     }
     SemanticAnalyser.RemoveLabel(name);
     return(true);
 }
コード例 #22
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);
        }
コード例 #23
0
        internal static bool IsDeletable(Identifier left, Identifier right, out bool isCtr)
        {
            Type ctr = SemanticAnalyser.map_to_ctr(left.name.Value);

            isCtr = ctr != null ? true : false;

            if (isCtr)
            {
                return(SemanticAnalyser.get_member(left, right) == null);
            }

            Console.WriteLine("ctr = {0}, left = {1} ({2}); right = {3} ({4})",
                              ctr, left, left.GetType(), right, right.GetType());
            return(false);
        }
コード例 #24
0
        internal object CallMethod(string name, params object [] args)
        {
            Type       prototype = SemanticAnalyser.map_to_prototype(this);
            MethodInfo method    = prototype.GetMethod(name, BindingFlags.Public | BindingFlags.Static);

            if (method == null)
            {
                method = typeof(ObjectPrototype).GetMethod(name, BindingFlags.Public | BindingFlags.Static);
            }
            if (method == null)
            {
                Console.WriteLine("CallMethod: method is null! this = {0}, prototype = {1}, name = {2}", this, prototype, name);
            }
            return(CallMethod(method, args));
        }
コード例 #25
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);
            }
        }
コード例 #26
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)));
            }
        }
コード例 #27
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));
            }
        }
コード例 #28
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);
        }
コード例 #29
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);
        }
コード例 #30
0
        internal void build_closure(EmitContext ec, string full_name, string encodedSource)
        {
            ILGenerator ig   = ec.ig;
            string      name = func_obj.name;
            Type        t    = ec.mod_builder.GetType(CodeGenerator.GetTypeName(Location.SourceName));

            ig.Emit(OpCodes.Ldtoken, t);
            ig.Emit(OpCodes.Ldstr, name);
            ig.Emit(OpCodes.Ldstr, full_name);

            func_obj.parameters.Emit(ec);
            build_local_fields(ig);

            //
            // If we have en eval method call, we have to
            // save the loca vars in the stack
            //
            if (SemanticAnalyser.MethodContainsEval(name) ||
                SemanticAnalyser.MethodVarsUsedNested(name))
            {
                ig.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                ig.Emit(OpCodes.Ldc_I4_0);
            }

            ig.Emit(OpCodes.Ldc_I4_0);            // FIXME: this hard coded for now.
            ig.Emit(OpCodes.Ldstr, Decompiler.Decompile(encodedSource, 0, 0).Trim());
            ig.Emit(OpCodes.Ldnull);              // FIXME: this hard coded for now.

            CodeGenerator.load_engine(InFunction, ig);

            ig.Emit(OpCodes.Call, typeof(FunctionDeclaration).GetMethod("JScriptFunctionDeclaration"));

            if (parent == null || parent.GetType() == typeof(ScriptBlock))
            {
                ig.Emit(OpCodes.Stsfld, t.GetField(name));
            }
            else
            {
                ig.Emit(OpCodes.Stloc, local_func);
            }
        }