Exemplo n.º 1
0
        private T GetCache()
        {
            if (!IsInCache)
            {
                AddToCache();
            }

            ThisObj = (T)HttpContext.Current.Cache[ThisObj.GetType().ToString()];
            return(ThisObj);
        }
Exemplo n.º 2
0
        private bool CreateFile(string fullpath)
        {
            var    filepath   = fullpath;
            string objcontent = ThisObj.Serialize();

            _inOutBinaryService
            .StreamWriterEx
            .WriteStream(filepath)
            .Write(objcontent)
            .Close()
            .Dispose();

            return(true);
        }
Exemplo n.º 3
0
        public void Save(T value)
        {
            RemoveCache();

            var    filepath   = FullPath();
            string objcontent = ThisObj.Serialize();

            _inOutBinaryService
            .StreamWriterEx
            .WriteStream(filepath)
            .Write(objcontent)
            .Close()
            .Dispose();

            ThisObj = GetCache();
        }
Exemplo n.º 4
0
        private void AddArrayProperties()
        {
            this.Global.SetDataProp("Array", this.ArrayCtor, false, false, false);
            this.ArrayPrototype.SetDataProp("length", 0.0, true, false, true);
            this.ArrayCtor.SetDataProp("isArray", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                return(args[0] is JSArray);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.toString cannot be used as a constructor");
                }
                JSObject array     = ThisObj.ToJSObject();
                JSFunctionBase fnc = ThisObj["join"] as JSFunctionBase;
                if (fnc != null)
                {
                    return(fnc.Call(Scope, ThisObj, new JSArgs(fnc, new JSValue[0])));
                }
                return("[object " + ThisObj.ClassString + "]");
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("toLocaleString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                JSObject elementObj;
                JSFunctionBase func;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.toLocaleString called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (len == 0)
                {
                    return(string.Empty);
                }
                JSValue firstElement = O["0"];
                StringBuilder R      = new StringBuilder();
                if (firstElement.CheckCoercible())
                {
                    elementObj = firstElement.ToJSObject();
                    func       = InternalUtilities.JSFunctionCast(elementObj["toLocaleString"]);
                    R.Append(func.Call(Scope, elementObj, new JSArgs(func, new JSValue[0])).StringValue());
                }
                for (uint k = 1; k < len; k++)
                {
                    R.Append(",");
                    JSValue nextElement = O[k.ToString()];
                    if (nextElement.CheckCoercible())
                    {
                        elementObj = nextElement.ToJSObject();
                        func       = InternalUtilities.JSFunctionCast(elementObj["toLocaleString"]);
                        R.Append(func.Call(Scope, elementObj, new JSArgs(func, new JSValue[0])).StringValue());
                    }
                }
                return(R.ToString());
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("concat", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.concat called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                JSArray A  = new JSArray(new JSValue[0]);
                int n      = 0;
                _concat_append(A, ref n, O);
                foreach (JSValue E in args.ArgValues)
                {
                    _concat_append(A, ref n, E);
                }
                return(A);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("join", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                string sep;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.join called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (args[0] is JSUndefined)
                {
                    sep = ",";
                }
                else
                {
                    sep = args[0].StringValue();
                }
                if (len == 0)
                {
                    return(string.Empty);
                }
                JSValue element0 = O["0"];
                StringBuilder R  = new StringBuilder();
                if (element0.CheckCoercible())
                {
                    R.Append(element0.StringValue());
                }
                for (int k = 1; k < len; k++)
                {
                    R.Append(sep);
                    JSValue element = O[k.ToString()];
                    if (element.CheckCoercible())
                    {
                        R.Append(element.StringValue());
                    }
                }
                return(R.ToString());
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("pop", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.pop called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (len == 0)
                {
                    O["length"] = 0.0;
                    return(JSUndefined.Instance);
                }
                string indx     = (len - 1).ToString();
                JSValue element = O[indx];
                O.DeleteProperty(indx, true);
                O["length"] = (JSValue)(len - 1);
                return(element);
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("push", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.push called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double n   = O["length"].NumberValue().JSToUInt32();
                foreach (JSValue E in args.ArgValues)
                {
                    O[n.ToString()] = E;
                    n++;
                }
                O["length"] = n;
                return(n);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("reverse", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.reverse called as constructor");
                }
                JSObject O  = ThisObj.ToJSObject();
                uint len    = O["length"].NumberValue().JSToUInt32();
                uint middle = len / 2;
                for (uint lower = 0; lower != middle; lower++)
                {
                    string upperP      = ((len - lower) - 1).ToString();
                    string lowerP      = lower.ToString();
                    JSValue lowerValue = O[lowerP];
                    JSValue upperValue = O[upperP];
                    bool lowerExists   = O.HasProperty(lowerP);
                    bool upperExists   = O.HasProperty(upperP);
                    if (lowerExists && upperExists)
                    {
                        O[lowerP] = upperValue;
                        O[upperP] = lowerValue;
                    }
                    else if (!(lowerExists || !upperExists))
                    {
                        O[lowerP] = upperValue;
                        O.DeleteProperty(upperP, true);
                    }
                    else if (!(!lowerExists || upperExists))
                    {
                        O.DeleteProperty(lowerP, true);
                        O[upperP] = lowerValue;
                    }
                }
                return(O);
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("shift", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.shift called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double len = O["length"].NumberValue().JSToUInt32();
                if (len == 0.0)
                {
                    O["length"] = 0.0;
                    return(JSUndefined.Instance);
                }
                JSValue first = O["0"];
                for (int k = 1; k < len; k++)
                {
                    string from = k.ToString();
                    string to   = (k - 1).ToString();
                    if (O.HasProperty(from))
                    {
                        JSValue fromVal = O[from];
                        O[to]           = fromVal;
                    }
                    else
                    {
                        O.DeleteProperty(to, true);
                    }
                }
                O.DeleteProperty((len - 1.0).ToString(), true);
                O["length"] = len - 1.0;
                return(first);
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("slice", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                double k;
                double relativeEnd;
                double final;

                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.slice called as constructor");
                }

                JSObject O           = ThisObj.ToJSObject();
                JSArray A            = new JSArray(new JSValue[0]);
                uint len             = O["length"].NumberValue().JSToUInt32();
                double relativeStart = args[0].NumberValue().JSToInteger();

                if (relativeStart < 0.0)
                {
                    k = Math.Max((double)(len + relativeStart), (double)0.0);
                }
                else
                {
                    k = Math.Min(relativeStart, (double)len);
                }

                if (args[1] is JSUndefined)
                {
                    relativeEnd = len;
                }
                else
                {
                    relativeEnd = args[1].NumberValue().JSToInteger();
                }

                if (relativeEnd < 0.0)
                {
                    final = Math.Max((double)(len + relativeEnd), (double)0.0);
                }
                else
                {
                    final = Math.Min(relativeEnd, (double)len);
                }

                uint ik     = (uint)k;
                uint ifinal = (uint)final;
                for (int n = 0; ik < ifinal; n++)
                {
                    string Pk = ik.ToString();
                    if (O.HasProperty(Pk))
                    {
                        JSValue kValue  = O[Pk];
                        A[n.ToString()] = kValue;
                    }
                    ik++;
                }
                return(A);
            }, 2), true, false, true);
            this.ArrayPrototype.SetDataProp("sort", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.sort called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    int i;
                    IEnumerable <JSValue> a2;
                    int nUnset        = 0;
                    int nUndef        = 0;
                    List <JSValue> a1 = new List <JSValue>();
                    for (i = 0; i < len; i++)
                    {
                        JSValue v;
                        if (!O.TryGetPropertyValue(i.ToString(), out v))
                        {
                            nUnset++;
                        }
                        else if (v is JSUndefined)
                        {
                            nUndef++;
                        }
                        else
                        {
                            a1.Add(v);
                        }
                    }
                    if (args[0] is JSUndefined)
                    {
                        a2 = a1.OrderBy <JSValue, string>(x => x.StringValue(), StringComparer.Ordinal);
                    }
                    else
                    {
                        _sortHelper h = new _sortHelper(InternalUtilities.JSFunctionCast(args[0]), Scope);
                        a2            = a1.OrderBy <JSValue, JSValue>(x => x, h);
                    }
                    i = 0;
                    foreach (JSValue v in a2)
                    {
                        O[i.ToString()] = v;
                        i++;
                    }
                    while (nUndef-- != 0)
                    {
                        O[i.ToString()] = JSUndefined.Instance;
                        i++;
                    }
                    while (nUnset-- != 0)
                    {
                        string s = i.ToString();
                        if (O.HasOwnProperty(s))
                        {
                            O.DeleteProperty(s, false);
                        }
                        i++;
                    }
                }
                return(O);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("splice", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                double actualStart;
                uint k;
                string from;
                JSValue fromValue;
                JSValue[] items;
                string to;
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.splice called as constructor");
                }
                JSObject O           = ThisObj.ToJSObject();
                JSArray A            = new JSArray(new JSValue[0]);
                uint len             = O["length"].NumberValue().JSToUInt32();
                double relativeStart = args[0].NumberValue().JSToInteger();
                if (relativeStart < 0.0)
                {
                    actualStart = Math.Max((double)(len + relativeStart), (double)0.0);
                }
                else
                {
                    actualStart = Math.Min(relativeStart, (double)len);
                }
                double actualDeleteCount = Math.Min(Math.Max(args[1].NumberValue().JSToInteger(), 0.0), len - actualStart);
                uint iactualStart        = (uint)actualStart;
                uint iactualDeleteCount  = (uint)actualDeleteCount;
                for (k = 0; k < iactualDeleteCount; k++)
                {
                    from = (iactualStart + k).ToString();
                    if (O.HasProperty(from))
                    {
                        fromValue       = O[from];
                        A[k.ToString()] = fromValue;
                    }
                }
                if (args.Count <= 2)
                {
                    items = new JSValue[0];
                }
                else
                {
                    items = args.ArgValues.Skip <JSValue>(2).ToArray <JSValue>();
                }
                int itemCount = items.Length;
                if (itemCount < iactualDeleteCount)
                {
                    for (k = iactualStart; k < (len - iactualDeleteCount); k++)
                    {
                        from = (k + iactualDeleteCount).ToString();
                        to   = (k + itemCount).ToString();
                        if (O.HasProperty(from))
                        {
                            fromValue = O[from];
                            O[to]     = fromValue;
                        }
                        else
                        {
                            O.DeleteProperty(to, true);
                        }
                    }
                    for (k = len; k > ((len - iactualDeleteCount) + itemCount); k--)
                    {
                        O.DeleteProperty((k - 1).ToString(), true);
                    }
                }
                else if (itemCount > iactualDeleteCount)
                {
                    for (k = len - iactualDeleteCount; k > iactualStart; k--)
                    {
                        from = ((k + iactualDeleteCount) - 1).ToString();
                        to   = ((k + itemCount) - 1L).ToString();
                        if (O.HasProperty(from))
                        {
                            fromValue = O[from];
                            O[to]     = fromValue;
                        }
                        else
                        {
                            O.DeleteProperty(to, true);
                        }
                    }
                }
                k = iactualStart;
                foreach (JSValue E in items)
                {
                    O[k.ToString()] = E;
                    k++;
                }
                O["length"] = (JSValue)((len - iactualDeleteCount) + itemCount);
                return(A);
            }, 2), true, false, true);
            this.ArrayPrototype.SetDataProp("unshift", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.unshift called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                double len = O["length"].NumberValue().JSToUInt32();
                for (double k = len; k > 0.0; k--)
                {
                    string from = (k - 1.0).ToString();
                    string to   = ((k + args.Count) - 1.0).ToString();
                    if (O.HasProperty(from))
                    {
                        JSValue fromValue = O[from];
                        O[to]             = fromValue;
                    }
                    else
                    {
                        O.DeleteProperty(to, true);
                    }
                }
                int j = 0;
                foreach (JSValue E in args.ArgValues)
                {
                    O[j.ToString()] = E;
                    j++;
                }
                O["length"] = len + args.Count;
                return(len + args.Count);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("indexOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.indexOf called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    double n;
                    uint k;
                    if (args.Count >= 2)
                    {
                        n = args[1].NumberValue();
                    }
                    else
                    {
                        n = 0.0;
                    }
                    if (n >= len)
                    {
                        return(-1.0);
                    }
                    if (n >= 0.0)
                    {
                        k = (uint)n;
                    }
                    else
                    {
                        k = len - ((uint)-n);
                        if (k < 0)
                        {
                            k = 0;
                        }
                    }
                    while (k < len)
                    {
                        if (O.HasProperty(k.ToString()))
                        {
                            JSValue elementK = O[k.ToString()];
                            if (JSValue.JSEqualsExact(args[0], elementK))
                            {
                                return((double)k);
                            }
                        }
                        k++;
                    }
                }
                return(-1.0);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("lastIndexOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                if (AsConstructor)
                {
                    throw new JSRuntimeException("TypeError", "Array.lastIndexOf called as constructor");
                }
                JSObject O = ThisObj.ToJSObject();
                uint len   = O["length"].NumberValue().JSToUInt32();
                if (len != 0)
                {
                    double n;
                    uint k;
                    if (args.Count >= 2)
                    {
                        n = args[1].NumberValue();
                    }
                    else
                    {
                        n = len;
                    }
                    if (n >= 0.0)
                    {
                        k = Math.Min((uint)n, len - 1);
                    }
                    else
                    {
                        k = len - ((uint)-n);
                    }
                    while (k >= 0)
                    {
                        if (O.HasProperty(k.ToString()))
                        {
                            JSValue elementK = O[k.ToString()];
                            if (JSValue.JSEqualsExact(args[0], elementK))
                            {
                                return((double)k);
                            }
                        }
                        k--;
                    }
                }
                return(-1.0);
            }, 1), true, false, true);
            this.ArrayPrototype.SetDataProp("every", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("some", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("forEach", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("map", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("filter", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("reduce", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
            this.ArrayPrototype.SetDataProp("reduceRight", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
            {
                throw new Exception();
            }), true, false, true);
        }
Exemplo n.º 5
0
 private void AddToCache()
 {
     HttpContext.Current.Cache[ThisObj.GetType().ToString()] = ThisObj.DeSerialize(FullPath());
 }
Exemplo n.º 6
0
 private void RemoveCache()
 {
     HttpContext.Current.Cache.Remove(ThisObj.GetType().ToString());
 }
Exemplo n.º 7
0
 private void AddObjectProperties()
 {
     this.Global.SetDataProp("Object", this.ObjectCtor, false, false, false);
     this.ObjectCtor.SetDataProp("getPrototypeOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "getPrototypeOf argument not an object");
         }
         JSValue r = arg.Prototype;
         if (r == null)
         {
             return(JSNull.Instance);
         }
         return(r);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("getOwnPropertyNames", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "getOwnPropertyNames argument not an object");
         }
         IList <KeyValuePair <string, PropWrapper> > c = arg.GetOwnProperties();
         List <JSValue> ar = new List <JSValue>();
         foreach (KeyValuePair <string, PropWrapper> p in c)
         {
             if (p.Value.Enumerable)
             {
                 ar.Add(p.Key);
             }
         }
         return(new JSArray(ar.ToArray()));
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("create", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSValue arg = args[0];
         if (!((arg is JSObject) || (arg is JSNull)))
         {
             throw new JSRuntimeException("TypeError", "invalid prototype passed to Object.create");
         }
         if (arg is JSNull)
         {
             arg = null;
         }
         JSObject obj = new JSObject(arg);
         if (args.Count > 1)
         {
             throw new NotImplementedException();
         }
         return(obj);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("defineProperty", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject O = args[0] as JSObject;
         if (O == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.defineProperty");
         }
         string P      = args[1].StringValue();
         JSObject desc = args[2].ToJSObject();
         UpdatePropertyDescriptor(O, P, desc);
         return(O);
     }, 3), true, false, true);
     this.ObjectCtor.SetDataProp("defineProperties", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         throw new Exception();
     }), true, false, true);
     this.ObjectCtor.SetDataProp("seal", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.seal");
         }
         foreach (KeyValuePair <string, PropWrapper> p in arg.GetOwnProperties())
         {
             p.Value.Configurable = false;
         }
         arg.IsExtensible = false;
         return(arg);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("freeze", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.freeze");
         }
         foreach (KeyValuePair <string, PropWrapper> p in arg.GetOwnProperties())
         {
             if (p.Value is DataProperty)
             {
                 p.Value.Writable = false;
             }
             p.Value.Configurable = false;
         }
         arg.IsExtensible = false;
         return(arg);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("preventExtensions", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.preventExtensions");
         }
         arg.IsExtensible = false;
         return(arg);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("isSealed", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.isSealed");
         }
         if (arg.IsExtensible)
         {
             return(JSBool.False);
         }
         foreach (KeyValuePair <string, PropWrapper> p in arg.GetOwnProperties())
         {
             if (p.Value.Configurable)
             {
                 return(JSBool.False);
             }
         }
         return(JSBool.True);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("isFrozen", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.isFrozen");
         }
         if (arg.IsExtensible)
         {
             return(JSBool.False);
         }
         foreach (KeyValuePair <string, PropWrapper> p in arg.GetOwnProperties())
         {
             if ((p.Value is DataProperty) && p.Value.Writable)
             {
                 return(JSBool.False);
             }
             if (p.Value.Configurable)
             {
                 return(JSBool.False);
             }
         }
         return(JSBool.True);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("isExtensible", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.isExtensible");
         }
         return(arg.IsExtensible);
     }, 1), true, false, true);
     this.ObjectCtor.SetDataProp("keys", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSObject arg = args[0] as JSObject;
         if (arg == null)
         {
             throw new JSRuntimeException("TypeError", "invalid argument passed to Object.keys");
         }
         IList <KeyValuePair <string, PropWrapper> > ar = arg.GetOwnProperties();
         List <JSValue> ar2 = new List <JSValue>();
         for (int i = 0; i < ar.Count; i++)
         {
             KeyValuePair <string, PropWrapper> p = ar[i];
             if (p.Value.Enumerable)
             {
                 ar2.Add(p.Key);
             }
         }
         return(new JSArray(ar2.ToArray()));
     }, 1), true, false, true);
     this.ObjectPrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return("[object " + ThisObj.ClassString + "]");
     }), true, false, true);
     this.ObjectPrototype.SetDataProp("toLocaleString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(((JSFunctionBase)ThisObj.ToJSObject()["toString"]).Call(Scope, ThisObj, args));
     }), true, false, true);
     this.ObjectPrototype.SetDataProp("valueOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(ThisObj);
     }), true, false, true);
     this.ObjectPrototype.SetDataProp("hasOwnProperty", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(ThisObj.HasOwnProperty(args[0].StringValue()));
     }, 1), true, false, true);
     this.ObjectPrototype.SetDataProp("isPrototypeOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         JSValue v = args[0];
         while (true)
         {
             v = v.Prototype;
             if (v == null)
             {
                 return(JSBool.False);
             }
             if (v == ThisObj)
             {
                 return(JSBool.True);
             }
         }
     }, 1), true, false, true);
     this.ObjectPrototype.SetDataProp("propertyIsEnumerable", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         string v      = args[0].StringValue();
         PropWrapper r = ThisObj.ToJSObject().GetOwnPropertyRef(v);
         if (r == null)
         {
             return(JSBool.False);
         }
         return(r.Enumerable);
     }, 1), true, false, true);
 }
        /// <summary>
        /// Parallel move from focused object to others.
        /// </summary>
        /// <param name="move">Which direction</param>
        /// <param name="status">Status of eye or kinect..etc..</param>
        /// <returns>New focused object</returns>
        private BuildingObjectLib3DS GetObjectByParallelMovement(DrawingEnumTypes.Movement move, DrawingStatus status)
        {
            XmlTextWriter writer = null;

            writer = new XmlTextWriter(Console.Out);

            if (this.Father.Childs.Count <= 1)
            {
                return(this);
            }

            int count = Father.Childs.Count - 1;
            BuildingObjectLib3DS rnt = null;

            double          shita  = Math.Atan((status.eye.x - this.Coordinate.x) / (status.eye.z + this.Coordinate.y));
            Matrix <double> matrix = new Matrix <double>(1, 2);

            matrix.SetValue(0);
            matrix.Data[0, 0] = this.Coordinate.x;
            matrix.Data[0, 1] = -this.Coordinate.y;
            Matrix <double> _matrix = new Matrix <double>(2, 2);

            _matrix.SetValue(0);
            _matrix.Data[0, 0] = Math.Cos(shita);
            _matrix.Data[0, 1] = -Math.Sin(shita);
            _matrix.Data[1, 0] = Math.Sin(shita);
            _matrix.Data[1, 1] = Math.Cos(shita);

            Matrix <double> otherChilds = new Matrix <double>(1, 2);

            otherChilds.SetValue(0);
            double MinIn    = 99999.0f;
            double MinOut   = 99999.0f;
            double MinLeft  = 99999.0f;
            double MinRight = 99999.0f;

            foreach (BuildingObjectLib3DS ThisObj in Father.Childs.Values)
            {
                if (ThisObj.Equals(this))
                {
                    continue;
                }

                otherChilds.Data[0, 0] = ThisObj.Coordinate.x;
                otherChilds.Data[0, 1] = -ThisObj.Coordinate.y;
                otherChilds            = (otherChilds - matrix) * _matrix;
                switch (move)
                {
                case DrawingEnumTypes.Movement.MoveIn:
                    if (otherChilds.Data[0, 1] < 0 &&
                        Math.Abs(otherChilds.Data[0, 1]) < MinIn)
                    {
                        rnt   = ThisObj;
                        MinIn = Math.Abs(otherChilds.Data[0, 1]);
                    }
                    break;

                case DrawingEnumTypes.Movement.MoveOut:
                    if (otherChilds.Data[0, 1] > 0 &&
                        Math.Abs(otherChilds.Data[0, 1]) < MinOut)
                    {
                        rnt    = ThisObj;
                        MinOut = Math.Abs(otherChilds.Data[0, 1]);
                    }
                    break;

                case DrawingEnumTypes.Movement.MoveLeft:
                    if (otherChilds.Data[0, 0] < 0 &&
                        Math.Abs(otherChilds.Data[0, 0]) < MinLeft)
                    {
                        rnt     = ThisObj;
                        MinLeft = Math.Abs(otherChilds.Data[0, 0]);
                    }
                    break;

                case DrawingEnumTypes.Movement.MoveRight:
                    if (otherChilds.Data[0, 0] > 0 &&
                        Math.Abs(otherChilds.Data[0, 0]) < MinRight)
                    {
                        rnt      = ThisObj;
                        MinRight = Math.Abs(otherChilds.Data[0, 0]);
                    }
                    break;

                default:
                    return(this);
                }
            }

            // If we find the object
            if (rnt != null)
            {
                return(rnt);
            }

            // Do not find....
            return(this);
        }
