Пример #1
0
        public JsValue GetOwnPropertyNames(JsValue thisObject, JsValue[] arguments)
        {
            var oArg = arguments.At(0);
            var o    = oArg.TryCast <ObjectInstance>();

            if (ReferenceEquals(o, null))
            {
                ExceptionHelper.ThrowTypeError(Engine);
            }

            uint n = 0;

            ArrayInstance array         = null;
            var           ownProperties = o.GetOwnProperties().ToList();

            if (o is StringInstance)
            {
                var s      = o as StringInstance;
                var length = s.PrimitiveValue.Length;
                array = Engine.Array.ConstructFast((uint)(ownProperties.Count + length));
                for (var i = 0; i < length; i++)
                {
                    array.SetIndexValue(n, TypeConverter.ToString(i), updateLength: false);
                    n++;
                }
            }

            array = array ?? Engine.Array.ConstructFast((uint)ownProperties.Count);
            for (var i = 0; i < ownProperties.Count; i++)
            {
                var p = ownProperties[i];
                array.SetIndexValue(n, p.Key, false);
                n++;
            }

            array.SetLength(n);
            return(array);
        }