Example #1
0
 public ObjectConstructor(Context context, StaticProxy staticProxy, JSObject prototype)
     : base(context, staticProxy, prototype)
 {
     _length = new Number(1);
 }
Example #2
0
        public ConstructorProxy(Context context, StaticProxy staticProxy, JSObject prototype)
            : base(context)
        {
            if (staticProxy == null)
            {
                throw new ArgumentNullException(nameof(staticProxy));
            }
            if (prototype == null)
            {
                throw new ArgumentNullException(nameof(prototype));
            }

            _fields      = staticProxy._fields;
            _staticProxy = staticProxy;
            _prototype   = prototype;

#if (PORTABLE || NETCORE)
            if (_staticProxy._hostedType.GetTypeInfo().ContainsGenericParameters)
            {
                ExceptionHelper.Throw(new TypeError(_staticProxy._hostedType.Name + " can't be created because it's generic type."));
            }
#else
            if (_staticProxy._hostedType.ContainsGenericParameters)
            {
                ExceptionHelper.ThrowTypeError(_staticProxy._hostedType.Name + " can't be created because it's generic type.");
            }
#endif
            var withNewOnly    = staticProxy._hostedType.GetTypeInfo().IsDefined(typeof(RequireNewKeywordAttribute), true);
            var withoutNewOnly = staticProxy._hostedType.GetTypeInfo().IsDefined(typeof(DisallowNewKeywordAttribute), true);

            if (withNewOnly && withoutNewOnly)
            {
                ExceptionHelper.Throw(new InvalidOperationException("Unacceptably use of " + typeof(RequireNewKeywordAttribute).Name + " and " + typeof(DisallowNewKeywordAttribute).Name + " for same type."));
            }

            if (withNewOnly)
            {
                RequireNewKeywordLevel = RequireNewKeywordLevel.WithNewOnly;
            }
            if (withoutNewOnly)
            {
                RequireNewKeywordLevel = RequireNewKeywordLevel.WithoutNewOnly;
            }

            if (_length == null)
            {
                _length = new Number(0)
                {
                    _attributes = JSValueAttributesInternal.ReadOnly | JSValueAttributesInternal.DoNotDelete | JSValueAttributesInternal.DoNotEnumerate
                }
            }
            ;

#if (PORTABLE || NETCORE)
            var ctors  = staticProxy._hostedType.GetTypeInfo().DeclaredConstructors.Where(x => x.IsPublic).ToArray();
            var ctorsL = new List <MethodProxy>(ctors.Length + (staticProxy._hostedType.GetTypeInfo().IsValueType ? 1 : 0));
#else
            var ctors  = staticProxy._hostedType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
            var ctorsL = new List <MethodProxy>(ctors.Length + (staticProxy._hostedType.IsValueType ? 1 : 0));
#endif
            for (int i = 0; i < ctors.Length; i++)
            {
                if (ctors[i].IsStatic)
                {
                    continue;
                }

                if (!ctors[i].IsDefined(typeof(HiddenAttribute), false) || ctors[i].IsDefined(typeof(ForceUseAttribute), true))
                {
                    ctorsL.Add(new MethodProxy(context, ctors[i]));
                    length._iValue = System.Math.Max(ctorsL[ctorsL.Count - 1]._length._iValue, _length._iValue);
                }
            }

            ctorsL.Sort((x, y) =>
                        x.Parameters.Length == 1 && x.Parameters[0].ParameterType == typeof(Arguments) ? 1 :
                        y.Parameters.Length == 1 && y.Parameters[0].ParameterType == typeof(Arguments) ? -1 :
                        x.Parameters.Length - y.Parameters.Length);

            constructors = ctorsL.ToArray();
        }
Example #3
0
        public JSObject GetConstructor(Type type)
        {
            JSObject constructor = null;

            if (!_proxies.TryGetValue(type, out constructor))
            {
                lock (_proxies)
                {
                    JSObject dynamicProxy = null;

                    if (type.GetTypeInfo().ContainsGenericParameters)
                    {
                        constructor = GetGenericTypeSelector(new[] { type });
                    }
                    else
                    {
                        var indexerSupport = IndexersSupport == IndexersSupport.ForceEnable ||
                                             (IndexersSupport == IndexersSupport.WithAttributeOnly && type.GetTypeInfo().IsDefined(typeof(UseIndexersAttribute), false));

                        var staticProxy = new StaticProxy(this, type, indexerSupport);
                        if (type.GetTypeInfo().IsAbstract)
                        {
                            _proxies[type] = staticProxy;
                            return(staticProxy);
                        }

                        JSObject parentPrototype = null;
                        var      pa = type.GetTypeInfo().GetCustomAttributes(typeof(PrototypeAttribute), true).ToArray();
                        if (pa.Length != 0 && (pa[0] as PrototypeAttribute).PrototypeType != type)
                        {
                            var parentType = (pa[0] as PrototypeAttribute).PrototypeType;
                            parentPrototype = (GetConstructor(parentType) as Function).prototype as JSObject;

                            if ((pa[0] as PrototypeAttribute).Replace && parentType.IsAssignableFrom(type))
                            {
                                dynamicProxy = parentPrototype;
                            }
                            else
                            {
                                dynamicProxy = new PrototypeProxy(this, type, indexerSupport)
                                {
                                    _objectPrototype = parentPrototype
                                };
                            }
                        }
                        else
                        {
                            dynamicProxy = new PrototypeProxy(this, type, indexerSupport);
                        }

                        if (type == typeof(JSObject))
                        {
                            constructor = new ObjectConstructor(this, staticProxy, dynamicProxy);
                        }
                        else
                        {
                            constructor = new ConstructorProxy(this, staticProxy, dynamicProxy);
                        }

                        if (type.GetTypeInfo().IsDefined(typeof(ImmutableAttribute), false))
                        {
                            dynamicProxy._attributes |= JSValueAttributesInternal.Immutable;
                        }
                        constructor._attributes   = dynamicProxy._attributes;
                        dynamicProxy._attributes |= JSValueAttributesInternal.DoNotDelete | JSValueAttributesInternal.DoNotEnumerate | JSValueAttributesInternal.NonConfigurable | JSValueAttributesInternal.ReadOnly;

                        if (dynamicProxy != parentPrototype && type != typeof(ConstructorProxy))
                        {
                            dynamicProxy._fields["constructor"] = constructor;
                        }
                    }

                    _proxies[type] = constructor;

                    if (dynamicProxy != null && typeof(JSValue).IsAssignableFrom(type))
                    {
                        if (dynamicProxy._objectPrototype == null)
                        {
                            dynamicProxy._objectPrototype = _globalPrototype ?? JSValue.@null;
                        }
                        var fake = (dynamicProxy as PrototypeProxy).PrototypeInstance;
                    }
                }
            }

            return(constructor);
        }