Exemplo n.º 9
0
 private void AddDateProperties()
 {
     this.Global.SetDataProp("Date", this.DateCtor, false, false, false);
     this.DateCtor.SetDataProp("parse", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(new JSDate(DateTime.Parse(args[0].StringValue())));
     }), true, false, true);
     this.DateCtor.SetDataProp("UTC", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(new JSDate(JSDate.UTC(args)));
     }), true, false, true);
     this.DateCtor.SetDataProp("now", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         return(new JSDate(DateTime.UtcNow));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("F"));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toDateString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toDateString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("D"));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toTimeString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toTimeString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("T"));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toLocaleString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toLocaleString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("F") + " GMT" + v.ToString("zzz") + " (" + (TimeZone.CurrentTimeZone.IsDaylightSavingTime(v) ? TimeZone.CurrentTimeZone.DaylightName : TimeZone.CurrentTimeZone.StandardName) + ")");
     }), true, false, true);
     this.DatePrototype.SetDataProp("toLocaleDateString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toLocaleDateString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("D"));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toLocaleTimeString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toLocaleTimeString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToLocalTime().ToString("T") + " GMT" + v.ToString("zzz") + " (" + (TimeZone.CurrentTimeZone.IsDaylightSavingTime(v) ? TimeZone.CurrentTimeZone.DaylightName : TimeZone.CurrentTimeZone.StandardName) + ")");
     }), true, false, true);
     this.DatePrototype.SetDataProp("valueOf", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.valueOf called on non-date type");
         }
         return(((JSDate)ThisObj).ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("getTime", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getTime called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return(((double)(v.Ticks - 0x89f7ff5f7b58000L)) / 10000.0);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getFullYear", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getFullYear called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Year);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCFullYear", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCFullYear called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Year);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getMonth", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getMonth called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)(v.ToLocalTime().Month - 1));
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCMonth", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCMonth called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)(v.Month - 1));
     }), true, false, true);
     this.DatePrototype.SetDataProp("getDate", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getDate called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Day);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCDate", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCDate called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Day);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getDay", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getDay called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((double)v.ToLocalTime().DayOfWeek);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCDay", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCDay called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((double)v.DayOfWeek);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getHours", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getHours called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Hour);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCHours", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCHours called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Hour);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getMinutes", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getMinutes called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Minute);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCMinutes", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCMinutes called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Minute);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getSeconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getSeconds called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Second);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCSeconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCSeconds called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Second);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getMilliseconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getMilliseconds called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.ToLocalTime().Millisecond);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getUTCMilliseconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getUTCMilliseconds called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)v.Millisecond);
     }), true, false, true);
     this.DatePrototype.SetDataProp("getTimezoneOffset", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.getTimezoneOffset called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return(((v - v.ToLocalTime())).TotalMinutes);
     }), true, false, true);
     this.DatePrototype.SetDataProp("setTime", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setTime called on non-date type");
         }
         JSDate d  = (JSDate)ThisObj;
         double v  = JSDate.TimeClip(args[0].NumberValue());
         d.CLRDate = JSDate.FromNumber(v);
         return(v);
     }), true, false, true);
     this.DatePrototype.SetDataProp("setMilliseconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMilliseconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMilliseconds(ms - d.CLRDate.Millisecond);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCMilliseconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setUTCMilliseconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMilliseconds(ms - d.CLRDate.Millisecond);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setSeconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setSeconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromSeconds(ms - d.CLRDate.Second);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCSeconds", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setUTCSeconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromSeconds(ms - d.CLRDate.Second);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setMinutes", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMinutes called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMinutes(ms - d.CLRDate.Minute);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCMinutes", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setUTCMinutes called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMinutes(ms - d.CLRDate.Minute);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setHours", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setHours called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromHours(ms - d.CLRDate.Hour);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCHours", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setUTCHours called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromHours(ms - d.CLRDate.Hour);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setDate", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setDate called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromDays(ms - d.CLRDate.Day);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCDate", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setDate called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromDays(ms - d.CLRDate.Day);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setMonth", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMonths called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         DateTime x = new DateTime(d.CLRDate.Year, (int)ms, 0);
         x         += TimeSpan.FromDays((double)d.CLRDate.Day);
         x         += d.CLRDate.TimeOfDay;
         d.CLRDate  = x;
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCMonth", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMilliseconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMilliseconds(ms - d.CLRDate.Millisecond);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setFullYear", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMilliseconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMilliseconds(ms - d.CLRDate.Millisecond);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("setUTCFullYear", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.setMilliseconds called on non-date type");
         }
         JSDate d   = (JSDate)ThisObj;
         double ms  = args[0].NumberValue().JSToInteger();
         d.CLRDate += TimeSpan.FromMilliseconds(ms - d.CLRDate.Millisecond);
         return(d.ToDouble());
     }), true, false, true);
     this.DatePrototype.SetDataProp("toUTCString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toUTCString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToString("F") + " GMT");
     }), true, false, true);
     this.DatePrototype.SetDataProp("toISOString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toISOString called on non-date type");
         }
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return("Invalid Date");
         }
         return(v.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ"));
     }), true, false, true);
     this.DatePrototype.SetDataProp("toJSON", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         if (!(ThisObj is JSDate))
         {
             throw new JSRuntimeException("TypeError", "Date.toJSON called on non-date type");
         }
         JSObject O = ThisObj.ToJSObject();
         JSValue p  = O.ToPrimitive(false);
         if (!(!(p is JSNumber) || p.NumberValue().IsFinite()))
         {
             return(JSNull.Instance);
         }
         JSFunctionBase toISO = O["toISOString"] as JSFunctionBase;
         if (toISO == null)
         {
             throw new JSRuntimeException("TypeError", "Date.toJSON called on object without toISOString");
         }
         return(toISO.Call(Scope, O, new JSArgs(toISO, new JSValue[0])));
     }), true, false, true);
     this.DatePrototype.SetDataProp("getYear", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor)
     {
         DateTime v = ((JSDate)ThisObj).CLRDate;
         if (v == DateTime.MinValue)
         {
             return(JSNumber.NaN);
         }
         return((JSValue)(v.ToLocalTime().Year - 0x76c));
     }), true, false, true);
 }