Example #4
0
        /// <summary>
        /// Transform placements to proxys<para/>
        /// Преобразование расстановок в прокси-объекты
        /// </summary>
        public static void Init()
        {
            // Firstly - normal objects
            // Сначала - обычные объекты
            foreach (ItemPlacement p in ObjectManager.Placements)
            {
                ItemDefinition ide = ObjectManager.Definitions[p.ID];
                if (!ide.ModelName.StartsWith("lod"))
                {
                    // Creating non-lod fields
                    // Заполнение обычных полей
                    StaticProxy sp = new StaticProxy();
                    sp.MainMesh = new StaticProxy.Group()
                    {
                        Placement  = p,
                        Definition = ide,
                        Range      = ide.DrawDistance[0],
                        Coords     = new Graphics.Transform()
                        {
                            Position = p.Position,
                            Scale    = p.Scale,
                            Angles   = p.Angle,
                        },
                        Timed   = ide.IsTimed,
                        HourOn  = ide.TimeOn,
                        HourOff = ide.TimeOff
                    };
                    sp.State = StaticProxy.VisState.Hidden;
                    Statics.Add(sp);

                    // Catch huge island LODs
                    // Выборка огромных LOD-мешей
                    if (p.ID == BeachLODIndex)
                    {
                        StaticProxy.BeachLod = sp;
                    }
                    else if (p.ID == MainlandLODIndex)
                    {
                        StaticProxy.MainlandLod = sp;
                    }
                }
            }

            // Secondly - LOD objects
            // Потом - LOD-объекты
            foreach (ItemPlacement p in ObjectManager.Placements)
            {
                ItemDefinition ide = ObjectManager.Definitions[p.ID];
                if (ide.ModelName.StartsWith("lod"))
                {
                    // Search for a parent
                    // Поиск родителя
                    StaticProxy    sp   = null;
                    ItemDefinition pide = null;
                    foreach (StaticProxy spp in Statics)
                    {
                        if (!spp.LodAssigned)
                        {
                            pide = ObjectManager.Definitions[spp.MainMesh.Definition.ID];
                            if (pide.ModelName.Length > 3)
                            {
                                if (ide.ModelName == "lod" + pide.ModelName.Substring(3))
                                {
                                    sp = spp;
                                    break;
                                }
                            }
                        }
                    }

                    if (sp == null)
                    {
                        // Owner is not found - it's a simple object
                        // Родитель не нашёлся - это простой объект
                        sp          = new StaticProxy();
                        sp.MainMesh = new StaticProxy.Group()
                        {
                            Definition = ide,
                            Placement  = p,
                            Range      = ide.DrawDistance[0],
                            Coords     = new Graphics.Transform()
                            {
                                Position = p.Position,
                                Scale    = p.Scale,
                                Angles   = p.Angle,
                            },
                            Timed   = ide.IsTimed,
                            HourOn  = ide.TimeOn,
                            HourOff = ide.TimeOff
                        };
                        sp.State       = StaticProxy.VisState.Hidden;
                        sp.LodAssigned = true;
                        Statics.Add(sp);
                    }
                    else
                    {
                        // Creating lod fields
                        // Заполнение низкополигональных полей
                        sp.LODMesh = new StaticProxy.Group()
                        {
                            Definition = ide,
                            Placement  = p,
                            Range      = ide.DrawDistance[0],
                            Coords     = new Graphics.Transform()
                            {
                                Position = p.Position,
                                Scale    = p.Scale,
                                Angles   = p.Angle,
                            },
                            Timed   = ide.IsTimed,
                            HourOn  = ide.TimeOn,
                            HourOff = ide.TimeOff
                        };
                        sp.LodAssigned = true;
                    }
                }
            }
            Dev.Console.Log("[StaticManager] Generated " + Statics.Count + " proxies");

            // Starting the culler thread
            // Запуск отсекающего потока
            thread = new Thread(CullingProcess);
            thread.IsBackground = true;
            thread.Priority     = ThreadPriority.BelowNormal;
            thread.Start();
            Dev.Console.Log("[StaticManager] Culling thread started");
        }